def get_storage(uuid): """Get the Redfish Storage for a given UUID. Return Storage Redfish JSON for a given server profile UUID. Logs exception of any error and return abort(500) Internal Server Error. Returns: JSON: Redfish json with Storage When server profile or server hardware type is not found calls abort(404) Exceptions: Logs the exception and call abort(500) """ server_profile = g.oneview_client.server_profiles.get(uuid) sht_uri = server_profile['serverHardwareTypeUri'] server_hardware_type = \ g.oneview_client.server_hardware_types.get(sht_uri) sas_logical_jbods = _find_sas_logical_jbods_by(server_profile) external_storage_volumes = [volume for volume in server_profile[ "sanStorage"]["volumeAttachments"]] st = Storage.build_for_composed_system(server_profile, server_hardware_type, sas_logical_jbods, external_storage_volumes) return ResponseBuilder.success(st)
def test_build_for_composed_system(self): with open( 'oneview_redfish_toolkit/mockups/oneview/ServerProfile.json' ) as f: server_profile = json.load(f) with open( 'oneview_redfish_toolkit/mockups/oneview/ServerHardwareTypes.json' ) as f: server_hardware_types = json.load(f) with open( 'oneview_redfish_toolkit/mockups/oneview/' 'SASLogicalJBODListForStorage.json' ) as f: sas_logical_jbods = json.load(f) with open( 'oneview_redfish_toolkit/mockups/redfish/Storage.json' ) as f: storage_mockup = json.load(f) with open('oneview_redfish_toolkit/mockups/oneview/' 'Volumes.json') as f: volumes = json.load(f) volume = volumes[0] storage = Storage.build_for_composed_system(server_profile, server_hardware_types, sas_logical_jbods, volume) result = json.loads(storage.serialize()) self.assertEqualMockup(storage_mockup, result)
def get_storage_details(resource_block_uuid, storage_id): """Get the Redfish Storage details of a Storage ResourceBlock for a given ID. Return Storage redfish JSON for a given ID. Logs exception of any error and return Internal Server Error or Not Found. Returns: JSON: Redfish json with Storage detail information. """ if str(storage_id) != FROZEN_ID: abort( status.HTTP_404_NOT_FOUND, "Storage {} not found for ResourceBlock {}".format( storage_id, resource_block_uuid)) storage_block = [] try: storage_block = g.oneview_client.volumes.get(resource_block_uuid) except HPOneViewException as e: if e.oneview_response["errorCode"] == 'RESOURCE_NOT_FOUND': storage_block = g.oneview_client.index_resources.get( '/rest/drives/' + resource_block_uuid) result = Storage.build_for_resource_block(storage_block) return ResponseBuilder.success(result)
def test_serialize(self): # Tests the serialize function result against known result try: storage = Storage('30303437-3034-4D32-3230-313133364752', self.server_hardware_types) except Exception as e: self.fail("Failed to instantiate Storage class." " Error: {}".format(e)) try: result = json.loads(storage.serialize()) except Exception as e: self.fail("Failed to serialize. Error: ".format(e)) self.assertEqual(self.storage_mockup, result)
def test_class_instantiation(self): # Tests if class is correctly instantiated and validated try: storage = Storage('30303437-3034-4D32-3230-313133364752', self.server_hardware_types) except Exception as e: self.fail("Failed to instantiate Storage class." " Error: {}".format(e)) self.assertIsInstance(storage, Storage)
def test_build_for_resource_block(self): with open('oneview_redfish_toolkit/mockups/oneview/Drive.json') as f: drive = json.load(f) with open('oneview_redfish_toolkit/mockups/redfish/' 'StorageForResourceBlock.json') as f: expected_result = json.load(f) storage = Storage.build_for_resource_block(drive) result = json.loads(storage.serialize()) self.assertEqualMockup(expected_result, result)
def test_build_for_resource_block_for_external_storage(self): with open( 'oneview_redfish_toolkit/mockups/oneview/Volumes.json' ) as f: volume = json.load(f) with open( 'oneview_redfish_toolkit/mockups/redfish/' 'ExternalStorageForResourceBlock.json' ) as f: expected_result = json.load(f) storage = Storage.build_for_resource_block(volume[0]) result = json.loads(storage.serialize()) self.assertEqualMockup(expected_result, result)
def get_storage(uuid): """Get the Redfish Storage for a given UUID. Return Storage Redfish JSON for a given hardware UUID. Logs exception of any error and return abort(500) Internal Server Error. Returns: JSON: Redfish json with Storage When hardware or hardware type is not found calls abort(404) Exceptions: Logs the exception and call abort(500) """ try: server_hardware = g.oneview_client.server_hardware. \ get(uuid) sht_uri = server_hardware['serverHardwareTypeUri'] server_hardware_type = \ g.oneview_client.server_hardware_types.get(sht_uri) st = Storage(uuid, server_hardware_type) json_str = st.serialize() return Response( response=json_str, status=status.HTTP_200_OK, mimetype="application/json") except HPOneViewException as e: if e.oneview_response['errorCode'] == "RESOURCE_NOT_FOUND": if e.msg.find("server-hardware-types") >= 0: logging.warning( 'Server hardware type ID {} not found'. format(server_hardware['serverHardwareTypeUri'])) abort( status.HTTP_404_NOT_FOUND, "Server hardware types not found") else: logging.warning( 'Server hardware UUID {} not found'. format(uuid)) abort( status.HTTP_404_NOT_FOUND, "Server hardware not found") elif e.msg.find("server-hardware-types") >= 0: logging.exception( 'OneView Exception while looking for server hardware type' ' {}'.format(e) ) abort(status.HTTP_500_INTERNAL_SERVER_ERROR) elif e.msg.find("server-hardware") >= 0: logging.exception( 'OneView Exception while looking for ' 'server hardware: {}'.format(e) ) abort(status.HTTP_500_INTERNAL_SERVER_ERROR) else: logging.exception('Unexpected OneView Exception: {}'.format(e)) abort(status.HTTP_500_INTERNAL_SERVER_ERROR) except Exception as e: # In case of error print exception and abort logging.exception('Unexpected error: {}'.format(e)) return abort(status.HTTP_500_INTERNAL_SERVER_ERROR)