Dima Kuznetsov has uploaded a new change for review. Change subject: hwinfo: Move calls from utils to hwinfo ......................................................................
hwinfo: Move calls from utils to hwinfo Change-Id: I0b949b34d0dfbadc9d91cd957edde10ce437e6d4 Signed-off-by: Dima Kuznetsov <[email protected]> --- M lib/vdsm/tool/register.py M lib/vdsm/tool/vdsm-id.py M lib/vdsm/utils.py M tests/vmTests.py M vdsm/caps.py M vdsm/supervdsmServer M vdsm/virt/vm.py 7 files changed, 14 insertions(+), 75 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/00/44600/1 diff --git a/lib/vdsm/tool/register.py b/lib/vdsm/tool/register.py index df56671..47fcef5 100644 --- a/lib/vdsm/tool/register.py +++ b/lib/vdsm/tool/register.py @@ -29,9 +29,10 @@ import selinux from . import expose +from .. import hwinfo from .. import utils -from vdsm.utils import getHostUUID, tobool +from vdsm.utils import tobool class Register(object): @@ -246,7 +247,7 @@ Determine host UUID and if there is no existing /etc/vdsm/vdsm.id it will genereate UUID and save/persist in /etc/vdsm/vdsm.id """ - self.uuid = getHostUUID(legacy=False) + self.uuid = hwinfo.get_host_uuid(legacy=False) self.url_reg += "&uniqueId={u}".format(u=self.uuid) self.logger.debug("Registration via: {u}".format(u=self.url_reg)) diff --git a/lib/vdsm/tool/vdsm-id.py b/lib/vdsm/tool/vdsm-id.py index 379b926..fd45236 100644 --- a/lib/vdsm/tool/vdsm-id.py +++ b/lib/vdsm/tool/vdsm-id.py @@ -18,7 +18,7 @@ # from __future__ import absolute_import -from ..utils import getHostUUID +from .. import hwinfo from . import expose, ExtraArgsError import sys @@ -31,7 +31,7 @@ """ if len(args) > 1: raise ExtraArgsError() - hostUUID = getHostUUID(False) + hostUUID = hwinfo.get_host_uuid(False) if hostUUID is None: raise EnvironmentError('Cannot retrieve host UUID') sys.stdout.write(hostUUID) diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index d847a23..3596575 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -43,7 +43,6 @@ import six import sys import os -import platform import random import select import shutil @@ -775,54 +774,6 @@ except: return False - -__hostUUID = None - - -def getHostUUID(legacy=False): - global __hostUUID - - if legacy: - raise NotImplementedError - - if __hostUUID: - return __hostUUID - - __hostUUID = None - - try: - if os.path.exists(constants.P_VDSM_NODE_ID): - with open(constants.P_VDSM_NODE_ID) as f: - __hostUUID = f.readline().replace("\n", "") - else: - arch = platform.machine() - if arch in ('x86_64', 'i686'): - 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' - __hostUUID = out.strip() - else: - logging.warning('Could not find host UUID.') - elif arch in ('ppc', 'ppc64'): - # eg. output IBM,03061C14A - try: - with open('/proc/device-tree/system-id') as f: - systemId = f.readline() - __hostUUID = systemId.rstrip('\0').replace(',', '') - except IOError: - logging.warning('Could not find host UUID.') - - except: - logging.error("Error retrieving host UUID", exc_info=True) - - return __hostUUID symbolerror = {} for code, symbol in errno.errorcode.iteritems(): diff --git a/tests/vmTests.py b/tests/vmTests.py index 30c7473..d279628 100644 --- a/tests/vmTests.py +++ b/tests/vmTests.py @@ -48,6 +48,7 @@ from testlib import XMLTestCase import caps import hooks +from vdsm import hwinfo from vdsm import utils from vdsm import libvirtconnection from monkeypatch import MonkeyPatch, MonkeyPatchScope @@ -473,7 +474,7 @@ @MonkeyPatch(constants, 'SMBIOS_MANUFACTURER', 'oVirt') @MonkeyPatch(constants, 'SMBIOS_OSNAME', 'oVirt Node') @MonkeyPatch(libvirtconnection, 'get', fake.Connection) - @MonkeyPatch(utils, 'getHostUUID', + @MonkeyPatch(hwinfo, 'get_host_uuid', lambda: "fc25cbbe-5520-4f83-b82e-1541914753d9") @MonkeyPatch(vm.Vm, 'send_status_event', lambda x: None) def testBuildCmdLineX86_64(self): @@ -483,7 +484,7 @@ @MonkeyPatch(caps, 'osversion', lambda: { 'release': '1', 'version': '18', 'name': 'Fedora'}) @MonkeyPatch(libvirtconnection, 'get', fake.Connection) - @MonkeyPatch(utils, 'getHostUUID', + @MonkeyPatch(hwinfo, 'get_host_uuid', lambda: "fc25cbbe-5520-4f83-b82e-1541914753d9") @MonkeyPatch(vm.Vm, 'send_status_event', lambda x: None) def testBuildCmdLinePPC64(self): diff --git a/vdsm/caps.py b/vdsm/caps.py index b443fab..387ee47 100644 --- a/vdsm/caps.py +++ b/vdsm/caps.py @@ -36,6 +36,7 @@ import rpm from vdsm.config import config +from vdsm.hwinfo import Architecture, get_host_uuid from vdsm import libvirtconnection import dsaversion from vdsm import netinfo @@ -120,13 +121,6 @@ if classes: cls, = classes attrs['hostQos'] = {'out': cls['hfsc']} - - -class Architecture: - X86_64 = 'x86_64' - PPC64 = 'ppc64' - PPC64LE = 'ppc64le' - POWER = (PPC64, PPC64LE) class CpuInfo(object): @@ -647,7 +641,7 @@ logging.debug('not reporting hooks', exc_info=True) caps['operatingSystem'] = osversion() - caps['uuid'] = utils.getHostUUID() + caps['uuid'] = get_host_uuid() caps['packages2'] = _getKeyPackages() caps['emulatedMachines'] = _getEmulatedMachines(targetArch) caps['ISCSIInitiatorName'] = _getIscsiIniName() diff --git a/vdsm/supervdsmServer b/vdsm/supervdsmServer index e836368..ee3fca3 100755 --- a/vdsm/supervdsmServer +++ b/vdsm/supervdsmServer @@ -18,7 +18,6 @@ # Refer to the README and COPYING files for full details of the license # from pwd import getpwnam -import platform import sys import os import stat @@ -34,7 +33,7 @@ from vdsm.infra import sigutils from vdsm.infra import zombiereaper -from caps import Architecture +from vdsm import hwinfo import numaUtils LOG_CONF_PATH = "/etc/vdsm/svdsm.logger.conf" @@ -131,15 +130,7 @@ @logDecorator def getHardwareInfo(self, *args, **kwargs): - if platform.machine() in ('x86_64', 'i686'): - from dmidecodeUtil import getHardwareInfoStructure - return getHardwareInfoStructure() - elif platform.machine() in Architecture.POWER: - from ppc64HardwareInfo import getHardwareInfoStructure - return getHardwareInfoStructure() - else: - # not implemented over other architecture - return {} + return hwinfo.get_hardware_info() @logDecorator def getDevicePartedInfo(self, *args, **kwargs): diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py index 572f1c5..9fd017c 100644 --- a/vdsm/virt/vm.py +++ b/vdsm/virt/vm.py @@ -35,6 +35,7 @@ # vdsm imports from vdsm import constants +from vdsm import hwinfo from vdsm import libvirtconnection from vdsm import netinfo from vdsm import qemuimg @@ -1604,7 +1605,7 @@ osd = caps.osversion() osVersion = osd.get('version', '') + '-' + osd.get('release', '') - serialNumber = self.conf.get('serial', utils.getHostUUID()) + serialNumber = self.conf.get('serial', hwinfo.get_host_uuid()) domxml.appendSysinfo( osname=constants.SMBIOS_OSNAME, -- To view, visit https://gerrit.ovirt.org/44600 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0b949b34d0dfbadc9d91cd957edde10ce437e6d4 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Dima Kuznetsov <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
