def test_get_ethernet_interface(self): with open('oneview_redfish_toolkit/mockups/redfish' '/ResourceBlockEthernetInterface.json') as f: expected_ethernet_interface = json.load(f) with open( 'oneview_redfish_toolkit/mockups/oneview/EthernetNetwork.json' ) as f: ethernet_network = json.load(f) spt_obj = ServerProfileTemplate(self.oneview_client, self.server_profile_template) self.oneview_client.server_profile_templates.get_by_id.return_value = \ spt_obj self.oneview_client.index_resources.get.return_value = \ ethernet_network response = self.client.get( "/redfish/v1/CompositionService/ResourceBlocks" "/1f0ca9ef-7f81-45e3-9d64-341b46cf87e0/EthernetInterfaces/1") result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(expected_ethernet_interface, result)
def test_get_spt_vlan_network_interface_collection(self): with open('oneview_redfish_toolkit/mockups/' 'redfish/VLanNetworkInterfaceCollectionSPT.json') as f: expected_vlan_network_interface_collection = json.load(f) spt_obj = ServerProfileTemplate(self.oneview_client, self.server_profile_template) self.oneview_client.server_profile_templates.get_by_id.return_value = \ spt_obj network_set_obj = NetworkSets(self.oneview_client, self.network_set_mockup) self.oneview_client.network_sets.get_by_uri.return_value = \ network_set_obj response = self.client.get( "/redfish/v1/CompositionService/ResourceBlocks" "/1f0ca9ef-7f81-45e3-9d64-341b46cf87e0/" "EthernetInterfaces/1/VLANs") result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(expected_vlan_network_interface_collection, result) self.oneview_client.server_profile_templates.get_by_id.assert_called_with( self.server_profile_template["uri"].split("/")[-1]) self.oneview_client.network_sets.get_by_uri.assert_called_with( self.network_set_mockup["uri"])
def test_get_spt_vlan_network_interface(self): spt_obj = ServerProfileTemplate(self.oneview_client, self.server_profile_template) self.oneview_client.server_profile_templates.get_by_id.return_value = \ spt_obj ethernet_obj = EthernetNetworks(self.oneview_client, self.ethernet_network_mockup) self.oneview_client.ethernet_networks.get_by_id.return_value = \ ethernet_obj response = self.client.get( "/redfish/v1/CompositionService/ResourceBlocks" "/1f0ca9ef-7f81-45e3-9d64-341b46cf87e0" "/EthernetInterfaces/1/VLANs/19638712-679d-4232-9743-c7cb6c7bf718") result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(self.expected_vlan_network_interface_spt, result) self.oneview_client.server_profile_templates.get_by_id.assert_called_with( self.server_profile_template["uri"].split("/")[-1]) self.oneview_client.ethernet_networks.get_by_id.assert_called_with( self.expected_vlan_network_interface_spt["Id"])
def test_get_zone_when_external_storage_attached(self): """Tests get a Zone when the zone uuid is only template id""" api_client = self.oneview_client with open('oneview_redfish_toolkit/mockups/redfish/' 'ZoneWithExternalStorage.json') as f: zone_with_external_storage_mockup = json.load(f) enclosure_obj = Enclosures(self.oneview_client, self.enclosure) api_client.enclosures.get_by_id.return_value = enclosure_obj spt_obj = ServerProfileTemplate(self.oneview_client, self.server_profile_template) api_client.server_profile_templates.get_by_id.return_value = \ spt_obj api_client.server_hardware.get_all.return_value = \ self.server_hardware_list api_client.connection.get.side_effect = [ self.drive_encl_assoc, self.drives ] api_client.volumes.get_all.return_value = \ self.volumes response = self.client.get( "/redfish/v1/CompositionService/ResourceZones/" + self.spt_id + "-" + self.enclosure["uuid"]) result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(zone_with_external_storage_mockup, result)
def server_profile_templates(self): """ Gets the ServerProfileTemplate API client. Returns: ServerProfileTemplate: """ return ServerProfileTemplate(self.__connection)
def test_get_zone_when_uuid_is_template_id_with_enclosure_id(self): """Tests get a Zone when the zone uuid is template id + enclosure id""" api_client = self.oneview_client with open( 'oneview_redfish_toolkit/mockups/redfish/Zone.json' ) as f: zone_mockup = json.load(f) enclosure_obj = Enclosures(self.oneview_client, self.enclosure) api_client.enclosures.get_by_id.return_value = enclosure_obj spt_obj = ServerProfileTemplate( self.oneview_client, self.server_profile_template) api_client.server_profile_templates.get_by_id.return_value = \ spt_obj api_client.server_hardware.get_all.return_value = \ self.server_hardware_list api_client.connection.get.side_effect = [ self.drive_encl_assoc, self.drives ] api_client.volumes.get_all.return_value = [] response = self.client.get( "/redfish/v1/CompositionService/ResourceZones/" + self.spt_id + "-" + self.enclosure["uuid"]) result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(zone_mockup, result) api_client.enclosures.get_by_id.assert_called_with( self.enclosure["uuid"]) api_client.server_profile_templates.get_by_id.assert_called_with( self.spt_id) api_client.connection.get.assert_has_calls( [ call("/rest/index/associations/resources?parenturi=" + self.enclosure["uri"] + "&category=drive-enclosures"), call('/rest/index/resources?category=drives&count=10000' '&filter="driveEnclosureUri:' '/rest/drive-enclosures/SN123100"') ] ) api_client.server_hardware.get_all.assert_called_with( filter=[ "locationUri='/rest/enclosures/0000000000A66101'", "serverHardwareTypeUri='" + self.server_profile_template["serverHardwareTypeUri"] + "'" ])
def test_get_zone_when_drive_enclosures_assoc_is_empty(self): """Tests get a Zone when drive enclosures by enclosure is empty""" api_client = self.oneview_client with open( 'oneview_redfish_toolkit/mockups/redfish/' 'ZoneWithoutDrivesAssignedYet.json' ) as f: zone_without_drives_mockup = json.load(f) enclosure_obj = Enclosures(self.oneview_client, self.enclosure) api_client.enclosures.get_by_id.return_value = enclosure_obj spt_obj = ServerProfileTemplate( self.oneview_client, self.server_profile_template) api_client.server_profile_templates.get_by_id.return_value = \ spt_obj drive_encl_by_encl = copy.copy(self.drive_encl_assoc) drive_encl_by_encl["members"] = [] api_client.connection.get.side_effect = [ drive_encl_by_encl, self.drives ] api_client.server_hardware.get_all.return_value = \ self.server_hardware_list api_client.volumes.get_all.return_value = [] response = self.client.get( "/redfish/v1/CompositionService/ResourceZones/" + self.spt_id + "-" + self.enclosure["uuid"]) result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(zone_without_drives_mockup, result) api_client.enclosures.get_by_id.assert_called_with( self.enclosure["uuid"]) api_client.server_profile_templates.get_by_id.assert_called_with( self.spt_id) api_client.connection.get.assert_has_calls([ call("/rest/index/associations/resources?parenturi=" + self.enclosure["uri"] + "&category=drive-enclosures") ]) api_client.server_hardware.get_all.assert_called_with( filter=[ "locationUri='/rest/enclosures/0000000000A66101'", "serverHardwareTypeUri='" + self.server_profile_template["serverHardwareTypeUri"] + "'" ])
def run_common_mock_to_server_profile_template(self): template_obj = ServerProfileTemplate(self.oneview_client, self.server_profile_template) self.oneview_client.server_profile_templates.get_by_id.side_effect = [ self.not_found_error, template_obj, self.not_found_error, self.not_found_error, self.not_found_error, template_obj, ]
def test_get_zone_when_uuid_is_only_template_id(self): """Tests get a Zone when the zone uuid is only template id""" api_client = self.oneview_client with open( 'oneview_redfish_toolkit/mockups/redfish/' 'ZoneWithoutDrives.json' ) as f: zone_without_drives_mockup = json.load(f) spt_obj = ServerProfileTemplate( self.oneview_client, self.server_profile_template) api_client.server_profile_templates.get_by_id.return_value = \ spt_obj api_client.server_hardware.get_all.return_value = \ self.server_hardware_list api_client.connection.get.side_effect = [ self.drive_encl_assoc, self.drives ] api_client.volumes.get_all.return_value = [] response = self.client.get( "/redfish/v1/CompositionService/ResourceZones/" + self.spt_id) result = json.loads(response.data.decode("utf-8")) self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(zone_without_drives_mockup, result) api_client.enclosures.get_by_id.assert_not_called() api_client.server_profile_templates.get_by_id.assert_called_with( self.spt_id) api_client.connection.get.assert_not_called() api_client.server_hardware.get_all.assert_called_with( filter=[ "serverGroupUri='" + self.server_profile_template["enclosureGroupUri"] + "'", "serverHardwareTypeUri='" + self.server_profile_template["serverHardwareTypeUri"] + "'" ])
def test_get_spt_vlan_network_interface_connection_not_found(self): spt_obj = ServerProfileTemplate(self.oneview_client, self.server_profile_template) self.oneview_client.server_profile_templates.get_by_id.return_value = \ spt_obj connection_id = "999" response = self.client.get( "/redfish/v1/CompositionService/ResourceBlocks" "/1f0ca9ef-7f81-45e3-9d64-341b46cf87e0" "/EthernetInterfaces/" + connection_id + "/VLANs/19638712-679d-4232-9743-c7cb6c7bf718") self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) self.assertEqual("application/json", response.mimetype) self.oneview_client.server_profile_templates.get_by_id.assert_called_with( self.server_profile_template["uri"].split("/")[-1]) self.oneview_client.ethernet_networks.get_by_id.assert_not_called()
def test_get_spt_vlan_collection_not_found(self): spt_obj = ServerProfileTemplate(self.oneview_client, self.server_profile_template) self.oneview_client.server_profile_templates.get_by_id.return_value = \ spt_obj self.oneview_client.network_sets.get_by_uri.side_effect = \ self.resource_not_found response = self.client.get( "/redfish/v1/CompositionService/ResourceBlocks" "/1f0ca9ef-7f81-45e3-9d64-341b46cf87e0" "/EthernetInterfaces/1/VLANs") self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) self.assertEqual("application/json", response.mimetype) self.oneview_client.server_profile_templates.get_by_id.assert_called_with( self.server_profile_template["uri"].split("/")[-1]) self.oneview_client.network_sets.get_by_uri.assert_called_with( self.network_set_mockup["uri"])
def test_create_system_when_has_storage_but_not_valid_controller(self): """Tests when the Server Profile Template has not a valid storage controller. This test should return a http 403 with a error message. The case is: the server profile template associated with the request has not a valid local storage controller configured, but the request has storage resource blocks to compose the system """ self.run_common_mock_to_server_hardware() template_without_controller = copy.deepcopy( self.server_profile_template) template_without_controller["localStorage"]["controllers"] = [] spt_without_controller_obj = ServerProfileTemplate( self.oneview_client, template_without_controller) self.oneview_client.server_profile_templates.get_by_id.side_effect = [ self.not_found_error, spt_without_controller_obj, self.not_found_error, self.not_found_error, spt_without_controller_obj ] self.run_common_mock_to_drives() try: response = self.client.post("/redfish/v1/Systems/", data=json.dumps( self.data_to_create_system), content_type='application/json') except OneViewRedfishException: self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) self.assertIn( "The Server Profile Template should have a valid " "storage controller to use the Storage Resource " "Blocks passed", response.data.decode()) self.assert_common_calls()
def server_profile_templates(self): if not self.__server_profile_templates: self.__server_profile_templates = ServerProfileTemplate( self.__connection) return self.__server_profile_templates
def test_create_system_when_request_content_has_not_storage( self, _, power_state): """Tests create a redfish System without Storage. This test should works well. This case is when we are creating a System without Storage Resource Blocks, but the Server Profile Template related has a local storage controller configured properly """ with open('oneview_redfish_toolkit/mockups/redfish/' 'PostToComposeSystemWithoutStorage.json') as f: data_to_send = json.load(f) """ with open( 'oneview_redfish_toolkit/mockups/oneview/' 'ServerProfileBuiltFromZoneWithoutStorageToCreateASystem.json' ) as f: expected_server_profile_built = json.load(f) """ with open('oneview_redfish_toolkit/mockups/oneview/' 'ServerProfileTemplates.json') as f: list_spt = json.load(f) spt = list_spt[1] # without local storage controller configured spt_id = spt["uri"].split("/")[-1] task = { "associatedResource": { "resourceUri": self.server_profile["uri"] }, "uri": "/rest/tasks/123456" } serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) self.oneview_client.server_hardware.get_by_id.side_effect = [ serverhw_obj, self.not_found_error, serverhw_obj, # for multiple oneview (power update status) serverhw_obj ] power_state.return_value = None template_obj = ServerProfileTemplate(self.oneview_client, spt) self.oneview_client.server_profile_templates.get_by_id.side_effect = [ self.not_found_error, template_obj, template_obj, ] self.oneview_client.index_resources.get.side_effect = [ self.not_found_error, self.not_found_error, ] self.run_common_mock_to_volumes() self.oneview_client.connection.post.return_value = (task, None) response = self.client.post("/redfish/v1/Systems/", data=json.dumps(data_to_send), content_type='application/json') self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertIn("/redfish/v1/Systems/" + self.server_profile["uuid"], response.headers["Location"]) self.oneview_client.server_hardware.get_by_id.assert_has_calls([ call(self.sh_id), call(spt_id), ]) self.oneview_client.server_profile_templates.get_by_id.assert_has_calls( [call(self.sh_id), call(spt_id), call(spt_id)]) self.oneview_client.index_resources.get.assert_has_calls([ call('/rest/drives/' + self.sh_id), call('/rest/drives/' + spt_id), ])
def test_create_system_when_has_not_storage_and_controller( self, _, power_state): """Tests create a System without Storage but with Storage Controller. This test should works well. This case is when we are creating a System without Storage Resource Blocks and the Server Profile Template related has not a local storage controller configured properly """ task = { "associatedResource": { "resourceUri": self.server_profile["uri"] }, "uri": "/rest/tasks/123456" } serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) self.oneview_client.server_hardware.get_by_id.side_effect = [ serverhw_obj, self.not_found_error, self.not_found_error, self.not_found_error, self.not_found_error, serverhw_obj, # for multiple oneview (power update status) serverhw_obj # Get for multiple OneView support ] power_state.return_value = None template_without_controller = copy.deepcopy( self.server_profile_template) template_without_controller["localStorage"]["controllers"] = [] template_obj = ServerProfileTemplate(self.oneview_client, template_without_controller) self.oneview_client.server_profile_templates.get_by_id.side_effect = [ self.not_found_error, template_obj, self.not_found_error, self.not_found_error, self.not_found_error, template_obj ] self.oneview_client.index_resources.get.side_effect = [ self.not_found_error, self.not_found_error, self.not_found_error, self.not_found_error, self.not_found_error, ] self.run_common_mock_to_volumes() storage_pools_obj = StoragePools( self.oneview_client, {"storageSystemUri": "/rest/storage-systems/TXQ1000307"}) self.oneview_client.storage_pools.get.return_value = storage_pools_obj self.oneview_client.connection.post.return_value = (task, None) response = self.client.post("/redfish/v1/Systems/", data=json.dumps( self.data_to_create_system), content_type='application/json') self.assertEqual(status.HTTP_201_CREATED, response.status_code) self.assertEqual("application/json", response.mimetype) # self.assertIn( # "/redfish/v1/Systems/" + self.server_profile["uuid"], # response.headers["Location"] # ) self.assert_common_calls()
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' self._resource.get_all(start=2, count=500, filter=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=query_filter, sort=sort) @mock.patch.object(ResourceClient, 'get') def test_get_by_id(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" self._resource.get(template_id) mock_get.assert_called_once_with(id_or_uri=template_id) @mock.patch.object(ResourceClient, 'get_by') def test_get_by_property(self, mock_get_by): template_property = "name" template_name = "BL460c Gen8 1" self._resource.get_by(template_property, template_name) mock_get_by.assert_called_once_with(template_property, template_name) @mock.patch.object(ResourceClient, 'get_by_name') def test_get_by_name(self, mock_get_by_name): template_name = "BL460c Gen8 1" self._resource.get_by_name(template_name) mock_get_by_name.assert_called_once_with(template_name) @mock.patch.object(ResourceClient, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") expected_template = template.copy() expected_template["type"] = "ServerProfileTemplateV1" self._resource.create(resource=template, timeout=TIMEOUT) mock_create.assert_called_once_with(resource=expected_template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'update') def test_update(self, mock_update): uri = "/rest/server-profile-templates/4ff2327f-7638-4b66-ad9d-283d4940a4ae" template = dict(name="BL460c Gen8 1", macType="Virtual") expected_template = template.copy() expected_template["type"] = "ServerProfileTemplateV1" self._resource.update(resource=template, id_or_uri=uri) mock_update.assert_called_once_with(resource=expected_template, uri=uri) @mock.patch.object(ResourceClient, 'delete') def test_delete(self, mock_delete): template = dict(name="BL460c Gen8 1") self._resource.delete(resource=template, timeout=TIMEOUT) mock_delete.assert_called_once_with(resource=template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'get') def test_get_new_profile(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" expected_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6/new-profile' self._resource.get_new_profile(id_or_uri=template_id) mock_get.assert_called_once_with(id_or_uri=expected_uri)
def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) self.uri = "/rest/server-profile-templates/test" self._resource.data = {"uri": self.uri}
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) self.uri = "/rest/server-profile-templates/test" self._resource.data = {"uri": self.uri} @mock.patch.object(ResourceHelper, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' scope_uris = 'rest/scopes/cd237b60-09e2-45c4-829e-082e318a6d2a' self._resource.get_all( start=2, count=500, filter=query_filter, sort=sort, scope_uris=scope_uris) mock_get_all.assert_called_once_with( start=2, count=500, filter=query_filter, sort=sort, scope_uris=scope_uris) @mock.patch.object(ResourceHelper, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") self._resource.create(template, timeout=TIMEOUT) mock_create.assert_called_once_with( template, None, -1, force=True ) @mock.patch.object(Resource, 'ensure_resource_data') @mock.patch.object(ResourceHelper, 'update') def test_update(self, mock_update, mock_ensure_client): template = dict(name="BL460c Gen8 1", macType="Virtual") self._resource.update(template) template["uri"] = self.uri mock_update.assert_called_once_with(template, self.uri, True, -1) @mock.patch.object(ResourceHelper, 'delete') def test_delete(self, mock_delete): self._resource.delete(timeout=TIMEOUT) mock_delete.assert_called_once_with(self.uri, timeout=TIMEOUT, custom_headers=None, force=False) @mock.patch.object(ResourceHelper, 'do_get') def test_get_new_profile(self, mock_get): expected_uri = '{}/new-profile'.format(self.uri) self._resource.get_new_profile() mock_get.assert_called_once_with(expected_uri) @mock.patch.object(ResourceHelper, 'do_get') def test_get_transformation(self, mock_get): enclosure_group_uri = "/rest/enclosure-groups/bb1fbca0-2289-4b75-adbb-0564cdc4995d" server_hardware_type_uri = "/rest/server-hardware-types/34A3A0B2-66C7-4657-995E-60895C1F8F96" transformation_path = self._resource.TRANSFORMATION_PATH.format(**locals()) expected_uri = self.uri + transformation_path self._resource.get_transformation(enclosure_group_uri=enclosure_group_uri, server_hardware_type_uri=server_hardware_type_uri) mock_get.assert_called_once_with(expected_uri) @mock.patch.object(ResourceHelper, 'do_get') def test_get_available_networks(self, mock_get): uri = '/rest/server-profile-templates/available-networks?profileTemplateUri={}'.format(self.uri) self._resource.get_available_networks(profileTemplateUri=self.uri) mock_get.assert_called_once_with(uri)
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' self._resource.get_all(start=2, count=500, filter=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=query_filter, sort=sort) @mock.patch.object(ResourceClient, 'get') def test_get_by_id(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" self._resource.get(template_id) mock_get.assert_called_once_with(id_or_uri=template_id) @mock.patch.object(ResourceClient, 'get_by') def test_get_by_property(self, mock_get_by): template_property = "name" template_name = "BL460c Gen8 1" self._resource.get_by(template_property, template_name) mock_get_by.assert_called_once_with(template_property, template_name) @mock.patch.object(ResourceClient, 'get_by_name') def test_get_by_name(self, mock_get_by_name): template_name = "BL460c Gen8 1" self._resource.get_by_name(template_name) mock_get_by_name.assert_called_once_with(template_name) @mock.patch.object(ResourceClient, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") self._resource.create(resource=template, timeout=TIMEOUT) mock_create.assert_called_once_with( resource=template, timeout=TIMEOUT, default_values=ServerProfileTemplate.DEFAULT_VALUES) @mock.patch.object(ResourceClient, 'update') def test_update(self, mock_update): uri = "/rest/server-profile-templates/4ff2327f-7638-4b66-ad9d-283d4940a4ae" template = dict(name="BL460c Gen8 1", macType="Virtual") self._resource.update(resource=template, id_or_uri=uri) mock_update.assert_called_once_with( resource=template, uri=uri, default_values=ServerProfileTemplate.DEFAULT_VALUES) @mock.patch.object(ResourceClient, 'delete') def test_delete(self, mock_delete): template = dict(name="BL460c Gen8 1") self._resource.delete(resource=template, timeout=TIMEOUT) mock_delete.assert_called_once_with(resource=template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'get') def test_get_new_profile(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" expected_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6/new-profile' self._resource.get_new_profile(id_or_uri=template_id) mock_get.assert_called_once_with(id_or_uri=expected_uri) @mock.patch.object(ResourceClient, 'get') def test_get_transformation(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" enclosure_group_uri = "/rest/enclosure-groups/bb1fbca0-2289-4b75-adbb-0564cdc4995d" server_hardware_type_uri = "/rest/server-hardware-types/34A3A0B2-66C7-4657-995E-60895C1F8F96" transformation_path = self._resource.TRANSFORMATION_PATH.format( **locals()) template_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6' expected_uri = template_uri + transformation_path self._resource.get_transformation( id_or_uri=template_id, enclosure_group_uri=enclosure_group_uri, server_hardware_type_uri=server_hardware_type_uri) mock_get.assert_called_once_with(id_or_uri=expected_uri)
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' self._resource.get_all(start=2, count=500, filter=query_filter, sort=sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=query_filter, sort=sort) @mock.patch.object(ResourceClient, 'get') def test_get_by_id(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" self._resource.get(template_id) mock_get.assert_called_once_with(id_or_uri=template_id) @mock.patch.object(ResourceClient, 'get_by') def test_get_by_property(self, mock_get_by): template_property = "name" template_name = "BL460c Gen8 1" self._resource.get_by(template_property, template_name) mock_get_by.assert_called_once_with(template_property, template_name) @mock.patch.object(ResourceClient, 'get_by_name') def test_get_by_name(self, mock_get_by_name): template_name = "BL460c Gen8 1" self._resource.get_by_name(template_name) mock_get_by_name.assert_called_once_with(template_name) @mock.patch.object(ResourceClient, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") self._resource.create(resource=template, timeout=TIMEOUT) mock_create.assert_called_once_with( resource=template, timeout=TIMEOUT, default_values=ServerProfileTemplate.DEFAULT_VALUES ) @mock.patch.object(ResourceClient, 'update') def test_update(self, mock_update): uri = "/rest/server-profile-templates/4ff2327f-7638-4b66-ad9d-283d4940a4ae" template = dict(name="BL460c Gen8 1", macType="Virtual") self._resource.update(resource=template, id_or_uri=uri) mock_update.assert_called_once_with( resource=template, uri=uri, default_values=ServerProfileTemplate.DEFAULT_VALUES ) @mock.patch.object(ResourceClient, 'delete') def test_delete(self, mock_delete): template = dict(name="BL460c Gen8 1") self._resource.delete(resource=template, timeout=TIMEOUT) mock_delete.assert_called_once_with(resource=template, timeout=TIMEOUT) @mock.patch.object(ResourceClient, 'get') def test_get_new_profile(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" expected_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6/new-profile' self._resource.get_new_profile(id_or_uri=template_id) mock_get.assert_called_once_with(id_or_uri=expected_uri) @mock.patch.object(ResourceClient, 'get') def test_get_transformation(self, mock_get): template_id = "6fee02f3-b7c7-42bd-a528-04341e16bad6" enclosure_group_uri = "/rest/enclosure-groups/bb1fbca0-2289-4b75-adbb-0564cdc4995d" server_hardware_type_uri = "/rest/server-hardware-types/34A3A0B2-66C7-4657-995E-60895C1F8F96" transformation_path = self._resource.TRANSFORMATION_PATH.format(**locals()) template_uri = '/rest/server-profile-templates/6fee02f3-b7c7-42bd-a528-04341e16bad6' expected_uri = template_uri + transformation_path self._resource.get_transformation(id_or_uri=template_id, enclosure_group_uri=enclosure_group_uri, server_hardware_type_uri=server_hardware_type_uri) mock_get.assert_called_once_with(id_or_uri=expected_uri)
def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection)
class ServerProfileTemplateTest(TestCase): def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) self.uri = "/rest/server-profile-templates/test" self._resource.data = {"uri": self.uri} @mock.patch.object(ResourceHelper, 'get_all') def test_get_all(self, mock_get_all): query_filter = 'name=TestName' sort = 'name:ascending' scope_uris = 'rest/scopes/cd237b60-09e2-45c4-829e-082e318a6d2a' self._resource.get_all( start=2, count=500, filter=query_filter, sort=sort, scope_uris=scope_uris) mock_get_all.assert_called_once_with( start=2, count=500, filter=query_filter, sort=sort, scope_uris=scope_uris) @mock.patch.object(ResourceHelper, 'create') def test_create(self, mock_create): template = dict(name="BL460c Gen8 1") self._resource.create(template, timeout=TIMEOUT) mock_create.assert_called_once_with( template, None, -1, force=True ) @mock.patch.object(Resource, 'ensure_resource_data') @mock.patch.object(ResourceHelper, 'update') def test_update(self, mock_update, mock_ensure_client): template = dict(name="BL460c Gen8 1", macType="Virtual") self._resource.update(template) template["uri"] = self.uri mock_update.assert_called_once_with(template, self.uri, True, -1) @mock.patch.object(ResourceHelper, 'delete') def test_delete(self, mock_delete): self._resource.delete(timeout=TIMEOUT) mock_delete.assert_called_once_with(self.uri, timeout=TIMEOUT, custom_headers=None, force=False) @mock.patch.object(ResourceHelper, 'do_get') def test_get_new_profile(self, mock_get): expected_uri = '{}/new-profile'.format(self.uri) self._resource.get_new_profile() mock_get.assert_called_once_with(expected_uri) @mock.patch.object(ResourceHelper, 'do_get') def test_get_transformation(self, mock_get): enclosure_group_uri = "/rest/enclosure-groups/bb1fbca0-2289-4b75-adbb-0564cdc4995d" server_hardware_type_uri = "/rest/server-hardware-types/34A3A0B2-66C7-4657-995E-60895C1F8F96" transformation_path = self._resource.TRANSFORMATION_PATH.format(**locals()) expected_uri = self.uri + transformation_path self._resource.get_transformation(enclosure_group_uri=enclosure_group_uri, server_hardware_type_uri=server_hardware_type_uri) mock_get.assert_called_once_with(expected_uri) @mock.patch.object(ResourceHelper, 'do_get') def test_get_available_networks(self, mock_get): uri = '/rest/server-profile-templates/available-networks?profileTemplateUri={}'.format(self.uri) self._resource.get_available_networks(profileTemplateUri=self.uri) mock_get.assert_called_once_with(uri)
def test_get_computer_system_sp_with_invalid_labels( self, get_map_appliances, get_map_resources): """Tests ComputerSystem with a known SP with invalid labels""" server_profile = copy.deepcopy(self.server_profile) server_profile["localStorage"]["sasLogicalJBODs"].pop(0) invalid_label = { "uri": "/rest/labels/2", "name": "invalid label abc123" } label_for_sp = copy.deepcopy(self.label_for_server_profile) label_for_sp["labels"].extend(invalid_label) server_profile_template = copy.deepcopy(self.server_profile_template) server_profile_template["uri"] = self.spt_uri # Create mock response resource_id = "/rest/server-hardware-types/" \ "FE50A6FE-B1AC-4E42-8D40-B73CA8CC0CD2" get_map_resources.return_value = OrderedDict({ resource_id: "10.0.0.1", }) get_map_appliances.return_value = self.map_appliance profile_obj = ServerProfiles(self.oneview_client, server_profile) serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) template_obj = ServerProfileTemplate(self.oneview_client, server_profile_template) server_hardware_type_obj = ServerHardwareTypes( self.oneview_client, self.server_hardware_types) self.oneview_client.server_profiles.get_by_id.return_value = profile_obj self.oneview_client.server_hardware.get_by_uri.return_value = \ serverhw_obj self.oneview_client.server_hardware_types.get_by_uri.return_value = \ server_hardware_type_obj self.oneview_client.sas_logical_jbods.get_drives.return_value = \ [self.drives[4]] self.oneview_client.labels.get_by_resource.return_value = label_for_sp self.oneview_client.server_profile_templates.get_by_id.return_value = \ template_obj self.oneview_client.appliance_node_information.get_version.return_value = \ self.appliance_info # Get ComputerSystem response = self.client.get( "/redfish/v1/Systems/b425802b-a6a5-4941-8885-aab68dfa2ee2") # Gets json from response result = json.loads(response.data.decode("utf-8")) # Tests response self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(self.computer_system_mockup, result) self.assertEqual("{}{}".format("W/", self.server_profile["eTag"]), response.headers["ETag"]) self.oneview_client.server_profiles.get_by_id.assert_called_with( "b425802b-a6a5-4941-8885-aab68dfa2ee2") self.oneview_client.server_hardware.get_by_uri.assert_called_with( "/rest/server-hardware/30303437-3034-4D32-3230-313130304752") self.oneview_client.server_hardware_types.get_by_uri.assert_called_with( "/rest/server-hardware-types/FE50A6FE-B1AC-4E42-8D40-B73CA8CC0CD2") self.oneview_client.sas_logical_jbods.get_drives.assert_called_with( "/rest/sas-logical-jbods/9e83a03d-7a84-4f0d-a8d7-bd05a30c3175") self.oneview_client.labels.get_by_resource.assert_called_with( "/rest/server-profiles/b425802b-a6a5-4941-8885-aab68dfa2ee2") self.oneview_client.server_profile_templates.get_by_id.assert_called_with( "61c3a463-1355-4c68-a4e3-4f08c322af1b")
def setUp(self): host = '127.0.0.1' http_connection = connection(host) self._resource = ServerProfileTemplate(http_connection) self.uri = "/rest/server-profile-templates/test" self._resource.data = {"uri": self.uri}