예제 #1
0
    def mkinitrd(self, version, image, system_map, initrd):
        """Build kernel initrd image.
        Try to use distro specific way to build initrd image.
        Parameters:
                version
                        new kernel version
                image
                        new kernel image file
                system_map
                        System.map file
                initrd
                        initrd image file to build
        """
        vendor = utils.get_os_vendor()

        if os.path.isfile(initrd):
            print "Existing %s file, will remove it." % initrd
            os.remove(initrd)

        args = self.job.config_get('kernel.mkinitrd_extra_args')

        # don't leak 'None' into mkinitrd command
        if not args:
            args = ''

        # It is important to match the version with a real directory inside
        # /lib/modules
        real_version_list = glob.glob('/lib/modules/%s*' % version)
        rl = len(real_version_list)
        if rl == 0:
            logging.error("No directory %s found under /lib/modules. Initramfs"
                          "creation will most likely fail and your new kernel"
                          "will fail to build", version)
        else:
            if rl > 1:
                logging.warning("Found more than one possible match for "
                                "kernel version %s under /lib/modules", version)
            version = os.path.basename(real_version_list[0])

        if vendor in ['Red Hat', 'Fedora']:
            try:
                cmd = os_dep.command('dracut')
                full_cmd = '%s -f %s %s' % (cmd, initrd, version)
            except ValueError:
                cmd = os_dep.command('mkinitrd')
                full_cmd = '%s %s %s %s' % (cmd, args, initrd, version)
            utils.system(full_cmd)
        elif vendor in ['SUSE']:
            utils.system('mkinitrd %s -k %s -i %s -M %s' %
                         (args, image, initrd, system_map))
        elif vendor in ['Debian', 'Ubuntu']:
            if os.path.isfile('/usr/sbin/mkinitrd'):
                cmd = '/usr/sbin/mkinitrd'
            elif os.path.isfile('/usr/sbin/mkinitramfs'):
                cmd = '/usr/sbin/mkinitramfs'
            else:
                raise error.TestError('No Debian initrd builder')
            utils.system('%s %s -o %s %s' % (cmd, args, initrd, version))
        else:
            raise error.TestError('Unsupported vendor %s' % vendor)
예제 #2
0
    def run_start(self):
        """A run within this job is starting"""
        self.__send_status('GOOD', '----', '----', 'run starting')

        # Load up the autobench.conf if it exists.
        conf = autobench_load("/etc/autobench.conf")
        if 'partitions' in conf:
            self.job.config_set('partition.partitions', conf['partitions'])

        # Search the boot loader configuration for the autobench entry,
        # and extract its args.
        args = None
        for entry in self.job.bootloader.get_entries().itervalues():
            if entry['title'].startswith('autobench'):
                args = entry.get('args')

        if args:
            args = re.sub(r'autobench_args:.*', '', args)
            args = re.sub(r'root=\S*', '', args)
            args += " root=" + self.__root_device()

            self.job.config_set('boot.default_args', args)

        # Turn off boot_once semantics.
        self.job.config_set('boot.set_default', True)

        # For RedHat installs we do not load up the module.conf
        # as they cannot be builtin.  Pass them as arguments.
        vendor = utils.get_os_vendor()
        if vendor in ['Red Hat', 'Fedora'] and 'modules' in conf:
            args = '--allow-missing'
            for mod in conf['modules']:
                args += " --with " + mod
            self.job.config_set('kernel.mkinitrd_extra_args', args)
