Martin Polednik has uploaded a new change for review. Change subject: cpuinfo: idea - moving predicates to methods ......................................................................
cpuinfo: idea - moving predicates to methods idea for discussion Change-Id: I066575e98ff3778d915255f6c8a68667238fc6fb Signed-off-by: Martin Polednik <[email protected]> --- M lib/vdsm/cpuarch.py M lib/vdsm/cpuinfo.py M tests/nettestlib.py M vdsm/supervdsmServer M vdsm/virt/vm.py M vdsm/virt/vmxml.py M vdsm_hooks/faqemu/after_get_caps.py 7 files changed, 32 insertions(+), 32 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/28/51428/1 diff --git a/lib/vdsm/cpuarch.py b/lib/vdsm/cpuarch.py index 387a56a..3180f38 100644 --- a/lib/vdsm/cpuarch.py +++ b/lib/vdsm/cpuarch.py @@ -23,9 +23,17 @@ from .config import config -X86_64 = 'x86_64' -PPC64 = 'ppc64' -PPC64LE = 'ppc64le' +class _Architecture(str): + def is_ppc(self): + return self in (PPC64, PPC64LE) + + def is_x86(self): + return self == X86_64 + + +X86_64 = _Architecture('x86_64') +PPC64 = _Architecture('ppc64') +PPC64LE = _Architecture('ppc64le') SUPPORTED_ARCHITECTURES = (X86_64, PPC64, PPC64LE) @@ -76,19 +84,11 @@ return real() -def is_ppc(arch): - return arch == PPC64 or arch == PPC64LE - - -def is_x86(arch): - return arch == X86_64 - - def _supported(target_arch): if target_arch not in SUPPORTED_ARCHITECTURES: raise UnsupportedArchitecture(target_arch) - return target_arch + return _Architecture(target_arch) def arch_to_libvirt_cpu_map(target_arch): diff --git a/lib/vdsm/cpuinfo.py b/lib/vdsm/cpuinfo.py index 2bed471..1ee1672 100644 --- a/lib/vdsm/cpuinfo.py +++ b/lib/vdsm/cpuinfo.py @@ -71,9 +71,9 @@ ''' cpus = parse(_SOURCE) - if cpuarch.is_x86(cpuarch.real()): + if cpuarch.real().is_x86(): return cpus[0]['flags'].split() - elif cpuarch.is_ppc(cpuarch.real()): + elif cpuarch.real().is_ppc(): return ['powernv'] @@ -90,9 +90,9 @@ ''' cpus = parse(_SOURCE) - if cpuarch.is_x86(cpuarch.real()): + if cpuarch.real().is_x86(): return cpus[0]['cpu MHz'] - elif cpuarch.is_ppc(cpuarch.real()): + elif cpuarch.real().is_ppc(): clock = cpus[0]['clock'] return clock[:-3] @@ -110,7 +110,7 @@ ''' cpus = parse(_SOURCE) - if cpuarch.is_x86(cpuarch.real()): + if cpuarch.real().is_x86(): return cpus[0]['model name'] - elif cpuarch.is_ppc(cpuarch.real()): + elif cpuarch.real().is_ppc(): return cpus[0]['cpu'] diff --git a/tests/nettestlib.py b/tests/nettestlib.py index c1d24af..2c6b2cd 100644 --- a/tests/nettestlib.py +++ b/tests/nettestlib.py @@ -155,9 +155,9 @@ _IFF_TAP = 0x0002 _IFF_NO_PI = 0x1000 arch = cpuarch.real() - if cpuarch.is_x86(arch): + if arch.is_x86(): _TUNSETIFF = 0x400454ca - elif cpuarch.is_ppc(arch): + elif arch.is_ppc(): _TUNSETIFF = 0x800454ca else: raise SkipTest("Unsupported Architecture %s" % arch) diff --git a/vdsm/supervdsmServer b/vdsm/supervdsmServer index 9503ee7..67cb988 100755 --- a/vdsm/supervdsmServer +++ b/vdsm/supervdsmServer @@ -158,7 +158,7 @@ if platform.machine() in ('x86_64', 'i686'): from vdsm.dmidecodeUtil import getHardwareInfoStructure return getHardwareInfoStructure() - elif cpuarch.is_ppc(platform.machine()): + elif cpuarch.real().is_ppc(): from vdsm.ppc64HardwareInfo import getHardwareInfoStructure return getHardwareInfoStructure() else: diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py index eb9e6b2..a1c72e9 100644 --- a/vdsm/virt/vm.py +++ b/vdsm/virt/vm.py @@ -1639,7 +1639,7 @@ domxml = vmxml.Domain(self.conf, self.log, self.arch) domxml.appendOs(use_serial_console=(serial_console is not None)) - if cpuarch.is_x86(self.arch): + if self.arch.is_x86(): osd = caps.osversion() osVersion = osd.get('version', '') + '-' + osd.get('release', '') @@ -1652,7 +1652,7 @@ domxml.appendClock() - if cpuarch.is_x86(self.arch): + if self.arch.is_x86(): domxml.appendFeatures() domxml.appendCpu() @@ -1665,7 +1665,7 @@ _QEMU_GA_DEVICE_NAME) domxml.appendInput() - if cpuarch.is_ppc(self.arch): + if self.arch.is_ppc(): domxml.appendEmulator() self._appendDevices(domxml) @@ -3624,7 +3624,7 @@ actionToString(action)) def changeCD(self, drivespec): - if cpuarch.is_ppc(self.arch): + if self.arch.is_ppc(): blockdev = 'sda' else: blockdev = 'hdc' diff --git a/vdsm/virt/vmxml.py b/vdsm/virt/vmxml.py index 3d0c828..729ad78 100644 --- a/vdsm/virt/vmxml.py +++ b/vdsm/virt/vmxml.py @@ -204,7 +204,7 @@ m.appendChildWithArgs('timer', name='rtc', tickpolicy='catchup') m.appendChildWithArgs('timer', name='pit', tickpolicy='delay') - if cpuarch.is_x86(self.arch): + if self.arch.is_x86(): m.appendChildWithArgs('timer', name='hpet', present='no') self.dom.appendChild(m) @@ -277,7 +277,7 @@ if self.conf.get('kernelArgs'): oselem.appendChildWithArgs('cmdline', text=self.conf['kernelArgs']) - if cpuarch.is_x86(self.arch): + if self.arch.is_x86(): oselem.appendChildWithArgs('smbios', mode='sysinfo') if utils.tobool(self.conf.get('bootMenuEnable', False)): @@ -400,7 +400,7 @@ cpu = Element('cpu') - if cpuarch.is_x86(self.arch): + if self.arch.is_x86(): cpu.setAttrs(match='exact') features = self.conf.get('cpuType', 'qemu64').split(',') @@ -429,7 +429,7 @@ elif feature[0] == '-': featureAttrs['policy'] = 'disable' cpu.appendChildWithArgs('feature', **featureAttrs) - elif cpuarch.is_ppc(self.arch): + elif self.arch.is_ppc(): features = self.conf.get('cpuType', 'POWER8').split(',') model = features[0] cpu.appendChildWithArgs('model', text=model) @@ -507,7 +507,7 @@ """ if utils.tobool(self.conf.get('tabletEnable')): inputAttrs = {'type': 'tablet', 'bus': 'usb'} - elif cpuarch.is_x86(self.arch): + elif self.arch.is_x86(): inputAttrs = {'type': 'mouse', 'bus': 'ps2'} else: inputAttrs = {'type': 'mouse', 'bus': 'usb'} diff --git a/vdsm_hooks/faqemu/after_get_caps.py b/vdsm_hooks/faqemu/after_get_caps.py index 2442971..fe27b82 100644 --- a/vdsm_hooks/faqemu/after_get_caps.py +++ b/vdsm_hooks/faqemu/after_get_caps.py @@ -55,7 +55,7 @@ caps['kvmEnabled'] = str(config.getboolean('vars', 'fake_kvm_support')) caps['emulatedMachines'] = PPC64LE_MACHINES + X86_64_MACHINES - if cpuarch.is_x86(arch): + if arch.is_x86(): caps['cpuModel'] = 'Intel(Fake) CPU' flagList = ['vmx', 'sse2', 'nx'] @@ -69,7 +69,7 @@ '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): + elif arch.is_ppc(): caps['cpuModel'] = 'POWER 8(fake)' caps['cpuFlags'] = 'powernv,model_POWER8' else: -- To view, visit https://gerrit.ovirt.org/51428 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I066575e98ff3778d915255f6c8a68667238fc6fb Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Martin Polednik <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
