def test_ap_lf(self, capsys, profile_type): """List and find activation profiles.""" cpc_name, session, client, cpc, faked_cpc = \ setup_cpc(capsys, self.hmc_creds, self.fake_data) if faked_cpc: faked_cpc.add_resources(self.faked_cpc_resources) ap_mgr_attr = profile_type + '_activation_profiles' ap_class = profile_type + '-activation-profile' ap_mgr = getattr(cpc, ap_mgr_attr) # Test listing activation profiles ap_list = ap_mgr.list() assert len(ap_list) >= 1 for ap in ap_list: assert isinstance(ap, zhmcclient.ActivationProfile) # Pick the last one returned ap = ap_list[-1] ap_name = ap.name # Test finding the activation profile based on its (cached) name ap_found = ap_mgr.find(name=ap_name) assert ap_found.name == ap_name # There are no other server-side filtered props besides name # Test finding the partition based on a client-side filtered prop aps_found = ap_mgr.findall(**{'class': ap_class}) assert ap_name in [ap.name for ap in aps_found] # noqa: F812 # Cleanup session.logoff()
def test_crud(self, capsys): """Create, read, update and delete a partition.""" cpc_name, session, client, cpc, faked_cpc = \ setup_cpc(capsys, self.hmc_creds, self.fake_data) part_name = self.NAME_PREFIX + 'test_crud.part1' # Ensure a clean starting point for this test try: part = cpc.partitions.find(name=part_name) except zhmcclient.NotFound: pass else: info(capsys, "Cleaning up partition from previous run: {!r}".format(part)) status = part.get_property('status') if status != 'stopped': part.stop() part.delete() # Test creating the partition part_input_props = { 'name': part_name, 'description': 'Dummy partition description.', 'ifl-processors': 2, 'initial-memory': 1024, 'maximum-memory': 2048, 'processor-mode': 'shared', # used for filtering 'type': 'linux', # used for filtering } part_auto_props = { 'status': 'stopped', } part = cpc.partitions.create(part_input_props) for pn in part_input_props: exp_value = part_input_props[pn] assert part.properties[pn] == exp_value, \ "Unexpected value for property {!r}".format(pn) part.pull_full_properties() for pn in part_input_props: exp_value = part_input_props[pn] assert part.properties[pn] == exp_value, \ "Unexpected value for property {!r}".format(pn) for pn in part_auto_props: exp_value = part_auto_props[pn] assert part.properties[pn] == exp_value, \ "Unexpected value for property {!r}".format(pn) # Test finding the partition based on its (cached) name p = cpc.partitions.find(name=part_name) assert p.name == part_name # Test finding the partition based on a server-side filtered prop parts = cpc.partitions.findall(type='linux') assert part_name in [p.name for p in parts] # noqa: F812 # Test finding the partition based on a client-side filtered prop parts = cpc.partitions.findall(**{'processor-mode': 'shared'}) assert part_name in [p.name for p in parts] # noqa: F812 # Test updating a property of the partition new_desc = "Updated partition description." part.update_properties(dict(description=new_desc)) assert part.properties['description'] == new_desc part.pull_full_properties() assert part.properties['description'] == new_desc # Test deleting the partition part.delete() with pytest.raises(zhmcclient.NotFound): cpc.partitions.find(name=part_name) # Cleanup session.logoff()
def test_stogrp_crud(self, capsys): """Create, read, update and delete a storage group.""" cpc_name, session, client, cpc, faked_cpc = \ setup_cpc(capsys, self.hmc_creds, self.fake_data) if not self.dpm_storage_management_enabled(cpc): info( capsys, "DPM Storage feature not enabled or not supported; " "Skipping test_stogrp_crud() test case") return console = client.consoles.console stogrp_name = self.NAME_PREFIX + 'test_stogrp_crud.stogrp1' # Ensure clean starting point try: stogrp = console.storage_groups.find(name=stogrp_name) except zhmcclient.NotFound: pass else: info( capsys, "Cleaning up storage group from previous run: {!r}".format( stogrp)) stogrp.delete() # Test creating the storage group stogrp_input_props = { 'name': stogrp_name, 'description': 'Dummy storage group description.', 'type': 'fcp', } stogrp_auto_props = { 'shared': False, 'active': False, 'fulfillment-state': 'creating', 'adapter-count': 1, } stogrp = console.storage_groups.create(stogrp_input_props) for pn in stogrp_input_props: exp_value = stogrp_input_props[pn] assert stogrp.properties[pn] == exp_value, \ "Unexpected value for property {!r} of storage group:\n" \ "{!r}".format(pn, sorted(stogrp.properties)) stogrp.pull_full_properties() for pn in stogrp_input_props: exp_value = stogrp_input_props[pn] assert stogrp.properties[pn] == exp_value, \ "Unexpected value for property {!r} of storage group:\n" \ "{!r}".format(pn, sorted(stogrp.properties)) if not faked_cpc: for pn in stogrp_auto_props: exp_value = stogrp_auto_props[pn] assert stogrp.properties[pn] == exp_value, \ "Unexpected value for property {!r} of storage group:\n" \ "{!r}".format(pn, sorted(stogrp.properties)) # Test finding the storage group based on its (cached) name sg = console.storage_groups.find(name=stogrp_name) assert sg.name == stogrp_name # Test finding the storage group based on a server-side filtered prop stogrps = console.storage_groups.findall(type='fcp') assert stogrp_name in [sg.name for sg in stogrps] # noqa: F812 # Test finding the storage group based on a client-side filtered prop stogrps = console.storage_groups.findall(active=False) assert stogrp_name in [sg.name for sg in stogrps] # Test updating a property of the storage group new_desc = "Updated storage group description." stogrp.update_properties(dict(description=new_desc)) assert stogrp.properties['description'] == new_desc stogrp.pull_full_properties() assert stogrp.properties['description'] == new_desc # Test deleting the storage group stogrp.delete() with pytest.raises(zhmcclient.NotFound): console.storage_groups.find(name=stogrp_name) # Cleanup session.logoff()
def test_stovol_crud(self, capsys): """Create, read, update and delete a storage volume in a sto.grp.""" cpc_name, session, client, cpc, faked_cpc = \ setup_cpc(capsys, self.hmc_creds, self.fake_data) if not self.dpm_storage_management_enabled(cpc): info( capsys, "DPM Storage feature not enabled or not supported; " "Skipping test_stovol_crud() test case") return console = client.consoles.console stogrp_name = self.NAME_PREFIX + 'test_stovol_crud.stogrp1' stovol_name = self.NAME_PREFIX + 'test_stovol_crud.stovol1' # Ensure clean starting point try: stogrp = console.storage_groups.find(name=stogrp_name) except zhmcclient.NotFound: pass else: info( capsys, "Cleaning up storage group from previous run: {!r}".format( stogrp)) stogrp.delete() # Create a storage group for the volume stogrp = console.storage_groups.create( dict(name=stogrp_name, type='fcp')) # Test creating a volume stovol_input_props = { 'name': stovol_name, 'description': 'Dummy storage volume description.', 'size': 100, # MB } stovol_auto_props = { 'fulfillment-state': 'creating', 'usage': 'data', } # TODO: Remove this tempfix when fixed: if True: info( capsys, "Tempfix: Volume does not support 'cpc-uri' " "property; Omitting it in Create Volume.") else: stovol_input_props['cpc-uri'] = cpc.uri stovol = stogrp.storage_volumes.create(stovol_input_props) for pn in stovol_input_props: exp_value = stovol_input_props[pn] assert stovol.properties[pn] == exp_value, \ "Unexpected value for property {!r} of storage volume:\n" \ "{!r}".format(pn, sorted(stovol.properties)) stovol.pull_full_properties() for pn in stovol_input_props: # TODO: Remove this tempfix when fixed: if pn == 'name': info( capsys, "Tempfix: Create Volume does not honor name; " "Skipping assertion of name:\n" " provided name: %r\n" " created name: %r" % (stovol_input_props[pn], stovol.properties[pn])) continue exp_value = stovol_input_props[pn] assert stovol.properties[pn] == exp_value, \ "Unexpected value for property {!r} of storage volume:\n" \ "{!r}".format(pn, sorted(stovol.properties)) if not faked_cpc: for pn in stovol_auto_props: exp_value = stovol_auto_props[pn] assert stovol.properties[pn] == exp_value, \ "Unexpected value for property {!r} of storage volume:\n" \ "{!r}".format(pn, sorted(stovol.properties)) # Test finding the storage volume based on its (cached) name sv = stogrp.storage_volumes.find(name=stovol_name) assert sv.name == stovol_name # Test finding the storage volume based on a server-side filtered prop # TODO: Remove this tempfix when fixed: try: stovols = stogrp.storage_volumes.find(usage='data') except zhmcclient.HTTPError as exc: if exc.http_status == 500: info( capsys, "Tempfix: List Volumes filtered by usage raises " "%s,%s %r; Skipping this test." % (exc.http_status, exc.reason, exc.message)) else: assert stovol_name in [sv.name for sv in stovols] # noqa: F812 # Test finding the storage group based on a client-side filtered prop # TODO: Remove this tempfix when fixed: try: stovols = stogrp.storage_volumes.findall(active=False) except zhmcclient.HTTPError as exc: if exc.http_status == 500: info( capsys, "Tempfix: List Volumes raises " "%s,%s %r; Skipping this test." % (exc.http_status, exc.reason, exc.message)) else: assert stovol_name in [sv.name for sv in stovols] # Test updating a property of the storage volume new_desc = "Updated storage volume description." stovol.update_properties(dict(description=new_desc)) assert stovol.properties['description'] == new_desc stovol.pull_full_properties() assert stovol.properties['description'] == new_desc # Test deleting the storage volume # TODO: Remove this tempfix when fixed: try: stovol.delete() except zhmcclient.HTTPError as exc: if exc.http_status == 500: info( capsys, "Tempfix: Delete Volume raises " "%s,%s %r; Skipping this test." % (exc.http_status, exc.reason, exc.message)) else: with pytest.raises(zhmcclient.NotFound): stogrp.storage_volumes.find(name=stovol_name) # Cleanup stogrp.delete() session.logoff()