예제 #3
0
    def mkinitrd(self, version, image, system_map, initrd):
        """Build kernel initrd image.
        Try to use distro specific way to build initrd image.
        Parameters:
                version
                        new kernel version
                image
                        new kernel image file
                system_map
                        System.map file
                initrd
                        initrd image file to build
        """
        vendor = utils.get_os_vendor()

        if os.path.isfile(initrd):
            print "Existing %s file, will remove it." % initrd
            os.remove(initrd)

        args = self.job.config_get('kernel.mkinitrd_extra_args')

        # don't leak 'None' into mkinitrd command
        if not args:
            args = ''

        # It is important to match the version with a real directory inside
        # /lib/modules
        real_version_list = glob.glob('/lib/modules/%s*' % version)
        rl = len(real_version_list)
        if rl == 0:
            logging.error("No directory %s found under /lib/modules. Initramfs"
                          "creation will most likely fail and your new kernel"
                          "will fail to build", version)
        else:
            if rl > 1:
                logging.warning("Found more than one possible match for "
                                "kernel version %s under /lib/modules", version)
            version = os.path.basename(real_version_list[0])

        if vendor in ['Red Hat', 'Fedora']:
            try:
                cmd = os_dep.command('dracut')
                full_cmd = '%s -f %s %s' % (cmd, initrd, version)
            except ValueError:
                cmd = os_dep.command('mkinitrd')
                full_cmd = '%s %s %s %s' % (cmd, args, initrd, version)
            utils.system(full_cmd)
        elif vendor in ['SUSE']:
            utils.system('mkinitrd %s -k %s -i %s -M %s' %
                         (args, image, initrd, system_map))
        elif vendor in ['Debian', 'Ubuntu']:
            if os.path.isfile('/usr/sbin/mkinitrd'):
                cmd = '/usr/sbin/mkinitrd'
            elif os.path.isfile('/usr/sbin/mkinitramfs'):
                cmd = '/usr/sbin/mkinitramfs'
            else:
                raise error.TestError('No Debian initrd builder')
            utils.system('%s %s -o %s %s' % (cmd, args, initrd, version))
        else:
            raise error.TestError('Unsupported vendor %s' % vendor)
예제 #4
0
    def run_start(self):
        """A run within this job is starting"""
        self.__send_status('GOOD', '----', '----', 'run starting')

        # Load up the autobench.conf if it exists.
        conf = autobench_load("/etc/autobench.conf")
        if 'partitions' in conf:
            self.job.config_set('partition.partitions',
                    conf['partitions'])

        # Search the boot loader configuration for the autobench entry,
        # and extract its args.
        args = None
        for entry in self.job.bootloader.get_entries().itervalues():
            if entry['title'].startswith('autobench'):
                args = entry.get('args')

        if args:
            args = re.sub(r'autobench_args:.*', '', args)
            args = re.sub(r'root=\S*', '', args)
            args += " root=" + self.__root_device()

            self.job.config_set('boot.default_args', args)

        # Turn off boot_once semantics.
        self.job.config_set('boot.set_default', True)

        # For RedHat installs we do not load up the module.conf
        # as they cannot be builtin.  Pass them as arguments.
        vendor = utils.get_os_vendor()
        if vendor in ['Red Hat', 'Fedora'] and 'modules' in conf:
            args = '--allow-missing'
            for mod in conf['modules']:
                args += " --with " + mod
            self.job.config_set('kernel.mkinitrd_extra_args', args)
예제 #5
0
def install_distro_packages(distro_pkg_map):
    '''
    Installs packages for the currently running distribution

    This utility function checks if the currently running distro is a
    key in the distro_pkg_map dictionary, and if there is a list of packages
    set as its value.

    If these conditions match, the packages will be installed using the
    software manager interface, thus the native packaging system if the
    currenlty running distro.

    @type disto_pkg_map: dict
    @param distro_pkg_map: mapping of distro name, as returned by
        utils.get_os_vendor(), to a list of package names
    @returns: True if any packages were actually installed, False otherwise
    '''
    result = False
    distro = utils.get_os_vendor()
    if distro_pkg_map.has_key(distro):
        pkgs = distro_pkg_map.get(distro, None)
        needed_pkgs = []
        if pkgs is not None:
            s = SoftwareManager()
            for p in pkgs:
                if not s.check_installed(p):
                    needed_pkgs.append(p)
        if needed_pkgs:
            text = ' '.join(needed_pkgs)
            logging.info('Installing packages "%s"', text)
            result = s.install(text)
    return result
예제 #6
0
def install_distro_packages(distro_pkg_map):
    '''
    Installs packages for the currently running distribution

    This utility function checks if the currently running distro is a
    key in the distro_pkg_map dictionary, and if there is a list of packages
    set as its value.

    If these conditions match, the packages will be installed using the
    software manager interface, thus the native packaging system if the
    currenlty running distro.

    @type disto_pkg_map: dict
    @param distro_pkg_map: mapping of distro name, as returned by
        utils.get_os_vendor(), to a list of package names
    @returns: True if any packages were actually installed, False otherwise
    '''
    result = False
    distro = utils.get_os_vendor()
    if distro_pkg_map.has_key(distro):
        pkgs = distro_pkg_map.get(distro, None)
        needed_pkgs = []
        if pkgs is not None:
            s = SoftwareManager()
            for p in pkgs:
                if not s.check_installed(p):
                    needed_pkgs.append(p)
        if needed_pkgs:
            text = ' '.join(needed_pkgs)
            logging.info('Installing packages "%s"', text)
            result = s.install(text)
    return result
