def test_external_storage_resource_block_with_empty_sp_list(self): zone_ids = ["5394236a-384b-4151-9e32-685dbe990e93"] expected_resource_block = copy.deepcopy( self.external_storage_rb_mockup) expected_resource_block["Links"]["ComputerSystems"] = [] resource_block = StorageResourceBlock(self.volume, None, zone_ids, []) result = json.loads(resource_block.serialize()) self.assertEqual(expected_resource_block["Name"], result["Name"]) self.assertEqual(expected_resource_block["Id"], result["Id"])
def test_external_storage_resource_block(self): zone_ids = ["5394236a-384b-4151-9e32-685dbe990e93"] server_profiles = [ "/rest/server-profiles/72d7f1ff-00e5-43b6-83c2-d4d61abd1708", "/rest/server-profiles/416c23ad-1587-4484-9174-e10afd1801f9" ] resource_block = StorageResourceBlock(self.volume, None, zone_ids, server_profiles) result = json.loads(resource_block.serialize()) self.assertEqualMockup(self.external_storage_rb_mockup, result)
def test_serialize(self): zone_ids = [ "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66101", "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66102", "1f0ca9ef-7f81-45e3-9d64-341b46cf87e0-0000000000A66103", "75871d70-789e-4cf9-8bc8-6f4d73193578", ] resource_block = StorageResourceBlock( self.drive, self.drive_index_tree, zone_ids) result = json.loads(resource_block.serialize()) self.assertEqualMockup(self.resource_block_mockup, result)
def test_when_server_profile_template_has_not_storage_controller(self): """This test is a invalid state (it should never occur) The Drive ever must have at least one Zone """ expected_result = copy.copy(self.resource_block_mockup) expected_result["Links"]["Zones"] = [] zone_ids = ["75871d70-789e-4cf9-8bc8-6f4d73193578"] resource_block = StorageResourceBlock( self.drive, self.drive_index_tree, zone_ids) result = json.loads(resource_block.serialize()) self.assertEqualMockup(self.resource_block_mockup, result)
def get_resource_block(uuid): """Get the Redfish ResourceBlock for a given UUID. Return ResourceBlock redfish JSON for a given UUID. Logs exception of any error and return Internal Server Error or Not Found. Returns: JSON: Redfish json with ResourceBlock. """ try: resource = _get_oneview_resource(uuid) category = resource["category"] if category == "server-hardware": resource_block = _build_computer_system_resource_block( uuid, resource) elif category == "server-profile-templates": resource_block = \ ServerProfileTemplateResourceBlock(uuid, resource) elif category == "drives": resource_block = StorageResourceBlock(resource) else: raise OneViewRedfishError('Resource block not found') return ResponseBuilder.success(resource_block, {"ETag": "W/" + resource["eTag"]}) except OneViewRedfishError as e: # In case of error log exception and abort logging.exception('Unexpected error: {}'.format(e)) abort(status.HTTP_404_NOT_FOUND, e.msg)
def test_private_storage_volume_resource_block(self): zone_ids = ["5394236a-384b-4151-9e32-685dbe990e93"] server_profiles = [ "/rest/server-profiles/72d7f1ff-00e5-43b6-83c2-d4d61abd1708", "/rest/server-profiles/416c23ad-1587-4484-9174-e10afd1801f9" ] volume = copy.deepcopy(self.volume) volume["isShareable"] = False external_storage_rb_mockup = copy.deepcopy( self.external_storage_rb_mockup) external_storage_rb_mockup["CompositionStatus"]["CompositionState"] = \ "Composed" external_storage_rb_mockup["CompositionStatus"]["SharingCapable"] = \ False resource_block = StorageResourceBlock(volume, None, zone_ids, server_profiles) result = json.loads(resource_block.serialize()) self.assertEqualMockup(external_storage_rb_mockup, result)
def get_resource_block(uuid): """Get the Redfish ResourceBlock for a given UUID. Return ResourceBlock redfish JSON for a given UUID. Logs exception of any error and return Internal Server Error or Not Found. Returns: JSON: Redfish json with ResourceBlock. """ zone_service = ZoneService(g.oneview_client) resource = _get_oneview_resource(uuid) category = resource["category"] if category == "server-hardware": result_resource_block = _build_computer_system_resource_block( uuid, resource) elif category == "server-profile-templates": zone_ids = zone_service.get_zone_ids_by_templates([resource]) if not zone_ids: abort(status.HTTP_404_NOT_FOUND, "Zone not found to ResourceBlock {}".format(uuid)) result_resource_block = \ ServerProfileTemplateResourceBlock(uuid, resource, zone_ids) elif category == "drives": drive_uuid = resource["uri"].split("/")[-1] drive_index_trees_uri = \ "/rest/index/trees/rest/drives/{}?parentDepth=3" drive_index_trees = g.oneview_client.connection.get( drive_index_trees_uri.format(drive_uuid)) server_profile_templs = \ g.oneview_client.server_profile_templates.get_all() zone_ids = zone_service.get_zone_ids_by_templates( server_profile_templs) result_resource_block = StorageResourceBlock( resource, drive_index_trees, zone_ids) else: abort(status.HTTP_404_NOT_FOUND, 'Resource block not found') return ResponseBuilder.success( result_resource_block, {"ETag": "W/" + resource["eTag"]})
def get_resource_block(uuid): """Get the Redfish ResourceBlock for a given UUID. Return ResourceBlock redfish JSON for a given UUID. Logs exception of any error and return Internal Server Error or Not Found. Returns: JSON: Redfish json with ResourceBlock. """ zone_service = ZoneService(g.oneview_client) resource = _get_oneview_resource(uuid) category = resource["category"] if category == "server-hardware": result_resource_block = _build_computer_system_resource_block( uuid, resource) elif category == "server-profile-templates": zone_ids = zone_service.get_zone_ids_by_templates([resource]) if not zone_ids: abort(status.HTTP_404_NOT_FOUND, "Zone not found to ResourceBlock {}".format(uuid)) result_resource_block = \ ServerProfileTemplateResourceBlock(uuid, resource, zone_ids) elif category == "drives": drive_uuid = resource["uri"].split("/")[-1] drive_index_trees_uri = \ "/rest/index/trees/rest/drives/{}?parentDepth=3" drive_index_trees = g.oneview_client.connection.get( drive_index_trees_uri.format(drive_uuid)) server_profile_templs = \ g.oneview_client.server_profile_templates.get_all() zone_ids = zone_service.get_zone_ids_by_templates( server_profile_templs) result_resource_block = StorageResourceBlock( resource, drive_index_trees, zone_ids, None) elif category == "storage-volumes": volumeUri = resource["uri"] # filter STP's with volume attached server_profile_templs = \ g.oneview_client.server_profile_templates.get_all() filter_spt = list(filter(lambda i: i["sanStorage"][ "volumeAttachments"], server_profile_templs)) spt_with_volume = [spt for spt in filter_spt for volume in spt["sanStorage"]["volumeAttachments"] if volume.get("volumeUri") == volumeUri] zone_ids = [] if spt_with_volume: zone_ids = zone_service.get_zone_ids_by_templates(spt_with_volume) # filter SP's with volume attached volume_attachments = g.oneview_client. \ storage_volume_attachments.get_all( filter="storageVolumeUri='{}'".format(volumeUri)) server_profiles = [i.get('ownerUri') for i in volume_attachments] result_resource_block = StorageResourceBlock( resource, None, zone_ids, server_profiles) else: abort(status.HTTP_404_NOT_FOUND, 'Resource block not found') return ResponseBuilder.success( result_resource_block, {"ETag": "W/" + resource["eTag"]})
def test_serialize(self): # Tests the serialize function result against known result resource_block = StorageResourceBlock(self.drive) result = json.loads(resource_block.serialize()) self.assertEqual(self.resource_block_mockup, result)
def test_class_instantiation(self): # Tests if class is correctly instantiated and validated resource_block = StorageResourceBlock(self.drive) self.assertIsInstance(resource_block, StorageResourceBlock)