def _fake_caps_arch(caps, arch): ''' Mutate 'caps' to act as an architecture set by fake_kvm_architecture configuration option. Arguments: caps The host capabilities as returned by hooking.read_json. ''' arch = arch caps['kvmEnabled'] = True if cpuarch.is_x86(arch): caps['emulatedMachines'] = _X86_64_MACHINES caps['cpuModel'] = 'Intel(Fake) CPU' flag_list = ['vmx', 'sse2', 'nx'] if cpuarch.real() == cpuarch.X86_64: flag_list += cpuinfo.flags() flags = set(flag_list) caps['cpuFlags'] = ','.join(flags) + ',model_486,model_pentium,' \ 'model_pentium2,model_pentium3,model_pentiumpro,' \ 'model_qemu32,model_coreduo,model_core2duo,model_n270,' \ 'model_Conroe,model_Penryn,model_Nehalem,model_Opteron_G1' elif cpuarch.is_ppc(arch): caps['emulatedMachines'] = _PPC64LE_MACHINES caps['cpuModel'] = 'POWER 8(fake)' caps['cpuFlags'] = 'powernv,model_POWER8' else: raise cpuarch.UnsupportedArchitecture(arch)
def _alloc(count, size, path): """Helper to actually (de)allocate hugepages, called by public facing methods. Args: count: Number of hugepages to allocate (can be negative) size: The target hugepage size (must be supported by the system) path: Path to the hugepages directory. Returns: The amount of allocated pages (can be negative, implicating deallocation). Raises: """ if size is None: size = DEFAULT_HUGEPAGESIZE[cpuarch.real()] path = path.format(size) ret = supervdsm.getProxy().hugepages_alloc(count, path) if ret != count: supervdsm.getProxy().hugepages_alloc(-ret, path) raise NonContiguousMemory return ret
def x86_64_test(): caps = { 'cpuModel': None, 'cpuFlags': None, 'emulatedMachines': None, 'kvmEnabled': False } expected_caps = { 'cpuModel': 'Intel(Fake) CPU', 'cpuFlags': ',model_486,model_pentium,model_pentium2,' 'model_pentium3,model_pentiumpro,model_qemu32,' 'model_coreduo,model_core2duo,model_n270,model_Conroe,' 'model_Penryn,model_Nehalem,model_Opteron_G1', 'emulatedMachines': _X86_64_MACHINES, 'kvmEnabled': True } # This is duplicate of the real functionality and is required because we do # not know which flags are added unless we query the host cpu. flag_list = ['vmx', 'sse2', 'nx'] if cpuarch.real() == cpuarch.X86_64: flag_list += cpuinfo.flags() expected_caps['cpuFlags'] = (','.join(set(flag_list)) + expected_caps['cpuFlags']) _fake_caps_arch(caps, cpuarch.X86_64) return caps == expected_caps
def uuid(): host_UUID = None try: if os.path.exists(constants.P_VDSM_NODE_ID): with open(constants.P_VDSM_NODE_ID) as f: host_UUID = f.readline().replace("\n", "") else: arch = cpuarch.real() if cpuarch.is_x86(arch): ret, out, err = execCmd( [constants.EXT_DMIDECODE, "-s", "system-uuid"], raw=True, sudo=True) out = '\n'.join(line for line in out.splitlines() if not line.startswith('#')) if ret == 0 and 'Not' not in out: # Avoid error string - 'Not Settable' or 'Not Present' host_UUID = out.strip() else: logging.warning('Could not find host UUID.') elif cpuarch.is_ppc(arch): # eg. output IBM,03061C14A try: with open('/proc/device-tree/system-id') as f: systemId = f.readline() host_UUID = systemId.rstrip('\0').replace(',', '') except IOError: logging.warning('Could not find host UUID.') except: logging.error("Error retrieving host UUID", exc_info=True) return host_UUID
def workaround(function): @wraps(function) def wrapped(*args, **kwargs): return function(*args, **kwargs) if ((not real_arch or real_arch == cpuarch.real()) and (not effective_arch or effective_arch == cpuarch.effective())): _WORKAROUNDS.append(wrapped) return wrapped
def _is_hugetlbfs_1g_mounted(mtab_path='/etc/mtab'): if cpuarch.is_ppc(cpuarch.real()) or 'pdpe1gb' not in cpuinfo.flags(): return True with open(mtab_path, 'r') as f: for line in f: if '/dev/hugepages1G' in line: return True return False
def getHardwareInfo(*args, **kwargs): arch = cpuarch.real() if cpuarch.is_x86(arch): from vdsm.dmidecodeUtil import getHardwareInfoStructure return getHardwareInfoStructure() elif cpuarch.is_ppc(arch): from vdsm.ppc64HardwareInfo import getHardwareInfoStructure return getHardwareInfoStructure() else: # not implemented over other architecture return {}
def _preallocated_hugepages(vm_hugepagesz): kernel_args = osinfo.kernel_args_dict() if 'hugepagesz' not in kernel_args: hugepagesz = DEFAULT_HUGEPAGESIZE[cpuarch.real()] else: hugepagesz = _cmdline_hugepagesz_to_kb(kernel_args['hugepagesz']) preallocated_hugepages = 0 if ('hugepages' in kernel_args and hugepagesz == vm_hugepagesz): preallocated_hugepages = int(kernel_args['hugepages']) return preallocated_hugepages
def _os_set_arch_test(): domxml = minidom.parseString(''' <os> <type arch="x86_64" machine="pc-i440fx-rhel7.2.0">hvm</type> <smbios mode="sysinfo"/> </os> ''') _os_set_arch(domxml) return (domxml.getElementsByTagName( 'type')[0].getAttribute('arch') == cpuarch.real())
def _os_set_arch_test(): domxml = minidom.parseString(''' <os> <type arch="x86_64" machine="pc-i440fx-rhel7.2.0">hvm</type> <smbios mode="sysinfo"/> </os> ''') _os_set_arch(domxml) return (domxml.getElementsByTagName('type')[0].getAttribute('arch') == cpuarch.real())
def nested_virtualization(): if cpuarch.is_ppc(cpuarch.real()): return NestedVirtualization(False, None) if cpuarch.is_s390(cpuarch.real()): kvm_modules = ("kvm", ) else: kvm_modules = ("kvm_intel", "kvm_amd") for kvm_module in kvm_modules: kvm_module_path = "/sys/module/%s/parameters/nested" % kvm_module try: with open(kvm_module_path) as f: if f.readline().strip() in ("Y", "1"): return NestedVirtualization(True, kvm_module) except IOError: logging.debug('%s nested virtualization ' 'not detected' % kvm_module, exc_info=True) logging.debug('Could not determine status of nested ' 'virtualization') return NestedVirtualization(False, None)
def nested_virtualization(): if cpuarch.is_ppc(cpuarch.real()): return NestedVirtualization(False, None) for kvm_module in ("kvm_intel", "kvm_amd"): kvm_module_path = "/sys/module/%s/parameters/nested" % kvm_module try: with open(kvm_module_path) as f: if f.readline().strip() in ("Y", "1"): return NestedVirtualization(True, kvm_module) except IOError: logging.debug('Could not determine status of nested ' 'virtualization', exc_info=True) return NestedVirtualization(False, None)
def _preallocated_hugepages(vm_hugepagesz): kernel_args = osinfo.kernel_args_dict() if 'hugepagesz' not in kernel_args: hugepagesz = DEFAULT_HUGEPAGESIZE[cpuarch.real()] else: hugepagesz = _cmdline_hugepagesz_to_kb( kernel_args['hugepagesz'] ) preallocated_hugepages = 0 if ('hugepages' in kernel_args and hugepagesz == vm_hugepagesz): preallocated_hugepages = int(kernel_args['hugepages']) return preallocated_hugepages
class Tap(Interface): _IFF_TAP = 0x0002 _IFF_NO_PI = 0x1000 arch = cpuarch.real() if arch in (cpuarch.X86_64, cpuarch.S390X): _TUNSETIFF = 0x400454ca elif cpuarch.is_ppc(arch): _TUNSETIFF = 0x800454ca else: raise SkipTest("Unsupported Architecture %s" % arch) _deviceListener = None def addDevice(self): self._cloneDevice = open('/dev/net/tun', 'r+b') ifr = struct.pack('16sH', self.devName, self._IFF_TAP | self._IFF_NO_PI) fcntl.ioctl(self._cloneDevice, self._TUNSETIFF, ifr) self.up() def delDevice(self): self._down() self._cloneDevice.close() def startListener(self, icmp): self._deviceListener = Process(target=_listenOnDevice, args=(self._cloneDevice.fileno(), icmp)) self._deviceListener.start() def isListenerAlive(self): if self._deviceListener: return self._deviceListener.is_alive() else: return False def stopListener(self): if self._deviceListener: os.kill(self._deviceListener.pid, signal.SIGKILL) self._deviceListener.join() def writeToDevice(self, icmp): os.write(self._cloneDevice.fileno(), icmp)
def x86_64_test(): caps = {'cpuModel': None, 'cpuFlags': None, 'emulatedMachines': None, 'kvmEnabled': False} expected_caps = {'cpuModel': 'Intel(Fake) CPU', 'cpuFlags': ',model_486,model_pentium,model_pentium2,' 'model_pentium3,model_pentiumpro,model_qemu32,' 'model_coreduo,model_core2duo,model_n270,model_Conroe,' 'model_Penryn,model_Nehalem,model_Opteron_G1', 'emulatedMachines': ['pc-i440fx-rhel7.1.0', 'rhel6.3.0', 'pc-q35-rhel7.2.0', 'pc-i440fx-rhel7.0.0', 'rhel6.1.0', 'rhel6.6.0', 'rhel6.2.0', 'pc', 'pc-q35-rhel7.0.0', 'pc-q35-rhel7.1.0', 'q35', 'pc-i440fx-rhel7.2.0', 'rhel6.4.0', 'rhel6.0.0', 'rhel6.5.0'], 'kvmEnabled': True} # This is duplicate of the real functionality and is required because we do # not know which flags are added unless we query the host cpu. flag_list = ['vmx', 'sse2', 'nx'] if cpuarch.real() == cpuarch.X86_64: flag_list += cpuinfo.flags() expected_caps['cpuFlags'] = (','.join(set(flag_list)) + expected_caps['cpuFlags']) _fake_caps_arch(caps, cpuarch.X86_64) return caps == expected_caps
def uuid(): host_UUID = None try: if os.path.exists(constants.P_VDSM_NODE_ID): with open(constants.P_VDSM_NODE_ID) as f: host_UUID = f.readline().replace("\n", "") else: arch = cpuarch.real() if cpuarch.is_x86(arch): ret, out, err = execCmd([constants.EXT_DMIDECODE, "-s", "system-uuid"], raw=True, sudo=True) out = '\n'.join(line for line in out.splitlines() if not line.startswith('#')) if ret == 0 and 'Not' not in out: # Avoid error string - 'Not Settable' or 'Not Present' host_UUID = out.strip() else: logging.warning('Could not find host UUID.') elif cpuarch.is_ppc(arch): # eg. output IBM,03061C14A try: with open('/proc/device-tree/system-id') as f: systemId = f.readline() host_UUID = systemId.rstrip('\0').replace(',', '') except IOError: logging.warning('Could not find host UUID.') except: logging.error("Error retrieving host UUID", exc_info=True) return host_UUID
def _os_set_arch(domxml): ostag = domxml.getElementsByTagName('os')[0] typetag = ostag.getElementsByTagName('type')[0] typetag.setAttribute('arch', cpuarch.real())
def _os_set_arch(domxml): ostag = domxml.getElementsByTagName("os")[0] typetag = ostag.getElementsByTagName("type")[0] typetag.setAttribute("arch", cpuarch.real())