예제 #7
0
 def __init__(self, host=None):
     self.host = host
     self.got = False
     self.installed = False
     self.serverdir = utils.get_server_dir()
     self.os_vendor = client_utils.get_os_vendor()
     self.server_system_wide_install = _server_system_wide_install()
     super(BaseAutotest, self).__init__()
예제 #8
0
 def __init__(self, host=None):
     self.host = host
     self.got = False
     self.installed = False
     self.serverdir = utils.get_server_dir()
     self.os_vendor = client_utils.get_os_vendor()
     self.server_system_wide_install = _server_system_wide_install()
     super(BaseAutotest, self).__init__()
예제 #9
0
def rpm_kernel_vendor(job, rpm_package, subdir):
    vendor = utils.get_os_vendor()
    if vendor == "SUSE":
        return rpm_kernel_suse(job, rpm_package, subdir)
    else:
        return rpm_kernel(job, rpm_package, subdir)
예제 #10
0
    def __init__(self, job, harness_args):
        """
                job
                        The job object for this job
        """
        self.autodir = os.path.abspath(os.environ['AUTODIR'])
        self.setup(job)

        tmpdir = os.path.join(self.autodir, 'tmp')
        tests_dir = settings.get_value('COMMON', 'test_output_dir',
                                       default=tmpdir)

        src = job.control_get()
        dest = os.path.join(tests_dir, 'control')
        if os.path.abspath(src) != os.path.abspath(dest):
            shutil.copyfile(src, dest)
            job.control_set(dest)

        def yield_default_initlevel():
            """
            If we really can't figure out something better, default to '2',
            which is the case with some debian systems
            """
            init_default = '2'
            logging.error('Could not determine initlevel, assuming %s' %
                          init_default)
            return init_default

        rc = os.path.join(self.autodir, 'tools/autotest')
        # see if system supports event.d versus systemd versus inittab
        supports_eventd = os.path.exists('/etc/event.d')
        supports_systemd = os.path.exists('/etc/systemd')
        supports_inittab = os.path.exists('/etc/inittab')
        # This is the best heuristics I can think of for identifying
        # an embedded system running busybox
        busybox_system = (os.readlink('/bin/sh') == 'busybox')

        # Small busybox systems usually use /etc/rc.d/ straight
        if busybox_system:
            initdefault = ''

        elif supports_eventd or supports_systemd:
            try:
                # NB: assuming current runlevel is default
                cmd_result = utils.run('/sbin/runlevel', verbose=False)
                initdefault = cmd_result.stdout.split()[1]
            except (error.CmdError, IndexError):
                initdefault = yield_default_initlevel()

        elif supports_inittab:
            try:
                cmd_result = utils.run('grep :initdefault: /etc/inittab',
                                       verbose=False)
                initdefault = cmd_result.stdout.split(':')[1]
            except (error.CmdError, IndexError):
                initdefault = yield_default_initlevel()

        else:
            initdefault = yield_default_initlevel()

        vendor = utils.get_os_vendor()
        service = '/etc/init.d/autotest'
        if vendor == 'SUSE':
            service_link = '/etc/init.d/rc%s.d/S99autotest' % initdefault
        else:
            service_link = '/etc/rc%s.d/S99autotest' % initdefault
        try:
            if os.path.islink(service):
                os.remove(service)
            if os.path.islink(service_link):
                os.remove(service_link)
            os.symlink(rc, service)
            os.symlink(rc, service_link)
        except (OSError, IOError):
            logging.info("Could not symlink init scripts (lack of permissions)")
예제 #11
0
def rpm_kernel_vendor(job, rpm_package, subdir):
    vendor = utils.get_os_vendor()
    if vendor == "SUSE":
        return rpm_kernel_suse(job, rpm_package, subdir)
    else:
        return rpm_kernel(job, rpm_package, subdir)
예제 #12
0
 def __init__(self):
     """
     Probe system, and save information for future reference.
     """
     self.distro = utils.get_os_vendor()
예제 #13
0
 def __init__(self):
     """
     Probe system, and save information for future reference.
     """
     self.distro = utils.get_os_vendor()
     self.high_level_pms = ['apt-get', 'yum', 'zypper']
예제 #14
0
 def __init__(self):
     """
     Probe system, and save information for future reference.
     """
     self.distro = utils.get_os_vendor()
예제 #15
0
 def __init__(self):
     """
     Probe system, and save information for future reference.
     """
     self.distro = utils.get_os_vendor()
     self.high_level_pms = ['apt-get', 'yum', 'zypper']