Esempio n. 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
        """
        d = distro.detect()

        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 d.name in ['redhat', '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 d.name in ['sles']:
            utils.system('mkinitrd %s -k %s -i %s -M %s' %
                         (args, image, initrd, system_map))
        elif d.name 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 distro %s' % d.name)
Esempio n. 2
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
        """
        d = distro.detect()

        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 d.name in ['redhat', '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 d.name in ['sles']:
            utils.system('mkinitrd %s -k %s -i %s -M %s' %
                         (args, image, initrd, system_map))
        elif d.name 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 distro %s' % d.name)
Esempio n. 3
0
def install_distro_packages(distro_pkg_map, interactive=False):
    '''
    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
    '''
    if not interactive:
        os.environ['DEBIAN_FRONTEND'] = 'noninteractive'

    result = False
    pkgs = []
    detected_distro = distro.detect()

    distro_specs = [
        spec for spec in distro_pkg_map if isinstance(spec, distro.Spec)
    ]

    for distro_spec in distro_specs:
        if distro_spec.name != detected_distro.name:
            continue

        if (distro_spec.arch is not None
                and distro_spec.arch != detected_distro.arch):
            continue

        if int(detected_distro.version) < distro_spec.min_version:
            continue

        if (distro_spec.min_release is not None
                and int(detected_distro.release) < distro_spec.min_release):
            continue

        pkgs = distro_pkg_map[distro_spec]
        break

    if not pkgs:
        pkgs = distro_pkg_map.get(detected_distro.name, None)

    if pkgs:
        needed_pkgs = []
        software_manager = SoftwareManager()
        for pkg in pkgs:
            if not software_manager.check_installed(pkg):
                needed_pkgs.append(pkg)
        if needed_pkgs:
            text = ' '.join(needed_pkgs)
            logging.info('Installing packages "%s"', text)
            result = software_manager.install(text)
    return result
Esempio n. 4
0
def install_distro_packages(distro_pkg_map, interactive=False):
    '''
    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
    :return: True if any packages were actually installed, False otherwise
    '''
    if not interactive:
        os.environ['DEBIAN_FRONTEND'] = 'noninteractive'

    result = False
    pkgs = []
    detected_distro = distro.detect()

    distro_specs = [spec for spec in distro_pkg_map if
                    isinstance(spec, distro.Spec)]

    for distro_spec in distro_specs:
        if distro_spec.name != detected_distro.name:
            continue

        if (distro_spec.arch is not None and
                distro_spec.arch != detected_distro.arch):
            continue

        if int(detected_distro.version) < distro_spec.min_version:
            continue

        if (distro_spec.min_release is not None and
                int(detected_distro.release) < distro_spec.min_release):
            continue

        pkgs = distro_pkg_map[distro_spec]
        break

    if not pkgs:
        pkgs = distro_pkg_map.get(detected_distro.name, None)

    if pkgs:
        needed_pkgs = []
        software_manager = SoftwareManager()
        for pkg in pkgs:
            if not software_manager.check_installed(pkg):
                needed_pkgs.append(pkg)
        if needed_pkgs:
            text = ' '.join(needed_pkgs)
            logging.info('Installing packages "%s"', text)
            result = software_manager.install(text)
    return result
Esempio n. 5
0
def get_default_guest_os_info():
    """
    Gets the default asset and variant information depending on host OS
    """
    os_info = {'asset': 'jeos-19-64', 'variant': DEFAULT_GUEST_OS}

    detected = distro.detect()
    if detected.name == 'fedora' and int(detected.version) >= 20:
        os_info = {'asset': 'jeos-20-64', 'variant': 'JeOS.20'}

    return os_info
Esempio n. 6
0
 def finish_init(self):
     self.src_dir = os.path.join(self.SOURCES_dir, 'patches.addon')
     self.cfg_dir = os.path.join(self.SOURCES_dir, 'config.addon')
     d = distro.detect()
     if d.version == '11':
         self.spec = os.path.join(self.SPECS_dir, 'kernel-ppc64.spec')
         self.config_file = os.path.join(self.cfg_dir, utils.get_current_kernel_arch(), utils.get_current_kernel_arch())
         # sles11 needs both kernel and kernel-base
         self.binrpm_pattern = re.compile(r'kernel-%s-(base|[0-9])' % utils.get_current_kernel_arch())
     if d.version == '12':
         self.spec = os.path.join(self.SPECS_dir, 'kernel-default.spec')
         self.config_file = os.path.join(self.cfg_dir, utils.get_current_kernel_arch(), 'default')
         self.binrpm_pattern = re.compile(r'kernel-default-[0-9]')
Esempio n. 7
0
 def finish_init(self):
     self.src_dir = os.path.join(self.SOURCES_dir, 'patches.addon')
     self.cfg_dir = os.path.join(self.SOURCES_dir, 'config.addon')
     d = distro.detect()
     if d.version == '11':
         self.spec = os.path.join(self.SPECS_dir, 'kernel-ppc64.spec')
         self.config_file = os.path.join(self.cfg_dir, utils.get_current_kernel_arch(), utils.get_current_kernel_arch())
         # sles11 needs both kernel and kernel-base
         self.binrpm_pattern = re.compile(r'kernel-%s-(base|[0-9])' % utils.get_current_kernel_arch())
     if d.version == '12':
         self.spec = os.path.join(self.SPECS_dir, 'kernel-default.spec')
         self.config_file = os.path.join(self.cfg_dir, utils.get_current_kernel_arch(), 'default')
         self.binrpm_pattern = re.compile(r'kernel-default-[0-9]')
Esempio n. 8
0
    def setup_source(self):
        # setup tarball
        if len(self.patches) > 0:
            # need to ensure the tarball's contents are relative to SOURCES
            utils.system('tar jCcf %s %s.tar.bz2 %s' %
                         (self.SOURCES_dir, self.src_dir,
                          os.path.basename(self.src_dir)))
            # append to series file
            with open(os.path.join(self.SOURCES_dir, 'series.conf'),
                      'a') as series:
                for (spec, local, md5sum) in self.patches:
                    series.write("%s\n" %
                                 os.path.relpath(local, self.SOURCES_dir))

        if len(self.configs) > 0:
            with open(self.config_file, 'w+') as cfg:
                for config in self.configs:
                    cfg.write("%s\n" % config)
            # need to ensure the tarball's contents are relative to SOURCES
            utils.system('tar jCcf %s %s.tar.bz2 %s' %
                         (self.SOURCES_dir, self.cfg_dir,
                          os.path.basename(self.cfg_dir)))
            # if we are mucking with the new CONFIG symbols, the build will
            # fail if any dependencies get pulled in
            utils.system(
                'touch /usr/src/packages/SOURCES/TOLERATE-UNKNOWN-NEW-CONFIG-OPTIONS'
            )

        # generate spec file
        cwd = os.getcwd()
        os.chdir(self.SOURCES_dir)
        utils.system('./mkspec')
        os.chdir(cwd)

        # copy spec file
        d = distro.detect()
        if d.version == '11':
            utils.system('cp %s %s' % (os.path.join(
                self.SOURCES_dir, 'kernel-ppc64.spec'), self.spec))
        else:
            utils.system('cp %s %s' % (os.path.join(
                self.SOURCES_dir, 'kernel-default.spec'), self.spec))
Esempio n. 9
0
    def setup_source(self):
        # setup tarball
        if len(self.patches) > 0:
            # need to ensure the tarball's contents are relative to SOURCES
            utils.system('tar jCcf %s %s.tar.bz2 %s' % (self.SOURCES_dir,
                                                        self.src_dir,
                                                        os.path.basename(self.src_dir)))
            # append to series file
            with open(os.path.join(self.SOURCES_dir, 'series.conf'), 'a') as series:
                for (spec, local, md5sum) in self.patches:
                    series.write("%s\n" % os.path.relpath(local, self.SOURCES_dir))

        if len(self.configs) > 0:
            with open(self.config_file, 'w+') as cfg:
                for config in self.configs:
                    cfg.write("%s\n" % config)
            # need to ensure the tarball's contents are relative to SOURCES
            utils.system('tar jCcf %s %s.tar.bz2 %s' % (self.SOURCES_dir,
                                                        self.cfg_dir,
                                                        os.path.basename(self.cfg_dir)))
            # if we are mucking with the new CONFIG symbols, the build will
            # fail if any dependencies get pulled in
            utils.system('touch /usr/src/packages/SOURCES/TOLERATE-UNKNOWN-NEW-CONFIG-OPTIONS')

        # generate spec file
        cwd = os.getcwd()
        os.chdir(self.SOURCES_dir)
        utils.system('./mkspec')
        os.chdir(cwd)

        # copy spec file
        d = distro.detect()
        if d.version == '11':
            utils.system('cp %s %s' % (
                          os.path.join(self.SOURCES_dir, 'kernel-ppc64.spec'),
                          self.spec))
        else:
            utils.system('cp %s %s' % (
                          os.path.join(self.SOURCES_dir, 'kernel-default.spec'),
                          self.spec))
Esempio n. 10
0
 def __init__(self):
     """
     Probe system, and save information for future reference.
     """
     self.distro = distro.detect().name
Esempio n. 11
0
def rpm_kernel_vendor(job, rpm_package, subdir):
    d = distro.detect()
    if d.name == "sles":
        return rpm_kernel_suse(job, rpm_package, subdir)
    else:
        return rpm_kernel(job, rpm_package, subdir)
Esempio n. 12
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 = distro.detect().name
        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)")
Esempio n. 13
0
 def __init__(self):
     """
     Probe system, and save information for future reference.
     """
     self.distro = distro.detect().name
    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 = distro.detect().name
        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)")
Esempio n. 15
0
def srpm_kernel_vendor(job, rpm_package, subdir):
    d = distro.detect()
    if d.name == "sles":
        return srpm_kernel_suse(job, rpm_package, subdir)
    else:
        return srpm_kernel(job, rpm_package, subdir)