Skip to content

Commit

Permalink
Enhanced faked resources to automatically set parent prop.
Browse files Browse the repository at this point in the history
Details:

- So far, test code needed to set the 'parent' property in faked resources
  explicitly, otherwise it was not present in the resulting Faked...
  resource object.

  This change sets the 'parent' property of all Faked... resource objects
  automatically to the URI of the parent faked object, unless the
  'parent' property is already set.

  This makes the definition of testcases easier and less error-prone.

- Added a 'parent' property to test_hmc.py.

Signed-off-by: Andreas Maier <[email protected]>
  • Loading branch information
andy-maier committed Sep 4, 2018
1 parent aa5775e commit 366c445
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/unit/zhmcclient_mock/test_hmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def test_hmc_1_cpc(self):
'object-id': cpc1.oid,
'object-uri': cpc1.uri,
'class': 'cpc',
'parent': None,
'dpm-enabled': False,
'is-ensemble-member': False,
'status': 'operating',
Expand All @@ -104,6 +105,7 @@ def test_hmc_2_cpcs(self):
'object-id': cpc1.oid,
'object-uri': cpc1.uri,
'class': 'cpc',
'parent': None,
'dpm-enabled': False,
'is-ensemble-member': False,
'status': 'operating',
Expand All @@ -119,6 +121,7 @@ def test_hmc_2_cpcs(self):
'object-id': cpc2.oid,
'object-uri': cpc2.uri,
'class': 'cpc',
'parent': None,
'dpm-enabled': False,
'is-ensemble-member': False,
'status': 'operating',
Expand Down Expand Up @@ -174,6 +177,7 @@ def test_res_dict(self):
'object-id': cpc1.oid,
'object-uri': cpc1.uri,
'class': 'cpc',
'parent': None,
'dpm-enabled': False,
'is-ensemble-member': False,
'status': 'operating',
Expand All @@ -197,6 +201,7 @@ def test_res_dict(self):
'object-id': adapter1.oid,
'object-uri': adapter1.uri,
'class': 'adapter',
'parent': cpc1.uri,
'status': 'active',
'network-port-uris': [port1.uri],
})
Expand All @@ -209,6 +214,7 @@ def test_res_dict(self):
'element-id': port1.oid,
'element-uri': port1.uri,
'class': 'network-port',
'parent': adapter1.uri,
})
assert isinstance(port1, FakedPort)
assert port1.properties == port1_out_props
Expand All @@ -230,6 +236,7 @@ def setup_method(self):
'object-id': self.cpc1_oid,
'object-uri': self.cpc1_uri,
'class': 'cpc',
'parent': None,
'dpm-enabled': True,
'is-ensemble-member': False,
'status': 'service',
Expand Down Expand Up @@ -370,6 +377,7 @@ def test_profiles_list(self):
'name': resetprofile1.oid,
'element-uri': resetprofile1.uri,
'class': 'reset-activation-profile',
'parent': cpc1.uri,
})
assert isinstance(resetprofile1, FakedActivationProfile)
assert resetprofile1.properties == resetprofile1_out_props
Expand All @@ -386,6 +394,7 @@ def test_profiles_list(self):
'name': imageprofile1.oid,
'element-uri': imageprofile1.uri,
'class': 'image-activation-profile',
'parent': cpc1.uri,
})
assert isinstance(imageprofile1, FakedActivationProfile)
assert imageprofile1.properties == imageprofile1_out_props
Expand All @@ -402,6 +411,7 @@ def test_profiles_list(self):
'name': loadprofile1.oid,
'element-uri': loadprofile1.uri,
'class': 'load-activation-profile',
'parent': cpc1.uri,
})
assert isinstance(loadprofile1, FakedActivationProfile)
assert loadprofile1.properties == loadprofile1_out_props
Expand Down Expand Up @@ -435,6 +445,7 @@ def test_profiles_add(self):
'name': resetprofile2.oid,
'element-uri': resetprofile2.uri,
'class': 'reset-activation-profile',
'parent': cpc1.uri,
})
assert isinstance(resetprofile2, FakedActivationProfile)
assert resetprofile2.properties == resetprofile2_out_props
Expand Down Expand Up @@ -520,6 +531,7 @@ def test_adapters_list(self):
'object-id': adapter1.oid,
'object-uri': adapter1.uri,
'class': 'adapter',
'parent': cpc1.uri,
'status': 'active',
'adapter-family': 'roce',
'network-port-uris': [],
Expand Down Expand Up @@ -558,6 +570,7 @@ def test_adapters_add(self):
'object-id': adapter2.oid,
'object-uri': adapter2.uri,
'class': 'adapter',
'parent': cpc1.uri,
'status': 'active',
'storage-port-uris': [],
})
Expand Down Expand Up @@ -626,6 +639,7 @@ def test_cpcs_list(self):
'object-id': cpc1.oid,
'object-uri': cpc1.uri,
'class': 'cpc',
'parent': None,
'dpm-enabled': False,
'is-ensemble-member': False,
'status': 'operating',
Expand Down Expand Up @@ -670,6 +684,7 @@ def test_cpcs_add(self):
'object-id': cpc2.oid,
'object-uri': cpc2.uri,
'class': 'cpc',
'parent': None,
'dpm-enabled': False,
'is-ensemble-member': False,
'status': 'operating',
Expand Down Expand Up @@ -774,6 +789,7 @@ def test_hbas_list(self):
'element-id': self.hba1_oid,
'element-uri': hba1.uri,
'class': 'hba',
'parent': partition1.uri,
'device-number': hba1.properties['device-number'],
'wwpn': hba1.properties['wwpn'],
})
Expand Down Expand Up @@ -819,6 +835,7 @@ def test_hbas_add(self):
'element-id': hba2_oid,
'element-uri': hba2.uri,
'class': 'hba',
'parent': partition1.uri,
})
assert isinstance(hba2, FakedHba)
assert hba2.properties == hba2_out_props
Expand Down Expand Up @@ -886,6 +903,7 @@ def test_lpars_list(self):
'object-id': lpar1.oid,
'object-uri': lpar1.uri,
'class': 'logical-partition',
'parent': cpc1.uri,
'status': 'not-activated',
})
assert isinstance(lpar1, FakedLpar)
Expand Down Expand Up @@ -919,6 +937,7 @@ def test_lpars_add(self):
'object-id': lpar2.oid,
'object-uri': lpar2.uri,
'class': 'logical-partition',
'parent': cpc1.uri,
'status': 'not-activated',
})
assert isinstance(lpar2, FakedLpar)
Expand Down Expand Up @@ -1023,6 +1042,7 @@ def test_nics_list(self):
'element-id': self.nic1_oid,
'element-uri': nic1.uri,
'class': 'nic',
'parent': partition1.uri,
'device-number': nic1.properties['device-number'],
})
assert isinstance(nic1, FakedNic)
Expand Down Expand Up @@ -1065,6 +1085,7 @@ def test_nics_add(self):
'element-id': nic2_oid,
'element-uri': nic2.uri,
'class': 'nic',
'parent': partition1.uri,
'device-number': nic2.properties['device-number'],
})
assert isinstance(nic2, FakedNic)
Expand Down Expand Up @@ -1149,6 +1170,7 @@ def test_partitions_list(self):
'object-id': partition1.oid,
'object-uri': partition1.uri,
'class': 'partition',
'parent': cpc1.uri,
'status': 'stopped',
'hba-uris': [],
'nic-uris': [],
Expand Down Expand Up @@ -1186,6 +1208,7 @@ def test_partitions_add(self):
'object-id': partition2.oid,
'object-uri': partition2.uri,
'class': 'partition',
'parent': cpc1.uri,
'status': 'stopped',
'hba-uris': [],
'nic-uris': [],
Expand Down Expand Up @@ -1264,6 +1287,7 @@ def test_ports_list(self):
'element-id': port1.oid,
'element-uri': port1.uri,
'class': 'network-port',
'parent': adapter1.uri,
})
assert isinstance(port1, FakedPort)
assert port1.properties == port1_out_props
Expand Down Expand Up @@ -1298,6 +1322,7 @@ def test_ports_add(self):
'element-id': port2.oid,
'element-uri': port2.uri,
'class': 'network-port',
'parent': adapter1.uri,
})
assert isinstance(port2, FakedPort)
assert port2.properties == port2_out_props
Expand Down Expand Up @@ -1380,6 +1405,7 @@ def test_virtual_functions_list(self):
'element-id': virtual_function1.oid,
'element-uri': virtual_function1.uri,
'class': 'virtual-function',
'parent': partition1.uri,
'device-number': virtual_function1.properties['device-number'],
})
assert isinstance(virtual_function1, FakedVirtualFunction)
Expand Down Expand Up @@ -1416,6 +1442,7 @@ def test_virtual_functions_add(self):
'element-id': virtual_function2.oid,
'element-uri': virtual_function2.uri,
'class': 'virtual-function',
'parent': partition1.uri,
'device-number': virtual_function2.properties['device-number'],
})
assert isinstance(virtual_function2, FakedVirtualFunction)
Expand Down Expand Up @@ -1486,6 +1513,7 @@ def test_virtual_switches_list(self):
'object-id': virtual_switch1.oid,
'object-uri': virtual_switch1.uri,
'class': 'virtual-switch',
'parent': cpc1.uri,
'connected-vnic-uris': [],
})
assert isinstance(virtual_switch1, FakedVirtualSwitch)
Expand Down Expand Up @@ -1520,6 +1548,7 @@ def test_virtual_switches_add(self):
'object-id': virtual_switch2.oid,
'object-uri': virtual_switch2.uri,
'class': 'virtual-switch',
'parent': cpc1.uri,
'connected-vnic-uris': [],
})
assert isinstance(virtual_switch2, FakedVirtualSwitch)
Expand Down Expand Up @@ -1591,6 +1620,7 @@ def test_metrics_contexts_add(self):
mc_props.update({
'fake-id': mc.oid,
'fake-uri': mc.uri,
'parent': None,
})
assert mc.properties == mc_props

Expand Down
Loading

0 comments on commit 366c445

Please sign in to comment.