def get_resource_block_collection(): """Get the Redfish ResourceBlock Collection. Return ResourceBlockCollection redfish JSON. Logs exception of any error and return Internal Server Error or Not Found. Returns: JSON: Redfish json with ResourceBlockCollection. """ try: # Gets all server hardware server_hardware_list = g.oneview_client.server_hardware.get_all() server_profile_template_list = g.oneview_client.\ server_profile_templates.get_all() # Build ResourceBlockCollection object and validates it cc = ResourceBlockCollection(server_hardware_list, server_profile_template_list) # Build redfish json json_str = cc.serialize() # Build response and returns return Response(response=json_str, status=status.HTTP_200_OK, mimetype="application/json") except Exception as e: # In case of error print exception and abort logging.exception('Unexpected error: {}'.format(e)) abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
def test_serialize_empty_result(self): with open('oneview_redfish_toolkit/mockups/redfish/' 'ResourceBlockCollectionEmpty.json') as f: expected_result = json.load(f) # Tests the serialize function result against empty list result resource_block_collection = ResourceBlockCollection() result = json.loads(resource_block_collection.serialize()) self.assertEqualMockup(expected_result, result)
def test_serialize(self): # Tests the serialize function result against known result try: resource_block_collection = ResourceBlockCollection( self.server_hardware_list, self.server_profile_template_list) except Exception as e: self.fail("Failed to instantiate ResourceBlockCollection class." " Error: {}".format(e)) try: result = json.loads(resource_block_collection.serialize()) except Exception as e: self.fail("Failed to serialize. Error: {}".format(e)) self.assertEqual(self.resource_block_collection_mockup, result)
def get_resource_block_collection(): """Get the Redfish ResourceBlock Collection. Return ResourceBlockCollection redfish JSON. Logs exception of any error and return Internal Server Error or Not Found. Returns: JSON: Redfish json with ResourceBlockCollection. """ # Gets all server hardware server_hardware_list = g.oneview_client.server_hardware.get_all() server_profile_template_list = g.oneview_client.\ server_profile_templates.get_all() drives_list = g.oneview_client.index_resources \ .get_all(category="drives", count=10000) volume_list = g.oneview_client.volumes.get_all() filter_volume_list = [volume for volume in volume_list if volume["isShareable"]] # Emptying volume list to suppress external storage changes for # current release. # In future, remove this line to enable external storage support filter_volume_list = [] # Build ResourceBlockCollection object and validates it cc = ResourceBlockCollection(server_hardware_list, server_profile_template_list, drives_list, filter_volume_list) return ResponseBuilder.success(cc)
def test_class_instantiation(self): # Tests if class is correctly instantiated and validated try: resource_block_collection = ResourceBlockCollection( self.server_hardware_list, self.server_profile_template_list) except Exception as e: self.fail("Failed to instantiate ResourceBlockCollection class." " Error: {}".format(e)) self.assertIsInstance(resource_block_collection, ResourceBlockCollection)
def get_resource_block_collection(): """Get the Redfish ResourceBlock Collection. Return ResourceBlockCollection redfish JSON. Logs exception of any error and return Internal Server Error or Not Found. Returns: JSON: Redfish json with ResourceBlockCollection. """ # Gets all server hardware server_hardware_list = g.oneview_client.server_hardware.get_all() server_profile_template_list = g.oneview_client.\ server_profile_templates.get_all() drives_list = g.oneview_client.index_resources \ .get_all(category="drives", count=10000) # Build ResourceBlockCollection object and validates it cc = ResourceBlockCollection(server_hardware_list, server_profile_template_list, drives_list) return ResponseBuilder.success(cc)