Exemple #1
0
    def process(self):
        skip_rhsm = os.getenv('LEAPP_DEVEL_SKIP_RHSM', '0') == '1'
        mounts_dir = os.getenv('LEAPP_CONTAINER_ROOT',
                               '/var/lib/leapp/scratch')
        container_root = os.path.join(mounts_dir, 'mounts')
        error_flag = False

        if skip_rhsm:
            self.log.warning(
                "LEAPP_DEVEL_SKIP_RHSM has been used. The upgrade is unsupported."
            )

        if not skip_rhsm and not self.is_system_registered_and_attached():
            error = preparetransaction.ErrorData(
                summary='The system is not registered or subscribed.',
                details=(
                    'The system has to be registered and subscribed to be able'
                    ' to proceed the upgrade. Register your system with the'
                    ' subscription-manager tool and attach'
                    ' it to proper SKUs to be able to proceed the upgrade.'))
            preparetransaction.produce_error(error)
            return

        # TODO: Find a better place where to run this (perhaps even gate this behind user prompt/question)
        # FIXME: fails on insufficient permissions
        cmd = ['/usr/bin/dnf', 'clean', 'all']
        _unused, error = preparetransaction.guard_call(cmd)
        if error:
            preparetransaction.produce_error(
                error, summary='Cannot perform dnf cleanup.')
            return

        # prepare container #
        # TODO: wrap in one function (create ofs dirs, mount), or even context
        #       manager (enter -> create dirs, mount; exit -> umount)?
        xfs_presence = next(self.consume(XFSPresence), XFSPresence())
        if xfs_presence.present and xfs_presence.without_ftype:
            error = preparetransaction.create_disk_image(mounts_dir)
            if error:
                self.produce_error(error)

        ofs_info, error = preparetransaction.create_overlayfs_dirs(
            container_root)
        if not ofs_info:
            preparetransaction.produce_error(error)
            return

        error = preparetransaction.mount_overlayfs(ofs_info)
        if error:
            preparetransaction.produce_error(error)
            preparetransaction.remove_overlayfs_dirs(container_root)
            preparetransaction.remove_disk_image(mounts_dir)
            return

        prev_rhsm_release = None
        if not skip_rhsm:
            prev_rhsm_release = self.get_rhsm_system_release()
            if prev_rhsm_release is None:
                # TODO: error is produced inside - will be refactored later
                # with the whole actor
                return
            # switch EngID to use RHEL 8 subscriptions #
            error = self.update_rhel_subscription(ofs_info)

        if not error:
            dnfplugin_spath = self.get_file_path('rhel_upgrade.py')
            dnfplugin_dpath = '/lib/python2.7/site-packages/dnf-plugins'

            error = preparetransaction.copy_file_to_container(
                ofs_info, dnfplugin_spath, dnfplugin_dpath)
            if error:
                return error

        error = self.dnf_plugin_rpm_download(ofs_info)
        if not error:
            error = preparetransaction.copy_file_from_container(
                ofs_info,
                '/etc/yum.repos.d/redhat.repo',
                '/etc/yum.repos.d/',
                'redhat.repo.upgrade',
            )

        if error:
            preparetransaction.produce_error(error)
            error_flag = True

        # If Subscription Manager OS Release was set before, make sure we do not change it
        if not skip_rhsm and 'Release:' in prev_rhsm_release:
            release = prev_rhsm_release.split(':')[1].strip()
            cmd = ['subscription-manager', 'release', '--set', release]
            _unused, error = preparetransaction.guard_call(
                cmd, guards=(preparetransaction.connection_guard(), ))
            if error:
                preparetransaction.produce_error(
                    error, summary='Cannot set minor release version.')
                error_flag = True

        # clean #
        error = preparetransaction.umount_overlayfs(ofs_info)
        if error:
            preparetransaction.produce_error(error)
            error_flag = True

        preparetransaction.remove_overlayfs_dirs(container_root)
        preparetransaction.remove_disk_image(mounts_dir)

        # produce msg for upgrading actor
        if not error_flag:
            self.produce_used_target_repos()
Exemple #2
0
    def process(self):
        container_root = os.getenv('LEAPP_CONTAINER_ROOT', '/tmp/leapp-overlay')
        error_flag = False

        if not self.is_system_registered_and_attached():
            error = preparetransaction.ErrorData(
                summary='The system is not registered or subscribed.',
                details=('The system has to be registered and subscribed to be able'
                         ' to proceed the upgrade. Register your system with the'
                         ' subscription-manager tool and attach'
                         ' it to proper SKUs to be able to proceed the upgrade.'))
            self.produce_error(error)
            return

        # TODO: Find a better place where to run this (perhaps even gate this behind user prompt/question)
        preparetransaction.call(['/usr/bin/dnf', 'clean', 'all'])

        # prepare container #
        ofs_info, error = preparetransaction.create_overlayfs_dirs(container_root)
        if not ofs_info:
            self.produce_error(error)
            return

        error = preparetransaction.mount_overlayfs(ofs_info)
        if error:
            self.produce_error(error)
            preparetransaction.remove_overlayfs_dirs(container_root)
            return

        # switch EngID to use RHEL 8 subscriptions #
        prev_rhsm_release = preparetransaction.call(['subscription-manager', 'release'])[0]
        error = self.update_rhel_subscription(ofs_info)
        if not error:
            error = self.dnf_shell_rpm_download(ofs_info)

        if not error:
            error = preparetransaction.copy_file_from_container(
                        ofs_info,
                        '/etc/yum.repos.d/redhat.repo',
                        '/etc/yum.repos.d/',
                        'redhat.repo.upgrade',
                        )

        if error:
            self.produce_error(error)
            error_flag = True

        # If Subscription Manager OS Release was set before, make sure we do not change it
        if 'Release:' in prev_rhsm_release:
            release = prev_rhsm_release.split(':')[1].strip()
            error = preparetransaction.check_cmd_call(['subscription-manager', 'release', '--set', release])
            if error:
                self.produce_error(error)
                error_flag = True

        # clean #
        error = preparetransaction.umount_overlayfs(ofs_info)
        if error:
            self.produce_error(error)
            error_flag = True

        preparetransaction.remove_overlayfs_dirs(container_root)

        # produce msg for upgrading actor
        if not error_flag:
            self.produce_used_target_repos()