from ...Machine.PaedMLMachineCollection import MACHINE_COLLECTION
from ...Logging.Logger import log
from ..Playbooks.Playbook import FileCleanupTask, PlaybookCredentialCollection
from ...SetupSteps.SetupStep import SetupStep


class OpsiChangeMysqlSecret(SetupStep):
    def run(self, file_cleanup_stack : list[FileCleanupTask], credentials: PlaybookCredentialCollection):
        log('Changing MySQL passwords...')
        stdout, stderr, retval = MACHINE_COLLECTION.backup.execute_shell_command('/usr/share/paedmllinux/lmz-mysql-secret-change')
        if retval != 0:
            log(f'Error changing MySQL password on backup server: {stderr if len(stderr) > 0 else stdout}')
            return False
        return True