From 0bc47663c050267d396472216b4b7ae53f840a9e Mon Sep 17 00:00:00 2001 From: Michal Minar Date: Sat, 6 Jul 2013 21:17:35 +0200 Subject: software: be more tolerant when checking SystemName Allow hostname aliases and fully qualified domain names in properties like SystemName. Modified tests accordingly. --- src/software/lmi/software/core/ComputerSystem.py | 6 +++--- src/software/lmi/software/core/IdentityResource.py | 2 +- src/software/lmi/software/util/__init__.py | 11 +++++++++++ src/software/test/test_hosted_software_collection.py | 2 +- src/software/test/test_hosted_software_identity_resource.py | 4 ++-- src/software/test/test_installed_software_identity.py | 2 +- src/software/test/test_resource_for_software_identity.py | 2 +- src/software/test/test_software_identity_file_check.py | 2 +- src/software/test/test_software_identity_resource.py | 2 +- 9 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src/software') diff --git a/src/software/lmi/software/core/ComputerSystem.py b/src/software/lmi/software/core/ComputerSystem.py index fe341d7..22b66c7 100644 --- a/src/software/lmi/software/core/ComputerSystem.py +++ b/src/software/lmi/software/core/ComputerSystem.py @@ -69,10 +69,10 @@ def check_path(env, system, prop_name): raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, "CreationClassName of \"%s\" must be a sublass of %s" % ( prop_name, our_system.classname)) - if system['Name'] != our_system['Name']: + if not util.is_this_system(system['Name']): raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, - "Name of \"%s\" does not match \"%s\"" % - prop_name, our_system['Name']) + "Name of \"%s\" does not match \"%s\"" % ( + prop_name, our_system['Name'])) return True @cmpi_logging.trace_function diff --git a/src/software/lmi/software/core/IdentityResource.py b/src/software/lmi/software/core/IdentityResource.py index 392dac7..cd7e481 100644 --- a/src/software/lmi/software/core/IdentityResource.py +++ b/src/software/lmi/software/core/IdentityResource.py @@ -517,7 +517,7 @@ def object_path2repo(env, op, kind='enabled'): or not op["SystemCreationClassName"]) or (not "SystemName" in op or not op["SystemName"])): raise pywbem.CIMError(pywbem.CIM_ERR_INVALID_PARAMETER, "Wrong keys.") - if op["SystemName"] != util.Configuration().system_name: + if not util.is_this_system(op["SystemName"]): raise pywbem.CIMError(pywbem.CIM_ERR_NOT_FOUND, 'SystemName "%s" does not match "%s".' % ( op["SystemName"], diff --git a/src/software/lmi/software/util/__init__.py b/src/software/lmi/software/util/__init__.py index fad9bcd..43fd4ba 100644 --- a/src/software/lmi/software/util/__init__.py +++ b/src/software/lmi/software/util/__init__.py @@ -27,6 +27,8 @@ import platform import pywbem import re import signal +import socket + from lmi.software.util.SoftwareConfiguration \ import SoftwareConfiguration as Configuration @@ -188,3 +190,12 @@ def new_instance_name(class_name, namespace=None, **kwargs): host=Configuration.get_instance().system_name, namespace=namespace, keybindings=keybindings) + +def is_this_system(system_name): + """ + Return True if given system_name matches the hostname of currently + running system. + """ + return ( socket.gethostbyaddr(system_name)[0] + == socket.gethostbyaddr( + Configuration.get_instance().system_name)[0]) diff --git a/src/software/test/test_hosted_software_collection.py b/src/software/test/test_hosted_software_collection.py index c260210..51abc9d 100755 --- a/src/software/test/test_hosted_software_collection.py +++ b/src/software/test/test_hosted_software_collection.py @@ -51,7 +51,7 @@ class TestHostedSoftwareCollection(base.SoftwareBaseTestCase): namespace="root/cimv2", keybindings=pywbem.NocaseDict({ "CreationClassName" : "Linux_ComputerSystem", - "Name" : socket.gethostname() + "Name" : socket.getfqdn() })) objpath["Dependent"] = pywbem.CIMInstanceName( classname="LMI_SystemSoftwareCollection", diff --git a/src/software/test/test_hosted_software_identity_resource.py b/src/software/test/test_hosted_software_identity_resource.py index 6a60e61..b931b31 100755 --- a/src/software/test/test_hosted_software_identity_resource.py +++ b/src/software/test/test_hosted_software_identity_resource.py @@ -54,7 +54,7 @@ class TestHostedSoftwareIdentityResource(base.SoftwareBaseTestCase): namespace="root/cimv2", keybindings=pywbem.NocaseDict({ "CreationClassName" : "Linux_ComputerSystem", - "Name" : socket.gethostname() + "Name" : socket.getfqdn() })) objpath["Dependent"] = pywbem.CIMInstanceName( classname="LMI_SoftwareIdentityResource", @@ -62,7 +62,7 @@ class TestHostedSoftwareIdentityResource(base.SoftwareBaseTestCase): keybindings=pywbem.NocaseDict({ "CreationClassName" : "LMI_SoftwareIdentityResource", "SystemCreationClassName" : "Linux_ComputerSystem", - "SystemName" : socket.gethostname(), + "SystemName" : socket.getfqdn(), "Name" : repo.repoid })) return objpath diff --git a/src/software/test/test_installed_software_identity.py b/src/software/test/test_installed_software_identity.py index bf8fe2c..1a038c3 100755 --- a/src/software/test/test_installed_software_identity.py +++ b/src/software/test/test_installed_software_identity.py @@ -47,7 +47,7 @@ class TestInstalledSoftwareIdentity(base.SoftwareBaseTestCase): namespace="root/cimv2", keybindings=pywbem.NocaseDict({ "CreationClassName" : "Linux_ComputerSystem", - "Name" : socket.gethostname() + "Name" : socket.getfqdn() })) objpath["InstalledSoftware"] = pywbem.CIMInstanceName( classname="LMI_SoftwareIdentity", diff --git a/src/software/test/test_resource_for_software_identity.py b/src/software/test/test_resource_for_software_identity.py index d38da46..a9c2cf6 100755 --- a/src/software/test/test_resource_for_software_identity.py +++ b/src/software/test/test_resource_for_software_identity.py @@ -51,7 +51,7 @@ class TestResourceForSoftwareIdentity(base.SoftwareBaseTestCase): keybindings=pywbem.NocaseDict({ "CreationClassName" : "LMI_SoftwareIdentityResource", "SystemCreationClassName" : "Linux_ComputerSystem", - "SystemName" : socket.gethostname() + "SystemName" : socket.getfqdn() })) if repo is not None: objpath["AvailableSAP"]["Name"] = repo.repoid diff --git a/src/software/test/test_software_identity_file_check.py b/src/software/test/test_software_identity_file_check.py index 69c942a..027e17f 100755 --- a/src/software/test/test_software_identity_file_check.py +++ b/src/software/test/test_software_identity_file_check.py @@ -373,7 +373,7 @@ class TestSoftwareIdentityFileCheck( classname="Linux_ComputerSystem", keybindings=pywbem.NocaseDict({ "CreationClassName" : "Linux_ComputerSystem", - "Name" : socket.gethostname()}))) + "Name" : socket.getfqdn()}))) self.assertEqual(pywbem.Uint32(0), #Satisfied rval, msg="InvokeOnSystem method should be successful" diff --git a/src/software/test/test_software_identity_resource.py b/src/software/test/test_software_identity_resource.py index ecdc263..5d4b5ab 100755 --- a/src/software/test/test_software_identity_resource.py +++ b/src/software/test/test_software_identity_resource.py @@ -61,7 +61,7 @@ class TestSoftwareIdentityResource( repo = repo.repoid objpath = self.objpath.copy() objpath["Name"] = repo - objpath["SystemName"] = socket.gethostname() + objpath["SystemName"] = socket.getfqdn() return objpath def tearDown(self): -- cgit