Exemple #1
0
def main():
    """
    DistMigration run zypper based migration

    Call zypper migration plugin and migrate the system.
    The output of the call is logged on the system to migrate
    """
    root_path = Defaults.get_system_root_path()

    try:
        log.info('Running migrate service')
        migration_config = MigrationConfig()
        if migration_config.is_zypper_migration_plugin_requested():
            bash_command = ' '.join([
                'zypper', 'migration', '--non-interactive',
                '--gpg-auto-import-keys', '--no-selfupdate',
                '--auto-agree-with-licenses', '--allow-vendor-change',
                '--strict-errors-dist-migration', '--replacefiles',
                '--product',
                migration_config.get_migration_product(), '--root', root_path,
                '&>>',
                Defaults.get_migration_log_file()
            ])
            Command.run(['bash', '-c', bash_command])
        else:
            bash_command = ' '.join([
                'zypper', '--non-interactive', '--gpg-auto-import-keys',
                '--root', root_path, 'dup', '--auto-agree-with-licenses',
                '--allow-vendor-change', '--replacefiles', '&>>',
                Defaults.get_migration_log_file()
            ])
            zypper_call = Command.run(['bash', '-c', bash_command],
                                      raise_on_error=False)
            if zypper_has_failed(zypper_call.returncode):
                raise DistMigrationCommandException(
                    '{0} failed with: {1}: {2}'.format(bash_command,
                                                       zypper_call.output,
                                                       zypper_call.error))
    except Exception as issue:
        etc_issue_path = os.sep.join([root_path, 'etc/issue'])
        log_path_migrated_system = os.sep + os.path.relpath(
            Defaults.get_migration_log_file(), root_path)
        with open(etc_issue_path, 'w') as issue_file:
            issue_file.write(
                'Migration has failed, for further details see {0}'.format(
                    log_path_migrated_system))
        log.error('migrate service failed with {0}'.format(issue))
        raise DistMigrationZypperException(
            'Migration failed with {0}'.format(issue))
Exemple #2
0
def log_init():
    logging.setLoggerClass(Logger)
    log = logging.getLogger("suse-migration")
    log.setLevel(logging.DEBUG)

    log_file = Defaults.get_migration_log_file()
    if os.path.exists(log_file):
        log.set_logfile(log_file)
    return log
Exemple #3
0
    def setup():
        logger = logging.getLogger(Defaults.get_migration_log_name())
        logger.setLevel(logging.INFO)

        log_file = Defaults.get_migration_log_file()
        Path.create(os.path.dirname(log_file))

        log_to_file = logging.FileHandler(log_file)
        log_to_file.setLevel(logging.INFO)

        log_to_stream = logging.StreamHandler()
        log_to_stream.setLevel(logging.INFO)

        logger.addHandler(log_to_stream)
        logger.addHandler(log_to_file)
Exemple #4
0
def initialize_logging():
    log_file = Defaults.get_migration_log_file()
    with open(log_file, 'w'):
        log.set_logfile(Defaults.get_migration_log_file())
 def test_set_logfile_path_not_found(self):
     with raises(DistMigrationLoggingException):
         log.set_logfile(Defaults.get_migration_log_file())