Beispiel #1
0
 def test_s390x_get_version(self):
     with unittest.mock.patch('avocado.utils.cpu.platform.machine',
                              return_value='s390x'):
         with unittest.mock.patch(
                 'builtins.open',
                 return_value=self._get_data_mock('s390x')):
             self.assertEqual(cpu.get_version(), "2827")
 def test_power9_get_version(self):
     with unittest.mock.patch('avocado.utils.cpu.platform.machine',
                              return_value='powerpc'):
         with unittest.mock.patch(
                 'builtins.open',
                 return_value=self._get_data_mock('power9')):
             self.assertEqual(cpu.get_version(), "1.0")
 def test_intel_get_version(self):
     with unittest.mock.patch('avocado.utils.cpu.platform.machine',
                              return_value='x86_64'):
         with unittest.mock.patch(
                 'builtins.open',
                 return_value=self._get_data_mock('x86_64')):
             self.assertEqual(cpu.get_version(), "i7-4710MQ")
Beispiel #4
0
 def test_power9_get_version(self):
     with unittest.mock.patch(
         "avocado.utils.cpu.platform.machine", return_value="powerpc"
     ):
         with unittest.mock.patch(
             "builtins.open", return_value=self._get_data_mock("power9")
         ):
             self.assertEqual(cpu.get_version(), "1.0")
Beispiel #5
0
 def test_s390x_get_version(self):
     with unittest.mock.patch(
         "avocado.utils.cpu.platform.machine", return_value="s390x"
     ):
         with unittest.mock.patch(
             "builtins.open", return_value=self._get_data_mock("s390x")
         ):
             self.assertEqual(cpu.get_version(), "2827")
Beispiel #6
0
def create_host_os_cfg(options):
    def _forced_or_detected(forced, detected):
        if forced:
            return forced
        else:
            return detected

    host_os_cfg_path = data_dir.get_backend_cfg_path(
        get_opt(options, 'vt.type'), 'host.cfg')
    with open(host_os_cfg_path, 'w') as cfg:
        detected = distro.detect()
        name = host_os_get_distro_name(options, detected)
        version = _forced_or_detected(
            get_opt(options, 'vt_host_distro_version'),
            "m%s" % detected.version)
        release = _forced_or_detected(
            get_opt(options, 'vt_host_distro_release'),
            "u%s" % detected.release)
        arch = _forced_or_detected(get_opt(options, 'vt_host_distro_arch'),
                                   "Host_arch_%s" % detected.arch)
        vendor = cpu.get_vendor() if hasattr(
            cpu, 'get_vendor') else cpu.get_cpu_vendor_name()
        family = None
        if hasattr(cpu, 'get_family'):
            try:
                family = cpu.get_family()
            except Exception:
                pass
        cpu_version = cpu.get_version() if hasattr(cpu,
                                                   'get_version') else None
        # Replace special chars with _ to avoid bootstrap failure
        cpu_version = re.sub(r'[^\w-]', '_',
                             cpu_version) if cpu_version else cpu_version

        cfg.write("variants:\n")
        cfg.write("    - @Host:\n")
        cfg.write("        variants:\n")
        cfg.write("            - @%s:\n" % name)
        cfg.write("                variants:\n")
        cfg.write("                    - @%s:\n" % version)
        cfg.write("                        variants:\n")
        cfg.write("                            - @%s:\n" % release)
        cfg.write("                                variants:\n")
        cfg.write("                                    - @%s:\n" % arch)
        if vendor:
            cfg.write("variants:\n")
            cfg.write("    - @HostCpuVendor:\n")
            cfg.write("        variants:\n")
            cfg.write("            - @%s:\n" % vendor)
        if family:
            cfg.write("variants:\n")
            cfg.write("    - @HostCpuFamily:\n")
            cfg.write("        variants:\n")
            cfg.write("            - @%s:\n" % family)
            if cpu_version:
                cfg.write("                variants:\n")
                cfg.write("                    - @HostCpuVersion:\n")
                cfg.write("                        variants:\n")
                cfg.write("                            - @%s:\n" % cpu_version)

    count = [
        get_opt(options, 'vt_host_distro_name'),
        get_opt(options, 'vt_host_distro_version'),
        get_opt(options, 'vt_host_distro_release'),
        get_opt(options, 'vt_host_distro_arch')
    ].count(None)
    if count == 4:
        source = "distro detection"
    elif count == 0:
        source = "command line parameters"
    else:
        source = "distro detection and command line parameters"
    LOG.debug("Config file %s generated from %s", host_os_cfg_path, source)