Beispiel #1
0
    def a20_install_extra_pkgs(self):
        """
        Install required and useful packages for OL-type installs, read the
        list of packages from oci-migrate-conf.yaml, ol_os_packages_to_install.

        Returns
        -------
            bool: True on success, False otherwise.
        """

        def get_ol_package_list():
            """
            Retrieve the list of packages to install from oci-migrate-config file.

            Returns
            -------
            list: list of package names to install.
            """
            _logger.debug('Collection list of packages.')
            try:
                pkg_list = get_config_data('ol_os_packages_to_install')
                _logger.debug('Package list: %s' % pkg_list)
                return pkg_list
            except Exception as e:
                _logger.warning('Failed to find a list of packages: %s' % str(e))
                return False

        _logger.debug('__ Installing extra packages.')
        #
        # collect packages to install
        packages = get_ol_package_list()
        if not bool(packages):
            _logger.debug('No extra packages to install.')
            return True
        #
        #
        try:
            #
            # set current nameserver config.
            if system_tools.set_nameserver():
                _logger.debug('Updating nameserver info succeeded.')
            else:
                _logger.error('  Failed to update nameserver info.')
            #
            # get package manipulation tool.
            pkg_mgr = self.exec_yum \
                if self.package_tool['pkg_mgr'] == 'yum' else self.exec_dnf
            #
            # install packages
            for pkg in packages:
                #
                # verify if the package is available, the correct channel enabled.
                rpmlist = pkg_mgr(self.package_tool['package_available'] + [pkg])
                pkg_present = False
                for lline in rpmlist.splitlines():
                    _logger.debug('%s' % lline)
                    if pkg in lline:
                        _logger.debug('The rpm %s is available.' % pkg)
                        pkg_present = True
                        break
                if not pkg_present:
                    _logger.error('  The rpm %s is missing.' % pkg)
                    migrate_data.migrate_preparation = False
                    migrate_data.migrate_non_upload_reason += \
                        '\n  The rpm package %s is missing from ' \
                        'the yum repository.' % pkg
                    return False
                else:
                    installoutput = \
                        pkg_mgr(self.package_tool['package_install'] + [pkg])
                    _logger.debug('Successfully installed pkg %s:\n%s'
                                  % (pkg, installoutput))
                    migrate_tools.result_msg(msg='Installed %s.' % pkg,
                                             result=False)
                pause_msg(msg='Installed %s here, or not.' % pkg,
                          pause_flag='_OCI_CHROOT')
            #
            # restore nameserver data
            if system_tools.restore_nameserver():
                _logger.debug('Restoring nameserver info succeeded.')
            else:
                _logger.error('  Failed to restore nameserver info.')

        except Exception as e:
            errmsg = 'Failed to install one or more packages of ' \
                     '%s:\n%s' % (packages, str(e))
            _logger.critical('   %s' % errmsg)
            migrate_tools.error_msg('%s' % errmsg)
            migrate_data.migrate_preparation = False
            migrate_data.migrate_non_upload_reason += '\n  %s' % errmsg
            return False
        return True
Beispiel #2
0
    def a20_install_extra_pkgs(self):
        """
        Install required and useful packages for OL-type installs, read the
        list of packages from oci-migrate-conf.yaml, ol_os_packages_to_install.

        Returns
        -------
            bool: True on success, False otherwise.
        """
        def get_ubuntu_package_list():
            """
            Retrieve the list of packages to install from oci-migrate-config file.

            Returns
            -------
            list: list of package names to install.
            """
            _logger.debug('Collection list of packages.')
            try:
                pkg_list = get_config_data('ubuntu_os_packages_to_install_apt')
                if not bool(pkg_list):
                    _logger.debug('apt package list is empty.')
                    return False
                _logger.debug('Package list: %s', pkg_list)
                return pkg_list
            except Exception as e:
                _logger.warning('Failed to find a list of packages: %s',
                                str(e))
                return False

        _logger.debug('Installing extra packages.')
        packages = get_ubuntu_package_list()
        if not bool(packages):
            _logger.debug('No extra packages to install.')
            return True
        try:
            #
            # set current nameserver config.
            if system_tools.set_nameserver():
                _logger.debug('Updating nameserver info succeeded.')
            else:
                _logger.error('  Failed to update nameserver info.')

            #
            # update package list
            update_output = self._exec_apt(['update'])
            _logger.debug('Successfully updated package list.')
            #
            # install packages
            for pkg in packages:
                #
                # verify if the package is available.
                pkg_present = False
                deblist = self._exec_apt(['list', pkg])
                for lline in deblist.splitlines():
                    _logger.debug('%s', lline)
                    if pkg in lline:
                        _logger.debug('The deb package %s is available.', pkg)
                        pkg_present = True
                        break
                if not pkg_present:
                    _logger.debug('The deb package %s is missing.', pkg)
                    migrate_data.migrate_preparation = False
                    migrate_data.migrate_non_upload_reason +=\
                        '\n  The deb package %s is missing from ' \
                        'the repository.' % pkg
                    return False

                installoutput = self._exec_apt(['install', '-y', pkg])
                _logger.debug('Successfully installed %s:\n%s', pkg,
                              installoutput)
                pause_msg(msg='Installed %s here, or not.' % pkg,
                          pause_flag='_OCI_CHROOT')

            if system_tools.restore_nameserver():
                _logger.debug('Restoring nameserver info succeeded.')
            else:
                _logger.error('  Failed to restore nameserver info.')

        except Exception as e:
            _logger.critical(
                '   Failed to install one or more packages of %s:\n%s',
                packages, str(e))
            error_msg('Failed to install one or more packages of %s:\n%s' %
                      (packages, str(e)))
            migrate_data.migrate_non_upload_reason += \
                '\n Failed to install on or more packages ' \
                'of %s: %s' % (packages, str(e))
            return False
        return True