Repository: pywbem/pywbemtools (language: python)

Issue:
testmock/wbemserver_mock_class.py issue with getting instance
In once case in this test code, where the path for an instance get includes the host name, the request fails with pywbem 1.5.0-dev but passes with pywbem 1.4.1.

The error returned is:

Mock script tests/unit/pywbemcli/testmock/wbemserver_mock_script.py failed: 4 (CIM_ERR_INVALID_PARAMETER): Reference property 'ManagedElement' association end point CIMInstanceName(classname='MCK_StorageComputerSystem', keybindings=NocaseDict({'Name': '10.1.2.3', 'CreationClassName': 'MCK_StorageComputerSystem'}), namespace='root/cimv2', host='FakedUrl:5988') does not exist 
Aborted!

Removing the set host corrects the issue for both pywbem 1.4.1 and pywbem 1.5.0

                central_inst_path = CIMInstanceName(
                    item[1][0],
                    keybindings=item[1][1],
                    host=conn.host,   ## <<<<<<<<<<<<<<<<<Here lay dragons
                    namespace=ns)

Removing the line host=conn.host fixes the issue but this means we have a weakness in the mock instance get and possibly create to be sure use of host in the repository is consistent.





Discussion / hints:
The issue is actually in pywbem _instance_write_provider about line 842 

    return inst_store.object_exists(path)

where the instance path is:

CIMInstanceName(classname='MCK_StorageComputerSystem', keybindings=NocaseDict({'Name': '10.1.2.3', 'CreationClassName': 'MCK_StorageComputerSystem'}), namespace='root/cimv2', host='FakedUrl:5988'), one of the
reference properties

This is a call to the mock repository which by definition is sets the key  for all instances with host = None.   In this case,
the user put the host name into the path.  In previous pywbem versions we did not check for valid path on associations.

Since the mocker was designed to be a local mechanism and we did not consider cross-host associations, the most logical
solution is to just test for the existence of host and remove it.  The only possibility beyond that would be to check the host name against the conn url and only remove it if they match.  Otherwise, fail as we do now.  However, this means adding a new parameter to the set of classes that represent the providers (BaseProvider, InstanceWriteProvider, NamespaceProvider, etc. to be able to at least pass on the host name element so that the InstanceWriteProvider.CreateInstance could test the host name of any references to see if they match the mocker host name.

The alternative is to simply set the host name to None  before testing for the existence of references and Issue a warning for any CreateInstance association reference property that includes a host name.



Fix patch:
diff --git a/docs/changes.rst b/docs/changes.rst
index 83de729c..cfd26c6c 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -90,6 +90,12 @@ Released: not yet
 * Fixed tests that fail because XML output of classes and qualifier declarations
   return attributes not ordered before python version 3.8. (see issue #1173).
 
+* Modify tests/unit/pywbemcli/wbemserver_mock_class.py to remove the
+  CIMInstanceName host lement used in creating a ProfileImplements instance.  That
+  element of CIMInstanceName is not allowed on Create instance of association
+  classes and as of pywbem 1.5.0 that limitation is enforces.  (see issue
+  #1203)
+
 
 **Known issues:**
 


Test patch:
diff --git a/tests/unit/pywbemcli/testmock/wbemserver_mock_class.py b/tests/unit/pywbemcli/testmock/wbemserver_mock_class.py
index d7757f46..24b83743 100644
--- a/tests/unit/pywbemcli/testmock/wbemserver_mock_class.py
+++ b/tests/unit/pywbemcli/testmock/wbemserver_mock_class.py
@@ -324,7 +324,6 @@ def __init__(self, conn, server, interop_ns=None, server_mock_data=None,
                 central_inst_path = CIMInstanceName(
                     item[1][0],
                     keybindings=item[1][1],
-                    host=conn.host,
                     namespace=ns)
                 prof_insts = self.wbem_server.get_selected_profiles(
                     registered_org=profile_name[0],