Ejemplo n.º 1
0
    def process(self):
        installed_pkgs = set()
        for rpm_pkgs in self.consume(InstalledRedHatSignedRPM):
            installed_pkgs.update([pkg.name for pkg in rpm_pkgs.items])

        local_rpms = set()
        to_install = set()
        to_remove = set()
        to_keep = set()
        to_upgrade = set()
        for event in self.consume(RpmTransactionTasks, PESRpmTransactionTasks):
            local_rpms.update(event.local_rpms)
            to_install.update(event.to_install)
            to_remove.update(installed_pkgs.intersection(event.to_remove))
            to_keep.update(installed_pkgs.intersection(event.to_keep))

        to_remove.difference_update(to_keep)

        # run upgrade for the rest of RH signed pkgs which we do not have rule for
        to_upgrade = installed_pkgs - (to_install | to_remove)

        self.produce(
            FilteredRpmTransactionTasks(local_rpms=list(local_rpms),
                                        to_install=list(to_install),
                                        to_remove=list(to_remove),
                                        to_keep=list(to_keep),
                                        to_upgrade=list(to_upgrade)))
Ejemplo n.º 2
0
    def process(self):
        src_rhsm_info = next(self.consume(RHSMInfo), None)
        if src_rhsm_info:
            for prod_cert in src_rhsm_info.existing_product_certificates:
                run(['rm', '-f', prod_cert])

        used_repos = self.consume(UsedTargetRepositories)
        storage_info = next(self.consume(StorageInfo), None)
        plugin_info = list(self.consume(DNFPluginTask))
        tasks = next(self.consume(FilteredRpmTransactionTasks),
                     FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)

        dnfplugin.perform_transaction_install(
            tasks=tasks,
            used_repos=used_repos,
            storage_info=storage_info,
            target_userspace_info=target_userspace_info,
            plugin_info=plugin_info)
        self.produce(TransactionCompleted())
        userspace = next(self.consume(TargetUserSpaceInfo), None)
        if userspace:
            try:
                shutil.rmtree(userspace.path)
            except EnvironmentError:
                self.log.info(
                    "Failed to remove temporary userspace - error ignored",
                    exc_info=True)
Ejemplo n.º 3
0
    def process(self):
        # FIXME: we hitting issue now because the network is down and rhsm
        # # is trying to connect to the server. Commenting this out for now
        # # so people will not be affected in case they do not have set a
        # # release and we will have time to fix it properly.
        # Make sure Subscription Manager OS Release is unset
        # cmd = ['subscription-manager', 'release', '--unset']
        # run(cmd)

        # FIXME: that's ugly hack, we should get info which file remove and
        # do it more nicely..
        run(['rm', '-f', '/etc/pki/product/69.pem'])

        used_repos = self.consume(UsedTargetRepositories)
        tasks = next(self.consume(FilteredRpmTransactionTasks),
                     FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)

        dnfplugin.perform_transaction_install(
            tasks=tasks,
            used_repos=used_repos,
            target_userspace_info=target_userspace_info)
        self.produce(TransactionCompleted())
        userspace = next(self.consume(TargetUserSpaceInfo), None)
        if userspace:
            try:
                shutil.rmtree(userspace.path)
            except EnvironmentError:
                self.log.info(
                    "Failed to remove temporary userspace - error ignored",
                    exc_info=True)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def process(self):
        # FIXME: we hitting issue now because the network is down and rhsm
        # # is trying to connect to the server. Commenting this out for now
        # # so people will not be affected in case they do not have set a
        # # release and we will have time to fix it properly.
        # Make sure Subscription Manager OS Release is unset
        # cmd = ['subscription-manager', 'release', '--unset']
        # run(cmd)

        src_rhsm_info = next(self.consume(SourceRHSMInfo), None)
        if src_rhsm_info:
            for prod_cert in src_rhsm_info.existing_product_certificates:
                run(['rm', '-f', prod_cert])

        used_repos = self.consume(UsedTargetRepositories)
        storage_info = next(self.consume(StorageInfo), None)
        tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)

        dnfplugin.perform_transaction_install(tasks=tasks, used_repos=used_repos, storage_info=storage_info,
                                              target_userspace_info=target_userspace_info)
        self.produce(TransactionCompleted())
        userspace = next(self.consume(TargetUserSpaceInfo), None)
        if userspace:
            try:
                shutil.rmtree(userspace.path)
            except EnvironmentError:
                self.log.info("Failed to remove temporary userspace - error ignored", exc_info=True)
