zhmcclient / python-zhmcclient

A pure Python client library for the IBM Z HMC Web Services API
Apache License 2.0
38 stars 26 forks source link

zhmccliet_mock framework- partition start stop works with different partition object #211

Closed preethipy closed 7 years ago

preethipy commented 7 years ago

Actual behavior

partition.delete() invokation followed with query of status parameter on Partition fails

File "nova_dpm/virt/dpm/vm.py", line 315, in destroy if (self.partition.properties['status'] == 'stopped'): KeyError: 'status'

Placed some debuglogs in _urihandler.py and vm.py to see if the partition object is same but doesnt seem to be so... ###############destroy function debug logs in vm.py################### destroy function /api/partitions/1 140453452362448 #################logs from _urihandler.py############################ PartitionStopHandler /api/partitions/1 140453452274384 stopped {'virtual-function-uris': [], 'hba-uris': ['/api/partitions/1/hbas/1'], 'object-uri': '/api/partitions/1', 'initial-memory': 512, 'nic-uris': [], 'status': 'stopped', 'ifl-processors': 1, 'name': 'OpenStack-fakemini-38400000-8cf0-11bd-b23e-10b96e4ef00d', 'object-id': '1', 'description': 'Partition #1 in CPC #2'}

Expected behavior

partition.delete() with zhmcclient_mock is expected to have invoked the mocking framework's PartitionStopHandler function in _urihandler.py which is expected to add new parameter 'status' which is set with value "stopped"

Execution environment

zhmccliet_mock

andy-maier commented 7 years ago

The root cause for the problem you were seeing is that the unit test code tried to access the 'status' property without first refreshing the properties, e.g. via pull_full_properties(). With a real HMC, the status would still show the previous value before the stop() method, even when the support in zhmcclient v0.11.0 for waiting for completion of status transition is in place. With the mock support, the symptom is more drastic, because the 'status' property does not exist in the Python resource object until the pull_full_properties() method has been called, so a KeyError is raised.

PR #218 improves the situation in the mock support of the zhmcclient by ensuring that there is a 'status' property, so the behavior of the mock support is now closer to the behavior of a real HMC. However, as stated, the real fix is to change the unit test code to issue pull_full_properties() after the stop().

andy-maier commented 7 years ago

BTW, the different Partition objects are not a problem. The zhmcclient returns different Python objects for the same HMC resource in some situations, both for the real HMC and for the mock support. In the mock support, these different objects are fed from the same faked resource state in the Faked* objects.