Ejemplo 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
        """
        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 Core']:
            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)
Ejemplo n.º 2
0
    def get_package_management(self):
        """
        Determine the supported package management systems present on the
        system. If more than one package management system installed, try
        to find the best supported system.
        """
        list_supported = []
        for high_level_pm in self.high_level_pms:
            try:
                os_dep.command(high_level_pm)
                list_supported.append(high_level_pm)
            except Exception:
                pass

        pm_supported = None
        if len(list_supported) == 0:
            pm_supported = None
        if len(list_supported) == 1:
            pm_supported = list_supported[0]
        elif len(list_supported) > 1:
            if 'apt-get' in list_supported and self.distro in ['Debian', 'Ubuntu']:
                pm_supported = 'apt-get'
            elif 'yum' in list_supported and self.distro == 'Fedora':
                pm_supported = 'yum'
            else:
                pm_supported = list_supported[0]

        logging.debug('Package Manager backend: %s' % pm_supported)
        return pm_supported
Ejemplo n.º 3
0
def has_pbzip2():
    """Check if parallel bzip2 is available on this system."""
    try:
        os_dep.command("pbzip2")
    except ValueError:
        return False
    return True
Ejemplo n.º 4
0
def has_pbzip2():
    '''Check if parallel bzip2 is available on this system.'''
    try:
        os_dep.command('pbzip2')
    except ValueError:
        return False
    return True
Ejemplo n.º 5
0
def convert(package, destination_format):
    """\
    Convert packages with the 'alien' utility. If alien is not installed, it
    throws a NotImplementedError exception.
    returns: filename of the package generated.
    """
    try:
        os_dep.command('alien')
    except Exception:
        e_msg = 'Cannot convert to %s, alien not installed' % destination_format
        raise error.TestError(e_msg)

    # alien supports converting to many formats, but its interesting to map
    # convertions only for the implemented package types.
    if destination_format == 'dpkg':
        deb_pattern = re.compile('[A-Za-z0-9_.-]*[.][d][e][b]')
        conv_output = utils.system_output('alien --to-deb %s 2>/dev/null' %
                                          package)
        converted_package = re.findall(deb_pattern, conv_output)[0]
    elif destination_format == 'rpm':
        rpm_pattern = re.compile('[A-Za-z0-9_.-]*[.][r][p][m]')
        conv_output = utils.system_output('alien --to-rpm %s 2>/dev/null' %
                                          package)
        converted_package = re.findall(rpm_pattern, conv_output)[0]
    else:
        e_msg = 'Convertion to format %s not implemented' % destination_format
        raise NotImplementedError(e_msg)

    print 'Package %s successfuly converted to %s' % \
            (os.path.basename(package), os.path.basename(converted_package))
    return os.path.abspath(converted_package)
Ejemplo n.º 6
0
def has_pbzip2():
    '''Check if parallel bzip2 is available on this system.'''
    try:
        os_dep.command('pbzip2')
    except ValueError:
        return False
    return True
Ejemplo n.º 7
0
def convert(package, destination_format):
    """\
    Convert packages with the 'alien' utility. If alien is not installed, it
    throws a NotImplementedError exception.
    returns: filename of the package generated.
    """
    try:
        os_dep.command('alien')
    except Exception:
        e_msg = 'Cannot convert to %s, alien not installed' % destination_format
        raise error.TestError(e_msg)

    # alien supports converting to many formats, but its interesting to map
    # convertions only for the implemented package types.
    if destination_format == 'dpkg':
        deb_pattern = re.compile('[A-Za-z0-9_.-]*[.][d][e][b]')
        conv_output = utils.system_output('alien --to-deb %s 2>/dev/null'
                                          % package)
        converted_package = re.findall(deb_pattern, conv_output)[0]
    elif destination_format == 'rpm':
        rpm_pattern = re.compile('[A-Za-z0-9_.-]*[.][r][p][m]')
        conv_output = utils.system_output('alien --to-rpm %s 2>/dev/null'
                                          % package)
        converted_package = re.findall(rpm_pattern, conv_output)[0]
    else:
        e_msg = 'Convertion to format %s not implemented' % destination_format
        raise NotImplementedError(e_msg)

    print 'Package %s successfuly converted to %s' % \
            (os.path.basename(package), os.path.basename(converted_package))
    return os.path.abspath(converted_package)
Ejemplo n.º 8
0
    def _get_service_cmds(self):
        """
        Figure out the commands used to control the NFS service.
        """
        error.context("Finding out appropriate commands to handle NFS service")
        service = os_dep.command("service")
        try:
            systemctl = os_dep.command("systemctl")
        except ValueError:
            systemctl = None

        if systemctl is not None:
            init_script = "/etc/init.d/nfs"
            service_file = "/lib/systemd/system/nfs-server.service"
            if os.path.isfile(init_script):
                service_name = "nfs"
            elif os.path.isfile(service_file):
                service_name = "nfs-server"
            else:
                raise error.TestError("Files %s and %s absent, don't know "
                                      "how to set up NFS for this host" %
                                      (init_script, service_file))
            start_cmd = "%s start %s.service" % (systemctl, service_name)
            stop_cmd = "%s stop %s.service" % (systemctl, service_name)
            restart_cmd = "%s restart %s.service" % (systemctl, service_name)
            status_cmd = "%s status %s.service" % (systemctl, service_name)
        else:
            start_cmd = "%s nfs start" % service
            stop_cmd = "%s nfs stop" % service
            restart_cmd = "%s nfs restart" % service
            status_cmd = "%s nfs status" % service

        return [start_cmd, stop_cmd, restart_cmd, status_cmd]
Ejemplo n.º 9
0
    def get_package_management(self):
        """
        Determine the supported package management systems present on the
        system. If more than one package management system installed, try
        to find the best supported system.
        """
        list_supported = []
        for high_level_pm in self.high_level_pms:
            try:
                os_dep.command(high_level_pm)
                list_supported.append(high_level_pm)
            except:
                pass

        pm_supported = None
        if len(list_supported) == 0:
            pm_supported = None
        if len(list_supported) == 1:
            pm_supported = list_supported[0]
        elif len(list_supported) > 1:
            if 'apt-get' in list_supported and self.distro in [
                    'Debian', 'Ubuntu'
            ]:
                pm_supported = 'apt-get'
            elif 'yum' in list_supported and self.distro == 'Fedora':
                pm_supported = 'yum'
            else:
                pm_supported = list_supported[0]

        logging.debug('Package Manager backend: %s' % pm_supported)
        return pm_supported
Ejemplo n.º 10
0
    def setup(self, tarball='bonnie++-1.03a.tgz'):
        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
        utils.extract_tarball_to_dir(tarball, self.srcdir)
        os.chdir(self.srcdir)

        os_dep.command('g++')
        utils.system('patch -p1 < ../bonnie++-1.03a-gcc43.patch')
        utils.configure()
        utils.make()
Ejemplo n.º 11
0
    def setup(self, tarball = 'bonnie++-1.03a.tgz'):
        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
        utils.extract_tarball_to_dir(tarball, self.srcdir)
        os.chdir(self.srcdir)

        os_dep.command('g++')
        utils.system('patch -p1 < ../bonnie++-1.03a-gcc43.patch')
        utils.system('./configure')
        utils.system('make')
Ejemplo n.º 12
0
 def initialize(self, qemu_path=''):
     if qemu_path:
         # Prepending the path at the beginning of $PATH will make the
         # version found on qemu_path be preferred over other ones.
         os.environ['PATH'] =  qemu_path + ":" + os.environ['PATH']
     try:
         self.qemu_img_path = os_dep.command('qemu-img')
         self.qemu_io_path = os_dep.command('qemu-io')
     except ValueError, e:
         raise error.TestNAError('Commands qemu-img or qemu-io missing')
Ejemplo n.º 13
0
 def initialize(self, qemu_path=''):
     if qemu_path:
         # Prepending the path at the beginning of $PATH will make the
         # version found on qemu_path be preferred over other ones.
         os.environ['PATH'] =  qemu_path + ":" + os.environ['PATH']
     try:
         self.qemu_img_path = os_dep.command('qemu-img')
         self.qemu_io_path = os_dep.command('qemu-io')
     except ValueError, e:
         raise error.TestNAError('Commands qemu-img or qemu-io missing')
Ejemplo n.º 14
0
    def set_install_params(self, test, params):
        super(KojiInstaller, self).set_install_params(test, params)
        os_dep.command("rpm")
        os_dep.command("yum")

        self.tag = params.get("%s_tag" % self.param_key_prefix, None)
        self.koji_cmd = params.get("%s_cmd" % self.param_key_prefix, None)
        if self.tag is not None:
            virt_utils.set_default_koji_tag(self.tag)
        self.koji_pkgs = eval(params.get("%s_pkgs" % self.param_key_prefix,
                                         "[]"))
Ejemplo n.º 15
0
    def set_install_params(self, test, params):
        super(KojiInstaller, self).set_install_params(test, params)
        os_dep.command("rpm")
        os_dep.command("yum")

        self.tag = params.get("%s_tag" % self.param_key_prefix, None)
        self.koji_cmd = params.get("%s_cmd" % self.param_key_prefix, None)
        if self.tag is not None:
            virt_utils.set_default_koji_tag(self.tag)
        self.koji_pkgs = eval(
            params.get("%s_pkgs" % self.param_key_prefix, "[]"))
Ejemplo n.º 16
0
def _dpkg_info(dpkg_package):
    """\
    Private function that returns a dictionary with information about a
    dpkg package file
    - type: Package management program that handles the file
    - system_support: If the package management program is installed on the
    system or not
    - source: If it is a source (True) our binary (False) package
    - version: The package version (or name), that is used to check against the
    package manager if the package is installed
    - arch: The architecture for which a binary package was built
    - installed: Whether the package is installed (True) on the system or not
    (False)
    """
    # We will make good use of what the file command has to tell us about the
    # package :)
    file_result = utils.system_output('file ' + dpkg_package)
    package_info = {}
    package_info['type'] = 'dpkg'
    # There's no single debian source package as is the case
    # with RPM
    package_info['source'] = False
    try:
        os_dep.command('dpkg')
        # Build the command strings that will be used to get package info
        # a_cmd - Command to determine package architecture
        # v_cmd - Command to determine package version
        # i_cmd - Command to determiine if package is installed
        a_cmd = 'dpkg -f ' + dpkg_package + ' Architecture 2>/dev/null'
        v_cmd = 'dpkg -f ' + dpkg_package + ' Package 2>/dev/null'
        i_cmd = 'dpkg -s ' + utils.system_output(v_cmd) + ' 2>/dev/null'

        package_info['system_support'] = True
        package_info['version'] = utils.system_output(v_cmd)
        package_info['arch'] = utils.system_output(a_cmd)
        # Checking if package is installed
        package_status = utils.system_output(i_cmd, ignore_status=True)
        not_inst_pattern = re.compile('not-installed', re.IGNORECASE)
        dpkg_not_installed = re.search(not_inst_pattern, package_status)
        if dpkg_not_installed:
            package_info['installed'] = False
        else:
            package_info['installed'] = True

    except Exception:
        package_info['system_support'] = False
        package_info['installed'] = False
        # The output of file is not as generous for dpkg files as
        # it is with rpm files
        package_info['arch'] = 'Not Available'
        package_info['version'] = 'Not Available'

    return package_info
Ejemplo n.º 17
0
def _dpkg_info(dpkg_package):
    """\
    Private function that returns a dictionary with information about a
    dpkg package file
    - type: Package management program that handles the file
    - system_support: If the package management program is installed on the
    system or not
    - source: If it is a source (True) our binary (False) package
    - version: The package version (or name), that is used to check against the
    package manager if the package is installed
    - arch: The architecture for which a binary package was built
    - installed: Whether the package is installed (True) on the system or not
    (False)
    """
    # We will make good use of what the file command has to tell us about the
    # package :)
    file_result = utils.system_output('file ' + dpkg_package)
    package_info = {}
    package_info['type'] = 'dpkg'
    # There's no single debian source package as is the case
    # with RPM
    package_info['source'] = False
    try:
        os_dep.command('dpkg')
        # Build the command strings that will be used to get package info
        # a_cmd - Command to determine package architecture
        # v_cmd - Command to determine package version
        # i_cmd - Command to determiine if package is installed
        a_cmd = 'dpkg -f ' + dpkg_package + ' Architecture 2>/dev/null'
        v_cmd = 'dpkg -f ' + dpkg_package + ' Package 2>/dev/null'
        i_cmd = 'dpkg -s ' + utils.system_output(v_cmd) + ' 2>/dev/null'

        package_info['system_support'] = True
        package_info['version'] = utils.system_output(v_cmd)
        package_info['arch'] = utils.system_output(a_cmd)
        # Checking if package is installed
        package_status = utils.system_output(i_cmd, ignore_status=True)
        not_inst_pattern = re.compile('not-installed', re.IGNORECASE)
        dpkg_not_installed = re.search(not_inst_pattern, package_status)
        if dpkg_not_installed:
            package_info['installed'] = False
        else:
            package_info['installed'] = True

    except Exception:
        package_info['system_support'] = False
        package_info['installed'] = False
        # The output of file is not as generous for dpkg files as
        # it is with rpm files
        package_info['arch'] = 'Not Available'
        package_info['version'] = 'Not Available'

    return package_info
Ejemplo n.º 18
0
    def setup(self, tarball='ffsb-6.0-rc2.tar.bz2'):
        """
        Uncompress the FFSB tarball and compiles it.

        @param tarball: FFSB tarball. Could be either a path relative to
                self.srcdir or a URL.
        """
        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
        utils.extract_tarball_to_dir(tarball, self.srcdir)
        os.chdir(self.srcdir)
        os_dep.command('gcc')
        utils.configure()
        utils.make()
Ejemplo n.º 19
0
 def initialize(self):
     try:
         import pexpect
     except ImportError:
         raise error.TestError("Missing python library pexpect. You have to "
                               "install the package python-pexpect or the "
                               "equivalent for your distro")
     try:
         os_dep.command("nmap")
     except ValueError:
         raise error.TestError("Missing required command nmap. You have to"
                               "install the package nmap or the equivalent"
                               "for your distro")
Ejemplo n.º 20
0
    def setup(self, tarball='ffsb-6.0-rc2.tar.bz2'):
        """
        Uncompress the FFSB tarball and compiles it.

        @param tarball: FFSB tarball. Could be either a path relative to
                self.srcdir or a URL.
        """
        tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
        utils.extract_tarball_to_dir(tarball, self.srcdir)
        os.chdir(self.srcdir)
        os_dep.command('gcc')
        utils.configure()
        utils.make()
Ejemplo n.º 21
0
    def set_install_params(self, test, params):
        super(KojiInstaller, self).set_install_params(test, params)
        os_dep.command("rpm")
        os_dep.command("yum")

        self.tag = params.get("%s_tag" % self.param_key_prefix, None)
        self.koji_cmd = params.get("%s_cmd" % self.param_key_prefix, None)
        if self.tag is not None:
            virt_utils.set_default_koji_tag(self.tag)
        self.koji_pkgs = params.get("%s_pkgs" % self.param_key_prefix,
                                    "").split()
        if self.install_debug_info:
            self._expand_koji_pkgs_with_debuginfo()
Ejemplo n.º 22
0
    def __init__(self, test, params):
        super(YumInstaller, self).__init__(test, params)
        # Checking if all required dependencies are available
        os_dep.command("rpm")
        os_dep.command("yum")

        default_pkg_list = str(['qemu-kvm', 'qemu-kvm-tools'])
        default_qemu_bin_paths = str(['/usr/bin/qemu-kvm', '/usr/bin/qemu-img'])
        default_pkg_path_list = str(None)
        self.pkg_list = eval(params.get("pkg_list", default_pkg_list))
        self.pkg_path_list = eval(params.get("pkg_path_list",
                                             default_pkg_path_list))
        self.qemu_bin_paths = eval(params.get("qemu_bin_paths",
                                              default_qemu_bin_paths))
Ejemplo n.º 23
0
 def initialize(self):
     try:
         import pexpect
     except ImportError:
         raise error.TestError(
             "Missing python library pexpect. You have to "
             "install the package python-pexpect or the "
             "equivalent for your distro")
     try:
         os_dep.command("nmap")
     except ValueError:
         raise error.TestError("Missing required command nmap. You have to"
                               "install the package nmap or the equivalent"
                               "for your distro")
Ejemplo n.º 24
0
    def set_install_params(self, test, params):
        super(YumInstaller, self).set_install_params(test, params)
        # Checking if all required dependencies are available
        os_dep.command("rpm")
        os_dep.command("yum")

        default_pkg_list = str(['qemu-kvm', 'qemu-kvm-tools'])
        default_qemu_bin_paths = str(
            ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img'])
        default_pkg_path_list = str(None)
        self.pkg_list = eval(params.get("pkg_list", default_pkg_list))
        self.pkg_path_list = eval(
            params.get("pkg_path_list", default_pkg_path_list))
        self.qemu_bin_paths = eval(
            params.get("qemu_bin_paths", default_qemu_bin_paths))
Ejemplo n.º 25
0
    def initialize(self, interval=1):
        """
        Set sar interval and verify what flags the installed sar supports.

        @param interval: Interval used by sar to produce system data.
        """
        self.interval = interval
        self.sar_path = os_dep.command('sar')
        # If using older versions of sar, command below means: Measure default
        # params using interval of 1 second continuously. For newer versions,
        # behavior has changed - to generate reports continuously just omit the
        # count parameter.
        t_cmd = self.sar_path + " 1 0"
        t_process = subprocess.Popen(t_cmd, shell=True,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
        # Wait a little to see if process is going to fail or work
        time.sleep(3)
        if t_process.poll():
            # Sar process returned, so 0 doesn't mean generate continuously
            self.cmd = self.sar_path + " -o %s %d"
        else:
            # Sar process didn't return, so 0 means generate continuously
            # Just terminate the process
            self.cmd = self.sar_path + " -o %s %d 0"
            os.kill(t_process.pid, 15)
Ejemplo n.º 26
0
    def initialize(self, interval=1):
        """
        Set sar interval and verify what flags the installed sar supports.

        @param interval: Interval used by sar to produce system data.
        """
        self.interval = interval
        self.sar_path = os_dep.command('sar')
        # If using older versions of sar, command below means: Measure default
        # params using interval of 1 second continuously. For newer versions,
        # behavior has changed - to generate reports continuously just omit the
        # count parameter.
        t_cmd = self.sar_path + " 1 0"
        t_process = subprocess.Popen(t_cmd,
                                     shell=True,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
        # Wait a little to see if process is going to fail or work
        time.sleep(3)
        if t_process.poll():
            # Sar process returned, so 0 doesn't mean generate continuously
            self.cmd = self.sar_path + " -o %s %d"
        else:
            # Sar process didn't return, so 0 means generate continuously
            # Just terminate the process
            self.cmd = self.sar_path + " -o %s %d 0"
            os.kill(t_process.pid, 15)
Ejemplo n.º 27
0
    def __init__(self, uri, branch='master', lbranch='master', commit=None,
                 destination_dir=None, base_uri=None):
        '''
        Instantiates a new GitRepoHelper

        @type uri: string
        @param uri: git repository url
        @type branch: string
        @param branch: git remote branch
        @type destination_dir: string
        @param destination_dir: path of a dir where to save downloaded code
        @type commit: string
        @param commit: specific commit to download
        @type lbranch: string
        @param lbranch: git local branch name, if different from remote
        @type base_uri: string
        @param base_uri: a closer, usually local, git repository url from where to
                    fetch content first
        '''
        self.uri = uri
        self.base_uri = base_uri
        self.branch = branch
        self.commit = commit

        if destination_dir is None:
            uri_basename = uri.split("/")[-1]
            self.destination_dir = os.path.join("/tmp", uri_basename)
        else:
            self.destination_dir = destination_dir
        if lbranch is None:
            self.lbranch = branch
        else:
            self.lbranch = lbranch

        self.cmd = os_dep.command('git')
Ejemplo n.º 28
0
    def initialize(self):
        """
        Gets path of kvm_stat and verifies if debugfs needs to be mounted.
        """
        self.is_enabled = False

        kvm_stat_installed = False
        try:
            self.stat_path = os_dep.command('kvm_stat')
            kvm_stat_installed = True
        except ValueError:
            logging.error('Command kvm_stat not present')

        if kvm_stat_installed:
            try:
                utils.run("%s --batch" % self.stat_path)
                self.is_enabled = True
            except error.CmdError, e:
                if 'debugfs' in str(e):
                    try:
                        utils.run('mount -t debugfs debugfs /sys/kernel/debug')
                    except error.CmdError, e:
                        logging.error('Failed to mount debugfs:\n%s', str(e))
                else:
                    logging.error('Failed to execute kvm_stat:\n%s', str(e))
Ejemplo n.º 29
0
 def __init__(self):
     """
     Initializes the base command and the yum package repository.
     """
     super(ZypperBackend, self).__init__()
     self.base_command = os_dep.command('zypper') + ' -n'
     z_cmd = self.base_command + ' --version'
     self.zypper_version = utils.system_output(z_cmd, ignore_status=True)
     logging.debug('Zypper backend initialized')
     logging.debug('Zypper version: %s' % self.zypper_version)
Ejemplo n.º 30
0
 def __init__(self):
     """
     Initializes the base command and the yum package repository.
     """
     super(ZypperBackend, self).__init__()
     self.base_command = os_dep.command('zypper') + ' -n'
     z_cmd = self.base_command + ' --version'
     self.zypper_version = utils.system_output(z_cmd, ignore_status=True)
     logging.debug('Zypper backend initialized')
     logging.debug('Zypper version: %s' % self.zypper_version)
Ejemplo n.º 31
0
 def __init__(self):
     """
     Initializes the base command and the debian package repository.
     """
     super(AptBackend, self).__init__()
     executable = os_dep.command('apt-get')
     self.base_command = executable + ' -y'
     self.repo_file_path = '/etc/apt/sources.list.d/autotest'
     self.apt_version = utils.system_output('apt-get -v | head -1',
                                            ignore_status=True)
     logging.debug('Apt backend initialized')
     logging.debug('apt version: %s' % self.apt_version)
Ejemplo n.º 32
0
 def __init__(self):
     """
     Initializes the base command and the debian package repository.
     """
     super(AptBackend, self).__init__()
     executable = os_dep.command('apt-get')
     self.base_command = executable + ' -y'
     self.repo_file_path = '/etc/apt/sources.list.d/autotest'
     self.apt_version = utils.system_output('apt-get -v | head -1',
                                            ignore_status=True)
     logging.debug('Apt backend initialized')
     logging.debug('apt version: %s' % self.apt_version)
Ejemplo n.º 33
0
 def initialize(self, events="cycles,instructions"):
     self.events = events
     self.perf_bin = os_dep.command("perf")
     perf_help = utils.run("%s report help" % self.perf_bin, ignore_status=True).stderr
     self.sort_keys = None
     for line in perf_help.split("\n"):
         a = "sort by key(s):"
         if a in line:
             line = line.strip(a)
             self.sort_keys = [k.rstrip(",") for k in line.split() if k.rstrip(",") != "dso"]
     if not self.sort_keys:
         self.sort_keys = ["comm", "cpu"]
Ejemplo n.º 34
0
 def initialize(self):
     """
     Gets path of kvm_stat and verifies if debugfs needs to be mounted.
     """
     self.stat_path = os_dep.command('kvm_stat')
     try:
         utils.system_output("%s --batch" % self.stat_path)
     except error.CmdError, e:
         if 'debugfs' in str(e):
             utils.system('mount -t debugfs debugfs /sys/kernel/debug')
         else:
             raise error.AutotestError('kvm_stat failed due to an '
                                       'unknown reason: %s' % str(e))
Ejemplo n.º 35
0
 def initialize(self):
     """
     Gets path of kvm_stat and verifies if debugfs needs to be mounted.
     """
     self.stat_path = os_dep.command('kvm_stat')
     try:
         utils.system_output("%s --batch" % self.stat_path)
     except error.CmdError, e:
         if 'debugfs' in str(e):
             utils.system('mount -t debugfs debugfs /sys/kernel/debug')
         else:
             raise error.AutotestError('kvm_stat failed due to an '
                                       'unknown reason: %s' % str(e))
Ejemplo n.º 36
0
 def set_install_params(self, test, params):
     super(YumInstaller, self).set_install_params(test, params)
     os_dep.command("rpm")
     os_dep.command("yum")
     if self.install_debug_info:
         os_dep.command("debuginfo-install")
     self.yum_pkgs = eval(params.get("%s_pkgs" % self.param_key_prefix,
                                     "[]"))
Ejemplo n.º 37
0
    def __init__(self, cmd):
        """
        Verifies whether the system has koji or brew installed, then loads
        the configuration file that will be used to download the files.

        @param cmd: Command name, either 'brew' or 'koji'. It is important
                to figure out the appropriate configuration used by the
                downloader.
        @param dst_dir: Destination dir for the packages.
        """
        if not KOJI_INSTALLED:
            raise ValueError('No koji/brew installed on the machine')

        if os.path.isfile(cmd):
            koji_cmd = cmd
        else:
            koji_cmd = os_dep.command(cmd)

        logging.debug("Found %s as the buildsystem interface", koji_cmd)

        config_map = {'/usr/bin/koji': '/etc/koji.conf',
                      '/usr/bin/brew': '/etc/brewkoji.conf'}

        try:
            config_file = config_map[koji_cmd]
        except IndexError:
            raise ValueError('Could not find config file for %s' % koji_cmd)

        base_name = os.path.basename(koji_cmd)
        if os.access(config_file, os.F_OK):
            f = open(config_file)
            config = ConfigParser.ConfigParser()
            config.readfp(f)
            f.close()
        else:
            raise IOError('Configuration file %s missing or with wrong '
                          'permissions' % config_file)

        if config.has_section(base_name):
            self.koji_options = {}
            session_options = {}
            server = None
            for name, value in config.items(base_name):
                if name in ('user', 'password', 'debug_xmlrpc', 'debug'):
                    session_options[name] = value
                self.koji_options[name] = value
            self.session = koji.ClientSession(self.koji_options['server'],
                                              session_options)
        else:
            raise ValueError('Koji config file %s does not have a %s '
                             'session' % (config_file, base_name))
Ejemplo n.º 38
0
def os_support():
    """\
    Returns a dictionary with host os package support info:
    - rpm: True if system supports rpm packages, False otherwise
    - dpkg: True if system supports dpkg packages, False otherwise
    - conversion: True if the system can convert packages (alien installed),
    or False otherwise
    """
    support_info = {}
    for package_manager in KNOWN_PACKAGE_MANAGERS:
        try:
            os_dep.command(package_manager)
            support_info[package_manager] = True
        except Exception:
            support_info[package_manager] = False

    try:
        os_dep.command('alien')
        support_info['conversion'] = True
    except Exception:
        support_info['conversion'] = False

    return support_info
Ejemplo n.º 39
0
def os_support():
    """\
    Returns a dictionary with host os package support info:
    - rpm: True if system supports rpm packages, False otherwise
    - dpkg: True if system supports dpkg packages, False otherwise
    - conversion: True if the system can convert packages (alien installed),
    or False otherwise
    """
    support_info = {}
    for package_manager in KNOWN_PACKAGE_MANAGERS:
        try:
            os_dep.command(package_manager)
            support_info[package_manager] = True
        except Exception:
            support_info[package_manager] = False

    try:
        os_dep.command('alien')
        support_info['conversion'] = True
    except Exception:
        support_info['conversion'] = False

    return support_info
Ejemplo n.º 40
0
 def initialize(self, events=["cycles", "instructions"], trace=False):
     if type(events) == str:
         self.events = [events]
     else:
         self.events = events
     self.trace = trace
     self.perf_bin = os_dep.command("perf")
     perf_help = utils.run("%s report help" % self.perf_bin, ignore_status=True).stderr
     self.sort_keys = None
     for line in perf_help.split("\n"):
         a = "sort by key(s):"
         if a in line:
             line = line.replace(a, "")
             self.sort_keys = [k.rstrip(",") for k in line.split() if k.rstrip(",") != "dso"]
     if not self.sort_keys:
         self.sort_keys = ["comm", "cpu"]
Ejemplo n.º 41
0
 def initialize(self, events="cycles,instructions"):
     self.events = events
     self.perf_bin = os_dep.command('perf')
     perf_help = utils.run('%s report help' % self.perf_bin,
                           ignore_status=True).stderr
     self.sort_keys = None
     for line in perf_help.split('\n'):
         a = "sort by key(s):"
         if a in line:
             line = line.strip(a)
             self.sort_keys = [
                 k.rstrip(",") for k in line.split()
                 if k.rstrip(",") != 'dso'
             ]
     if not self.sort_keys:
         self.sort_keys = ['comm', 'cpu']
Ejemplo n.º 42
0
 def __init__(self):
     """
     Initializes the base command and the yum package repository.
     """
     super(YumBackend, self).__init__()
     executable = os_dep.command('yum')
     base_arguments = '-y'
     self.base_command = executable + ' ' + base_arguments
     self.repo_file_path = '/etc/yum.repos.d/autotest.repo'
     self.cfgparser = ConfigParser.ConfigParser()
     self.cfgparser.read(self.repo_file_path)
     y_cmd = executable + ' --version | head -1'
     self.yum_version = utils.system_output(y_cmd, ignore_status=True)
     logging.debug('Yum backend initialized')
     logging.debug('Yum version: %s' % self.yum_version)
     self.yum_base = yum.YumBase()
Ejemplo n.º 43
0
 def __init__(self):
     """
     Initializes the base command and the yum package repository.
     """
     super(YumBackend, self).__init__()
     executable = os_dep.command('yum')
     base_arguments = '-y'
     self.base_command = executable + ' ' + base_arguments
     self.repo_file_path = '/etc/yum.repos.d/autotest.repo'
     self.cfgparser = ConfigParser.ConfigParser()
     self.cfgparser.read(self.repo_file_path)
     y_cmd = executable + ' --version | head -1'
     self.yum_version = utils.system_output(y_cmd, ignore_status=True)
     logging.debug('Yum backend initialized')
     logging.debug('Yum version: %s' % self.yum_version)
     self.yum_base = yum.YumBase()
Ejemplo n.º 44
0
 def initialize(self, events=["cycles", "instructions"], trace=False):
     if type(events) == str:
         self.events = [events]
     else:
         self.events = events
     self.trace = trace
     self.perf_bin = os_dep.command('perf')
     perf_help = utils.run('%s report help' % self.perf_bin,
                           ignore_status=True).stderr
     self.sort_keys = None
     for line in perf_help.split('\n'):
         a = "sort by key(s):"
         if a in line:
             line = line.replace(a, "")
             self.sort_keys = [
                 k.rstrip(",") for k in line.split()
                 if k.rstrip(",") != 'dso'
             ]
     if not self.sort_keys:
         self.sort_keys = ['comm', 'cpu']
Ejemplo n.º 45
0
    def __init__(self, results_file, output_dir):
        self.active = True
        try:
            self.gnuplot = os_dep.command("gnuplot")
        except:
            logging.error("Command gnuplot not found, disabling graph "
                          "generation")
            self.active = False

        if not os.path.isdir(output_dir):
            os.makedirs(output_dir)
        self.output_dir = output_dir

        if not os.path.isfile(results_file):
            logging.error("Invalid file %s provided, disabling graph "
                          "generation", results_file)
            self.active = False
            self.results_file = None
        else:
            self.results_file = results_file
            self.generate_data_source()
Ejemplo n.º 46
0
    def __init__(self,
                 uri,
                 branch='master',
                 lbranch='master',
                 commit=None,
                 destination_dir=None,
                 base_uri=None):
        '''
        Instantiates a new GitRepoHelper

        @type uri: string
        @param uri: git repository url
        @type branch: string
        @param branch: git remote branch
        @type destination_dir: string
        @param destination_dir: path of a dir where to save downloaded code
        @type commit: string
        @param commit: specific commit to download
        @type lbranch: string
        @param lbranch: git local branch name, if different from remote
        @type base_uri: string
        @param base_uri: a closer, usually local, git repository url from where to
                    fetch content first
        '''
        self.uri = uri
        self.base_uri = base_uri
        self.branch = branch
        self.commit = commit

        if destination_dir is None:
            uri_basename = uri.split("/")[-1]
            self.destination_dir = os.path.join("/tmp", uri_basename)
        else:
            self.destination_dir = destination_dir
        if lbranch is None:
            self.lbranch = branch
        else:
            self.lbranch = lbranch

        self.cmd = os_dep.command('git')
Ejemplo n.º 47
0
    def __init__(self, test, params):
        """
        Class constructor. Sets default paths, and sets up class attributes

        @param test: kvm test object
        @param params: Dictionary with test arguments
        """
        default_koji_cmd = '/usr/bin/koji'
        default_src_pkg = 'qemu'
        default_pkg_list = ['qemu-kvm', 'qemu-kvm-tools']
        default_qemu_bin_paths = ['/usr/bin/qemu-kvm', '/usr/bin/qemu-img']
        default_extra_modules = None

        self.koji_cmd = params.get("koji_cmd", default_koji_cmd)

        # Checking if all required dependencies are available
        os_dep.command("rpm")
        os_dep.command("yum")
        os_dep.command(self.koji_cmd)

        self.src_pkg = params.get("src_pkg", default_src_pkg)
        self.pkg_list = params.get("pkg_list", default_pkg_list)
        self.qemu_bin_paths = params.get("qemu_bin_paths",
                                         default_qemu_bin_paths)
        self.tag = params.get("koji_tag", None)
        self.build = params.get("koji_build", None)
        if self.tag and self.build:
            logging.info("Both tag and build parameters provided, ignoring tag "
                         "parameter...")
        if self.tag and not self.build:
            self.build = self.__get_build()
        if not self.tag and not self.build:
            raise error.TestError("Koji install selected but neither koji_tag "
                                  "nor koji_build parameters provided. Please "
                                  "provide an appropriate tag or build name.")
        # Are we going to load modules?
        load_modules = params.get('load_modules')
        if not load_modules:
            self.load_modules = True
        elif load_modules == 'yes':
            self.load_modules = True
        elif load_modules == 'no':
            self.load_modules = False
        self.extra_modules = params.get("extra_modules", default_extra_modules)

        self.srcdir = test.srcdir
        self.test_bindir = test.bindir
Ejemplo n.º 48
0
    def list_tests(cls):
        """
        List the available tests for users to choose from
        """
        # One favorite feature from git :-)
        try:
            less_cmd = os_dep.command('less')
            pipe = os.popen('%s -FRSX' % less_cmd, 'w')
        except ValueError:
            pipe = sys.stdout

        pipe.write("List of tests available\n")
        pipe.write("Unless otherwise specified, outputs imply /control files\n")
        pipe.write("\n")

        # Walk local ./tests directory
        dirtest = os.path.join(os.path.abspath(os.path.curdir), LOCALDIRTEST)
        # Don't repeat autodirtest results
        if not os.environ['AUTODIRTEST']:
            dirtest = os.environ['AUTODIRTEST']
            pipe.write("Local tests (%s)\n" % dirtest)
            cls._print_control_list(pipe, dirtest)
            pipe.write("\n")

        # Walk globaldirtests directory
        if GLOBALDIRTEST and os.path.isdir(GLOBALDIRTEST):
            dirtest = GLOBALDIRTEST
            pipe.write("Globally imported tests (%s)\n" % dirtest)
            cls._print_control_list(pipe, dirtest)
            pipe.write("\n")

        # Walk autodirtest directory
        dirtest = os.environ['AUTODIRTEST']
        pipe.write("Autotest prepackaged tests (%s)\n" % dirtest)
        cls._print_control_list(pipe, dirtest)

        pipe.close()
        raise SystemExit(0)
Ejemplo n.º 49
0
    def provides(self, file):
        """
        Return a list of packages that provide [file].

        @param file: File path.
        """
        if not self.check_installed('apt-file'):
            self.install('apt-file')
        command = os_dep.command('apt-file')
        cache_update_cmd = command + ' update'
        try:
            utils.system(cache_update_cmd, ignore_status=True)
        except Exception:
            logging.error("Apt file cache update failed")
        fu_cmd = command + ' search ' + file
        try:
            provides = utils.system_output(fu_cmd).split('\n')
            list_provides = []
            for line in provides:
                if line:
                    try:
                        line = line.split(':')
                        package = line[0].strip()
                        path = line[1].strip()
                        if path == file and package not in list_provides:
                            list_provides.append(package)
                    except IndexError:
                        pass
            if len(list_provides) > 1:
                logging.warning('More than one package found, '
                                'opting by the first queue result')
            if list_provides:
                logging.info("Package %s provides %s", list_provides[0], file)
                return list_provides[0]
            return None
        except Exception:
            return None
    def __init__(self, repodir, giturl=None, weburl=None, abs_work_tree=None):
        """
        Initialized reposotory.

        @param repodir: destination repo directory.
        @param giturl: master repo git url.
        @param weburl: a web url for the master repo.
        @param abs_work_tree: work tree of the git repo. In the
            absence of a work tree git manipulations will occur
            in the current working directory for non bare repos.
            In such repos the -git-dir option should point to
            the .git directory and -work-tree should point to
            the repos working tree.
        Note: a bare reposotory is one which contains all the
        working files (the tree) and the other wise hidden files
        (.git) in the same directory. This class assumes non-bare
        reposotories.
        """
        if repodir is None:
            raise ValueError('You must provide a path that will hold the'
                             'git repository')
        self.repodir = utils.sh_escape(repodir)
        self._giturl = giturl
        if weburl is not None:
            warnings.warn(
                "Param weburl: You are no longer required to provide "
                "a web URL for your git repos", DeprecationWarning)

        # path to .git dir
        self.gitpath = utils.sh_escape(os.path.join(self.repodir, '.git'))

        # Find git base command. If not found, this will throw an exception
        self.git_base_cmd = os_dep.command('git')
        self.work_tree = abs_work_tree

        # default to same remote path as local
        self._build = os.path.dirname(self.repodir)
Ejemplo n.º 51
0
    def provides(self, file):
        """
        Return a list of packages that provide [file].

        @param file: File path.
        """
        if not self.check_installed('apt-file'):
            self.install('apt-file')
        command = os_dep.command('apt-file')
        cache_update_cmd = command + ' update'
        try:
            utils.system(cache_update_cmd, ignore_status=True)
        except:
            logging.error("Apt file cache update failed")
        fu_cmd = command + ' search ' + file
        try:
            provides = utils.system_output(fu_cmd).split('\n')
            list_provides = []
            for line in provides:
                if line:
                    try:
                        line = line.split(':')
                        package = line[0].strip()
                        path = line[1].strip()
                        if path == file and package not in list_provides:
                            list_provides.append(package)
                    except IndexError:
                        pass
            if len(list_provides) > 1:
                logging.warning('More than one package found, '
                                'opting by the first queue result')
            if list_provides:
                logging.info("Package %s provides %s", list_provides[0], file)
                return list_provides[0]
            return None
        except:
            return None
Ejemplo n.º 52
0
    def __init__(self, repodir, giturl, weburl=None):
        if repodir is None:
            raise ValueError('You must provide a path that will hold the'
                             'git repository')
        self.repodir = utils.sh_escape(repodir)
        if giturl is None:
            raise ValueError('You must provide a git URL repository')
        self.giturl = giturl
        if weburl is not None:
            warnings.warn(
                "Param weburl: You are no longer required to provide "
                "a web URL for your git repos", DeprecationWarning)

        # path to .git dir
        self.gitpath = utils.sh_escape(os.path.join(self.repodir, '.git'))

        # Find git base command. If not found, this will throw an exception
        git_base_cmd = os_dep.command('git')

        # base git command , pointing to gitpath git dir
        self.gitcmdbase = '%s --git-dir=%s' % (git_base_cmd, self.gitpath)

        # default to same remote path as local
        self._build = os.path.dirname(self.repodir)
Ejemplo n.º 53
0
 def __init__(self):
     self.lowlevel_base_cmd = os_dep.command('dpkg')