Ejemplo n.º 6
0
    def process(self):
        # FIXME: we hitting issue now because the network is down and rhsm
        # # is trying to connect to the server. Commenting this out for now
        # # so people will not be affected in case they do not have set a
        # # release and we will have time to fix it properly.
        # Make sure Subscription Manager OS Release is unset
        # cmd = ['subscription-manager', 'release', '--unset']
        # run(cmd)

        shutil.copyfile(
            self.get_file_path('rhel_upgrade.py'),
            '/lib/python2.7/site-packages/dnf-plugins/rhel_upgrade.py')

        dnf_command = ['/usr/bin/dnf', 'rhel-upgrade', 'upgrade']

        target_repoids = []
        for target_repos in self.consume(UsedTargetRepositories):
            for repo in target_repos.repos:
                target_repoids.append(repo.repoid)

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

        shutil.copyfile('/etc/yum.repos.d/redhat.repo.upgrade',
                        '/etc/yum.repos.d/redhat.repo')

        # FIXME: that's ugly hack, we should get info which file remove and
        # + do it more nicely..
        cmd = ['rm', '-f', '/etc/pki/product/69.pem']
        run(cmd)

        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': target_repoids,
                'gpgcheck': False,
                'platform_id': 'platform:el8',
                'releasever': '8',
                'test_flag': False,
            }
        }

        with NamedTemporaryFile() as data:
            json.dump(plugin_data, data)
            data.flush()
            run(dnf_command + [data.name], callback_raw=_logging_handler)

        self.produce(TransactionCompleted())
Ejemplo n.º 7
0
    def process(self):
        presence = next(self.consume(XFSPresence), XFSPresence())
        xfs_present = presence.present and presence.without_ftype
        used_repos = self.consume(UsedTargetRepositories)
        tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)

        dnfplugin.perform_rpm_download(tasks=tasks, used_repos=used_repos, target_userspace_info=target_userspace_info,
                                       xfs_present=xfs_present)
Ejemplo n.º 8
0
    def process(self):
        xfs_info = next(self.consume(XFSPresence), XFSPresence())
        storage_info = next(self.consume(StorageInfo), StorageInfo())
        used_repos = self.consume(UsedTargetRepositories)
        tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)

        dnfplugin.perform_rpm_download(tasks=tasks, used_repos=used_repos, target_userspace_info=target_userspace_info,
                                       xfs_info=xfs_info, storage_info=storage_info)
Ejemplo n.º 9
0
    def process(self):
        xfs_info = next(self.consume(XFSPresence), XFSPresence())
        storage_info = next(self.consume(StorageInfo), StorageInfo())
        used_repos = self.consume(UsedTargetRepositories)
        plugin_info = list(self.consume(DNFPluginTask))
        tasks = next(self.consume(FilteredRpmTransactionTasks), FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)

        if target_userspace_info:
            dnfplugin.perform_transaction_check(
                tasks=tasks, used_repos=used_repos, target_userspace_info=target_userspace_info,
                xfs_info=xfs_info, storage_info=storage_info, plugin_info=plugin_info
            )
Ejemplo n.º 10
0
    def process(self):
        installed_pkgs = set()
        for rpm_pkgs in self.consume(InstalledRedHatSignedRPM):
            installed_pkgs.update([pkg.name for pkg in rpm_pkgs.items])

        to_install = set()
        to_remove = set()
        to_keep = set()
        for event in self.consume(RpmTransactionTasks):
            to_install.update(event.to_install)
            to_remove.update(installed_pkgs.intersection(event.to_remove))
            to_keep.update(installed_pkgs.intersection(event.to_keep))

        to_remove.difference_update(to_keep)

        self.produce(FilteredRpmTransactionTasks(
            to_install=list(to_install),
            to_remove=list(to_remove),
            to_keep=list(to_keep)))
Ejemplo n.º 11
0
    def process(self):
        xfs_info = next(self.consume(XFSPresence), XFSPresence())
        storage_info = next(self.consume(StorageInfo), StorageInfo())
        used_repos = self.consume(UsedTargetRepositories)
        plugin_info = list(self.consume(DNFPluginTask))
        tasks = next(self.consume(FilteredRpmTransactionTasks),
                     FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)
        rhui_info = next(self.consume(RHUIInfo), None)
        on_aws = bool(rhui_info and rhui_info.provider == 'aws')

        dnfplugin.perform_dry_run(tasks=tasks,
                                  used_repos=used_repos,
                                  target_userspace_info=target_userspace_info,
                                  xfs_info=xfs_info,
                                  storage_info=storage_info,
                                  plugin_info=plugin_info,
                                  on_aws=on_aws)
        self.produce(TransactionDryRun())
