示例#1
0
    def dnf_shell_rpm_download(self, overlayfs_info):
        dnf_command = [
            '/usr/bin/dnf',
            'shell',
            '-y',
            '--setopt=protected_packages=',
            '--disablerepo', '\'*\'',
            '--releasever', '8',
            '--allowerasing',
            '--best',
            '--nogpgcheck',
            '--setopt=tsflags=test'
        ]

        # get list of UIDs of target repositories that should be used for upgrade
        error = self._setup_target_repos(overlayfs_info)
        if error:
            return error
        if not self.target_uids:
            return preparetransaction.ErrorData(
                summary='Cannot find any required target repository.',
                details='The list of available required repositories is empty.'
                )

        # enable repositores for upgrade
        dnf_command += ['--enablerepo', ','.join(self.target_uids)]

        if os.environ.get('LEAPP_DEBUG', '0') == '1':
            dnf_command.append('--debugsolver')

        error = preparetransaction.mount_dnf_cache(overlayfs_info)
        if error:
            return error

        data = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks())
        with open(os.path.join(overlayfs_info.merged, 'var', 'lib', 'leapp', 'dnf-script.txt'), 'w+') as script:
            cmds = ['distro-sync']
            cmds += ['remove ' + pkg for pkg in data.to_remove if pkg]
            cmds += ['install ' + pkg for pkg in data.to_install if pkg]

            script.write('\n'.join(cmds))
            script.flush()

        error = preparetransaction.check_container_call(overlayfs_info, [
            '--',
            '/bin/bash',
            '-c',
            ' '.join(dnf_command + ['/var/lib/leapp/dnf-script.txt'])])

        if os.environ.get('LEAPP_DEBUG', '0') == '1':
            # We want the debug data available where we would expect it usually.
            call(['rm', '-rf', os.path.join('/tmp', 'download-debugdata')])
            call(['cp', '-a', os.path.join(overlayfs_info.merged, 'debugdata'), '/tmp/download-debugdata'])

        if error:
            # FIXME: Do not swallow errors from umount
            preparetransaction.umount_dnf_cache(overlayfs_info)
            return error

        return preparetransaction.umount_dnf_cache(overlayfs_info)
示例#2
0
    def dnf_plugin_rpm_download(self, overlayfs_info):
        dnf_command = ['/usr/bin/dnf', 'rhel-upgrade', 'download']

        # get list of repo IDs of target repositories that should be used for upgrade
        error = self._setup_target_repos(overlayfs_info)
        if error:
            return error
        if not self.target_repoids:
            return preparetransaction.ErrorData(
                summary='Cannot find any required target repository.',
                details='The list of available required repositories is empty.'
            )

        debugsolver = True if os.environ.get('LEAPP_DEBUG',
                                             '0') == '1' else False

        yum_script_path = self.get_tool_path('handleyumconfig')
        cmd = ['--', '/bin/bash', '-c', yum_script_path]
        _unused, error = preparetransaction.guard_container_call(
            overlayfs_info, cmd)
        if error:
            return error

        error = preparetransaction.mount_dnf_cache(overlayfs_info)
        if error:
            return error

        data = next(self.consume(FilteredRpmTransactionTasks),
                    FilteredRpmTransactionTasks())

        plugin_data = {
            'pkgs_info': {
                'local_rpms': [pkg for pkg in data.local_rpms],
                'to_install': [pkg for pkg in data.to_install],
                'to_remove': [pkg for pkg in data.to_remove]
            },
            'dnf_conf': {
                'allow_erasing': True,
                'best': True,
                'debugsolver': debugsolver,
                'disable_repos': True,
                'enable_repos': self.target_repoids,
                'gpgcheck': False,
                'platform_id': 'platform:el8',
                'releasever': '8',
                'test_flag': True,
            }
        }

        with open(
                os.path.join(overlayfs_info.merged, 'var', 'lib', 'leapp',
                             'dnf-plugin-data.txt'), 'w+') as data:
            json.dump(plugin_data, data)
            data.flush()

        copy_error = preparetransaction.copy_file_from_container(
            overlayfs_info,
            '/var/lib/leapp/dnf-plugin-data.txt',
            '/var/log/leapp/',
            'dnf-plugin-data.txt',
        )

        if copy_error:
            preparetransaction.produce_warning(copy_error)

        # FIXME: fails on insufficient permissions
        cmd = [
            '--', '/bin/bash', '-c',
            ' '.join(dnf_command + ['/var/lib/leapp/dnf-plugin-data.txt'])
        ]
        _unused, error = preparetransaction.guard_container_call(
            overlayfs_info,
            cmd,
            guards=(preparetransaction.connection_guard(),
                    preparetransaction.space_guard()),
            print_output=True)

        if os.environ.get('LEAPP_DEBUG', '0') == '1':
            # We want the debug data available where we would expect it usually.
            debug_data_path = '/var/log/leapp/dnf-debugdata/'

            # The debugdata is a folder generated by dnf when using the --debugsolver dnf option. We switch on the
            # debug_solver dnf config parameter in our rhel-upgrade dnf plugin when LEAPP_DEBUG env var set to 1.
            cmd = [
                'cp', '-a',
                os.path.join(overlayfs_info.merged, 'debugdata'),
                debug_data_path
            ]
            _unused, dbg_error = preparetransaction.guard_call(cmd)
            if dbg_error:
                preparetransaction.produce_warning(
                    dbg_error, summary='Cannot copy new debugdata.')

        if error:
            umount_error = preparetransaction.umount_dnf_cache(overlayfs_info)
            if umount_error:
                preparetransaction.produce_error(umount_error)
            return error

        return preparetransaction.umount_dnf_cache(overlayfs_info)