Ejemplo n.º 12
0
    def process(self):
        # FIXME: we hitting issue now because the network is down and rhsm
        # # is trying to connect to the server. Commenting this out for now
        # # so people will not be affected in case they do not have set a
        # # release and we will have time to fix it properly.
        # Make sure Subscription Manager OS Release is unset
        #cmd = ['subscription-manager', 'release', '--unset']
        #check_call(cmd)

        dnf_command = [
            '/usr/bin/dnf', 'shell', '-y', '--setopt=protected_packages=',
            '--disablerepo', '\'*\'', '--releasever', '8', '--allowerasing',
            '--best', '--nogpgcheck', '-C'
        ]

        target_uids = []
        for target_repos in self.consume(UsedTargetRepositories):
            for repo in target_repos.repos:
                target_uids.append(repo.uid)
        dnf_command += ['--enablerepo', ','.join(target_uids)]

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

        shutil.copyfile('/etc/yum.repos.d/redhat.repo.upgrade',
                        '/etc/yum.repos.d/redhat.repo')

        # FIXME: that's ugly hack, we should get info which file remove and
        # + do it more nicely..
        cmd = ['rm', '-f', '/etc/pki/product/69.pem']
        check_call(cmd)

        data = next(self.consume(FilteredRpmTransactionTasks),
                    FilteredRpmTransactionTasks())
        with NamedTemporaryFile() 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()
            check_call(dnf_command + [script.name])
Ejemplo n.º 13
0
    def process(self):
        xfs_info = next(self.consume(XFSPresence), XFSPresence())
        storage_info = next(self.consume(StorageInfo), StorageInfo())
        used_repos = self.consume(UsedTargetRepositories)
        plugin_info = list(self.consume(DNFPluginTask))
        tasks = next(self.consume(FilteredRpmTransactionTasks),
                     FilteredRpmTransactionTasks())
        target_userspace_info = next(self.consume(TargetUserSpaceInfo), None)
        rhui_info = next(self.consume(RHUIInfo), None)
        # there are several "variants" related to the *AWS* provider (aws, aws-sap)
        on_aws = bool(rhui_info and rhui_info.provider.startswith('aws'))

        dnfplugin.perform_rpm_download(
            tasks=tasks,
            used_repos=used_repos,
            target_userspace_info=target_userspace_info,
            xfs_info=xfs_info,
            storage_info=storage_info,
            plugin_info=plugin_info,
            on_aws=on_aws)
Ejemplo n.º 14
0
    def process(self):
        installed_pkgs = set()
        for rpm_pkgs in self.consume(InstalledRedHatSignedRPM):
            installed_pkgs.update([pkg.name for pkg in rpm_pkgs.items])

        local_rpms = set()
        to_install = set()
        to_remove = set()
        to_keep = set()
        to_upgrade = set()
        modules_to_enable = {}
        modules_to_reset = {}
        for event in self.consume(RpmTransactionTasks, PESRpmTransactionTasks):
            local_rpms.update(event.local_rpms)
            to_install.update(event.to_install)
            to_remove.update(installed_pkgs.intersection(event.to_remove))
            to_keep.update(installed_pkgs.intersection(event.to_keep))
            modules_to_enable.update({
                '{}:{}'.format(m.name, m.stream): m
                for m in event.modules_to_enable
            })
            modules_to_reset.update({
                '{}:{}'.format(m.name, m.stream): m
                for m in event.modules_to_reset
            })

        to_remove.difference_update(to_keep)

        # run upgrade for the rest of RH signed pkgs which we do not have rule for
        to_upgrade = installed_pkgs - (to_install | to_remove)

        self.produce(
            FilteredRpmTransactionTasks(
                local_rpms=list(local_rpms),
                to_install=list(to_install),
                to_remove=list(to_remove),
                to_keep=list(to_keep),
                to_upgrade=list(to_upgrade),
                modules_to_reset=list(modules_to_reset.values()),
                modules_to_enable=list(modules_to_enable.values())))
Ejemplo n.º 15
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)