def run_common_mock_to_server_hardware(self): ov_client = self.oneview_client serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) ov_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 # for multiple oneview (create profile) ]
def test_get_blade_chassis_with_computer_system_cached(self, get_map_appliances, get_map_resources): """"Tests BladeChassis with a known Server Hardware""" serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) get_map_resources.return_value = OrderedDict({ "30303437-3034-4D32-3230-313133364752": "10.0.0.1", }) get_map_appliances.return_value = self.map_appliance self.oneview_client.index_resources.get_all.return_value = \ [{"category": "server-hardware"}] self.oneview_client.server_hardware.get_by_id.return_value = \ serverhw_obj self.oneview_client.appliance_node_information.get_version.return_value = \ self.appliance_info uri = "/redfish/v1/Chassis/30303437-3034-4D32-3230-313133364752" uuid = uri.split('/')[-1] # Get BladeChassis response = self.client.get(uri) result = json.loads(response.data.decode("utf-8")) # Tests response self.assertEqual(status.HTTP_200_OK, response.status_code) # Get cached BladeChassis response = self.client.get(uri) 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.blade_chassis_mockup, result) self.assertEqual( "{}{}".format("W/", self.server_hardware["eTag"]), response.headers["ETag"]) # Check for cached calls self.oneview_client.index_resources.get_all.assert_called_once_with( filter='uuid=' + uuid ) assert self.oneview_client.server_hardware.get.has_calls( [call(uuid), call(uuid)] ) self.assertTrue(category_resource.get_category_by_resource_id(uuid))
def test_get_processor(self): serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) self.oneview_client.server_hardware.get_by_id.return_value = \ serverhw_obj response = self.client.get( "/redfish/v1/CompositionService/ResourceBlocks" "/30303437-3034-4D32-3230-313133364752/Systems/1/Processors/") 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_processor_collection, result)
def test_get_blade_chassis_without_computer_system(self, get_map_appliances, get_map_resources): """"Tests BladeChassis with a known Server Hardware""" server_hardware = copy.deepcopy(self.server_hardware) server_hardware["serverProfileUri"] = None serverhw_obj = ServerHardware(self.oneview_client, server_hardware) get_map_resources.return_value = OrderedDict({ "30303437-3034-4D32-3230-313133364752": "10.0.0.1", }) get_map_appliances.return_value = self.map_appliance self.oneview_client.index_resources.get_all.return_value = \ [{"category": "server-hardware"}] self.oneview_client.server_hardware.get_by_id.return_value = serverhw_obj self.oneview_client.appliance_node_information.get_version.return_value = \ self.appliance_info response = self.client.get( "/redfish/v1/Chassis/30303437-3034-4D32-3230-313133364752" ) result = json.loads(response.data.decode("utf-8")) expected_blade_result = copy.deepcopy(self.blade_chassis_mockup) expected_blade_result["Links"]["ComputerSystems"] = [] self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) self.assertEqualMockup(expected_blade_result, result) self.assertEqual( "{}{}".format("W/", server_hardware["eTag"]), response.headers["ETag"]) self.oneview_client.server_hardware.get_by_id \ .assert_called_with(server_hardware["uuid"]) server_hardware["serverProfileUri"] = "" response = self.client.get( "/redfish/v1/Chassis/30303437-3034-4D32-3230-313133364752" ) result = json.loads(response.data.decode("utf-8")) self.assertEqualMockup(expected_blade_result, result)
def test_all_computer_system_states(self, get_map_appliances, get_map_resources): expected_cs = copy.deepcopy(self.computer_system_mockup) server_profile = copy.deepcopy(self.server_profile) server_profile["localStorage"]["sasLogicalJBODs"].pop(0) for oneview_status, redfish_status in status_mapping.\ SERVER_PROFILE_STATE_TO_REDFISH_STATE.items(): server_profile["state"] = oneview_status expected_cs["Status"]["State"] = redfish_status 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) 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 = \ self.label_for_server_profile self.oneview_client.appliance_node_information.get_version.return_value = \ self.appliance_info response = self.client.get( "/redfish/v1/Systems/b425802b-a6a5-4941-8885-aab68dfa2ee2") 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_cs, result)
def test_get_network_interface_invalid_id(self): """Tests NetworkInterfaceCollection""" profile_obj = ServerProfiles(self.oneview_client, self.server_profile) serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) self.oneview_client.\ server_profiles.get_by_id.return_value = profile_obj self.oneview_client.server_hardware.get_by_uri.return_value = \ serverhw_obj response = self.client.get( "/redfish/v1/Systems/b425802b-a6a5-4941-8885-aab68dfa2ee2/" "NetworkInterfaces/invalid_id") self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) self.assertEqual("application/json", response.mimetype) self.oneview_client.server_profiles.get_by_id.assert_not_called() self.oneview_client.server_hardware.get_by_uri.assert_not_called()
def test_get_network_interface_invalid_id(self): """Tests NetworkAdapter""" # Loading server_hardware mockup value with open('oneview_redfish_toolkit/mockups/oneview/ServerHardware.json' ) as f: server_hardware = json.load(f) # Create mock response serverhw_obj = ServerHardware(self.oneview_client, server_hardware) self.oneview_client.server_hardware.get_by_id.return_value = serverhw_obj # Get NetworkAdapter response = self.client.get( "/redfish/v1/Chassis/30303437-3034-4D32-3230-313133364752/" "NetworkAdapters/invalid_id") # Tests response self.assertEqual(status.HTTP_404_NOT_FOUND, response.status_code) self.assertEqual("application/json", response.mimetype)
def test_remove_computer_system(self, sp_delete, power_state): """Tests delete computer system""" profile_obj = ServerProfiles( self.oneview_client, {'serverHardwareUri': '/rest/server-hardware/uuid_1'}) sp_delete.return_value = True self.oneview_client.server_profiles.get_by_id.return_value = profile_obj ServerProfiles.delete.return_value = sp_delete.return_value serverhw_obj = ServerHardware(self.oneview_client, {"uri": "/rest/server-hardware/uuid_1"}) response = self.client.delete("/redfish/v1/Systems/" "e7f93fa2-0cb4-11e8-9060-e839359bc36b") self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code) self.oneview_client.server_hardware.get_by_uri.return_value = serverhw_obj ServerHardware.update_power_state\ .has_calls({ 'powerControl': 'PressAndHold', 'powerState': 'Off' }, )
def test_change_power_state(self, power_state): """Tests change SH power state with valid power values Valid Power Values: - On - ForceOff - GracefulShutdown - GracefulRestart - ForceRestart - PushPowerButton """ profile_obj = ServerProfiles(self.oneview_client, self.server_profile) serverhw_obj = ServerHardware(self.oneview_client, self.server_hardware) power_state.return_value = {"status": "OK"} self.oneview_client.\ server_profiles.get_by_id.return_value = profile_obj self.oneview_client.server_hardware.get_by_uri.return_value = \ serverhw_obj ServerHardware.update_power_state.return_value = \ power_state.return_value reset_types = [ "On", "ForceOff", "GracefulShutdown", "GracefulRestart", "ForceRestart", "PushPowerButton" ] for reset_type in reset_types: response = self.client.post( "/redfish/v1/Systems/b425802b-a6a5-4941-8885-aab68dfa2ee2" "/Actions/ComputerSystem.Reset", data=json.dumps(dict(ResetType=reset_type)), content_type='application/json') # Tests response self.assertEqual(status.HTTP_200_OK, response.status_code) self.assertEqual("application/json", response.mimetype) json_str = response.data.decode("utf-8") self.assertEqual(json_str, '{"ResetType": "%s"}' % reset_type) self.oneview_client.server_profiles.get_by_id.assert_called_with( "b425802b-a6a5-4941-8885-aab68dfa2ee2") self.oneview_client.server_hardware.get_by_uri.has_calls([ call("/rest/server-hardware/" "30303437-3034-4D32-3230-313130304752"), call("30303437-3034-4D32-3230-313130304752") ]) serverhw_obj = ServerHardware(self.oneview_client, { 'uri': '/rest/server-hardware/30303437-3034-4D32-3230-313130304752' }) self.oneview_client.server_hardware.get_by_uri = serverhw_obj ServerHardware.update_power_state \ .has_calls({ 'powerControl': 'MomentaryPress', 'powerState': 'Off' })
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 setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection) self.uri = "/rest/server-hardware/1224242424" self._server_hardware.data = {"uri": self.uri}
def server_hardware(self): if not self.__server_hardware: self.__server_hardware = ServerHardware(self.__connection) return self.__server_hardware
class ServerHardwareTest(TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection) @mock.patch.object(ResourceClient, 'get_utilization') def test_get_utilization_with_all_args(self, mock_get_utilization): self._server_hardware.get_utilization('09USE7335NW3', fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') mock_get_utilization.assert_called_once_with('09USE7335NW3', fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') @mock.patch.object(ResourceClient, 'get_utilization') def test_get_utilization_with_defaults(self, mock_get): self._server_hardware.get_utilization('09USE7335NW3') mock_get.assert_called_once_with( '09USE7335NW3', fields=None, filter=None, refresh=False, view=None) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' self._server_hardware.get_all(2, 500, filter, sort) mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_called_once_with_default_values(self, mock_get_all): self._server_hardware.get_all() mock_get_all.assert_called_once_with(0, -1, filter='', sort='') @mock.patch.object(ResourceClient, 'get_by') def test_get_by_called_once(self, mock_get_by): self._server_hardware.get_by('name', 'OneViewSDK-Test-Rack-Server') mock_get_by.assert_called_once_with( 'name', 'OneViewSDK-Test-Rack-Server') @mock.patch.object(ResourceClient, 'create') def test_add_called_once(self, mock_create): information = { "licensingIntent": "OneView", "configurationState": "Managed" } mock_create.return_value = {} self._server_hardware.add(information) mock_create.assert_called_once_with(information.copy(), timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_called_once(self, mock_get): self._server_hardware.get('3518be0e-17c1-4189-8f81-83f3724f6155') mock_get.assert_called_once_with( '3518be0e-17c1-4189-8f81-83f3724f6155') @mock.patch.object(ResourceClient, 'get') def test_get_with_uri_called_once(self, mock_get): uri = '/rest/server-hardware/3518be0e-17c1-4189-8f81-83f3724f6155' self._server_hardware.get(uri) mock_get.assert_called_once_with(uri) @mock.patch.object(ResourceClient, 'delete') def test_remove_called_once(self, mock_delete): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.remove(id, force=False) mock_delete.assert_called_once_with(id, force=False, timeout=-1) @mock.patch.object(ResourceClient, 'delete') def test_remove_called_once_with_force(self, mock_delete): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.remove(id, force=True) mock_delete.assert_called_once_with(id, force=True, timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_bios_by_uri(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/bios' self._server_hardware.get_bios(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_bios_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/bios' self._server_hardware.get_bios(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_environmental_configuration_by_uri(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' self._server_hardware.get_environmental_configuration( uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_environmental_configuration_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' self._server_hardware.get_environmental_configuration( id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'update') def test_update_environmental_configuration_by_uri(self, mock_update): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' configuration = {"calibratedMaxPower": 2500} configuration_rest_call = configuration.copy() self._server_hardware.update_environmental_configuration( configuration, uri_server_hardware, timeout=-1) mock_update.assert_called_once_with( configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_update_environmental_configuration_by_id(self, mock_update): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' configuration = {"calibratedMaxPower": 2500} configuration_rest_call = configuration.copy() self._server_hardware.update_environmental_configuration( configuration, id_server_hardware, timeout=-1) mock_update.assert_called_once_with( configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_ilo_sso_url_by_url(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/iloSsoUrl' self._server_hardware.get_ilo_sso_url(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_ilo_sso_url_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/iloSsoUrl' self._server_hardware.get_ilo_sso_url(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_java_remote_console_by_url(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/javaRemoteConsoleUrl' self._server_hardware.get_java_remote_console_url(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_java_remote_console_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/javaRemoteConsoleUrl' self._server_hardware.get_java_remote_console_url(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'update') def test_refresh_state_by_uri(self, mock_update): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/refreshState' configuration = {"refreshState": "RefreshPending"} configuration_rest_call = configuration.copy() self._server_hardware.refresh_state( configuration, uri_server_hardware, timeout=-1) mock_update.assert_called_once_with( configuration_rest_call, uri=uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_refresh_state_by_id(self, mock_update): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/refreshState' configuration = {"refreshState": "RefreshPending"} configuration_rest_call = configuration.copy() self._server_hardware.refresh_state( configuration, id_server_hardware, timeout=-1) mock_update.assert_called_once_with( configuration_rest_call, uri=uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_power_state_by_uri(self, mock_update): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/powerState' configuration = { "powerState": "Off", "powerControl": "MomentaryPress" } configuration_rest_call = configuration.copy() self._server_hardware.update_power_state( configuration, uri_server_hardware) mock_update.assert_called_once_with( configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_power_state_by_id(self, mock_update): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/powerState' configuration = { "powerState": "Off", "powerControl": "MomentaryPress" } configuration_rest_call = configuration.copy() self._server_hardware.update_power_state( configuration, id_server_hardware, -1) mock_update.assert_called_once_with( configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_remote_console_url_by_url(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/remoteConsoleUrl' self._server_hardware.get_remote_console_url(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_remote_console_url_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/remoteConsoleUrl' self._server_hardware.get_remote_console_url(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'update_with_zero_body') def test_update_mp_firware_version_called_once(self, mock_get): id_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.update_mp_firware_version(id_server_hardware) mock_get.assert_called_once_with('/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/mpFirmwareVersion', -1) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_firmwares_with_defaults(self, mock_get): self._server_hardware.get_all_firmwares() mock_get.assert_called_once_with(0, -1, '', '', '', '', '', '/rest/server-hardware/*/firmware') @mock.patch.object(ResourceClient, 'get_all') def test_get_all_firmwares_with_all_arguments(self, mock_get): self._server_hardware.get_all_firmwares("name='name'", 2, 5, 'query', 'sort') mock_get.assert_called_once_with(2, 5, "name='name'", 'query', 'sort', '', '', '/rest/server-hardware/*/firmware') @mock.patch.object(ResourceClient, 'get') def test_get_firmware_by_id(self, mock_get): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.get_firmware(id) mock_get.assert_called_once_with('/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/firmware') @mock.patch.object(ResourceClient, 'get') def test_get_firmware_by_uri(self, mock_get): uri = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.get_firmware(uri) mock_get.assert_called_once_with('/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/firmware') @mock.patch.object(ResourceClient, 'patch') def test_patch_called_once(self, mock_patch): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.patch(id, 'replace', '/uidState', 'On') mock_patch.assert_called_once_with(id, 'replace', '/uidState', 'On', timeout=-1)
class ServerHardwareTest(TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection) self.uri = "/rest/server-hardware/1224242424" self._server_hardware.data = {"uri": self.uri} @mock.patch.object(ResourceUtilizationMixin, 'get_utilization') def test_get_utilization_with_all_args(self, mock_get_utilization): self._server_hardware.get_utilization( fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') mock_get_utilization.assert_called_once_with( fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') @mock.patch.object(ResourceHelper, 'do_get') def test_get_utilization_with_defaults(self, mock_get): self._server_hardware.get_utilization() mock_get.assert_called_once_with("{}/utilization".format(self.uri)) @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' self._server_hardware.get_all(2, 500, filter, sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=filter, sort=sort) @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_called_once_with_default_values(self, mock_get_all): self._server_hardware.get_all() mock_get_all.assert_called_once_with(start=0, count=-1, filter='', sort='') @mock.patch.object(ResourceHelper, 'create') def test_add_called_once(self, mock_create): information = { "licensingIntent": "OneView", "configurationState": "Managed" } mock_create.return_value = {} self._server_hardware.add(information) mock_create.assert_called_once_with(information.copy(), None, -1, None, False) @mock.patch.object(ResourceHelper, 'create') def test_add_multiple_servers_called_once(self, mock_create): information = { "licensingIntent": "OneView", "configurationState": "Managed" } mock_create.return_value = {} self._server_hardware.add_multiple_servers(information) mock_create.assert_called_once_with(information.copy(), '/rest/server-hardware/discovery', -1, None, False) @mock.patch.object(ResourceHelper, 'delete') def test_remove_called_once(self, mock_delete): self._server_hardware.remove(force=False) mock_delete.assert_called_once_with(self.uri, force=False, custom_headers=None, timeout=-1) @mock.patch.object(ResourceHelper, 'delete') def test_remove_called_once_with_force(self, mock_delete): self._server_hardware.remove(force=True) mock_delete.assert_called_once_with(self.uri, force=True, custom_headers=None, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_bios(self, mock_get): uri_rest_call = '{}/bios'.format(self.uri) self._server_hardware.get_bios() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_environmental_configuration(self, mock_get): uri_rest_call = '{}/environmentalConfiguration'.format(self.uri) self._server_hardware.get_environmental_configuration() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'update') def test_update_environmental_configuration(self, mock_update): uri_rest_call = '{}/environmentalConfiguration'.format(self.uri) configuration = {"calibratedMaxPower": 2500} configuration_rest_call = configuration.copy() self._server_hardware.update_environmental_configuration(configuration, timeout=-1) mock_update.assert_called_once_with(configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_ilo_sso_url(self, mock_get): uri_rest_call = '{}/iloSsoUrl'.format(self.uri) self._server_hardware.get_ilo_sso_url() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_ilo_sso_url_with_ip(self, mock_get): uri_rest_call = '{}/iloSsoUrl?ip=172.16.8.4'.format(self.uri) self._server_hardware.get_ilo_sso_url(ip='172.16.8.4') mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_java_remote_console(self, mock_get): uri_rest_call = '{}/javaRemoteConsoleUrl'.format(self.uri) self._server_hardware.get_java_remote_console_url() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_java_remote_console_with_ip(self, mock_get): uri_rest_call = '{}/javaRemoteConsoleUrl?ip=172.16.8.4'.format( self.uri) self._server_hardware.get_java_remote_console_url(ip='172.16.8.4') mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'update') def test_refresh_state(self, mock_update): uri_rest_call = '{}/refreshState'.format(self.uri) configuration = {"refreshState": "RefreshPending"} configuration_rest_call = configuration.copy() self._server_hardware.refresh_state(configuration, timeout=-1) mock_update.assert_called_once_with(configuration_rest_call, uri=uri_rest_call, timeout=-1) @mock.patch.object(ResourceHelper, 'update') def test_power_state(self, mock_update): uri_rest_call = '{}/powerState'.format(self.uri) configuration = {"powerState": "Off", "powerControl": "MomentaryPress"} configuration_rest_call = configuration.copy() self._server_hardware.update_power_state(configuration) mock_update.assert_called_once_with(configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_remote_console_url(self, mock_get): uri_rest_call = '{}/remoteConsoleUrl'.format(self.uri) self._server_hardware.get_remote_console_url() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_remote_console_url_with_ip(self, mock_get): uri_rest_call = '{}/remoteConsoleUrl?ip=172.16.8.4'.format(self.uri) self._server_hardware.get_remote_console_url(ip='172.16.8.4') mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_put') def test_update_mp_firware_version_called_once(self, mock_get): self._server_hardware.update_mp_firware_version() uri = "{}/mpFirmwareVersion".format(self.uri) mock_get.assert_called_once_with(uri, None, -1, None) @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_firmwares_with_defaults(self, mock_get): self._server_hardware.get_all_firmwares() mock_get.assert_called_once_with(0, -1, '', '', '', '', '', '/rest/server-hardware/*/firmware') @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_firmwares_with_all_arguments(self, mock_get): self._server_hardware.get_all_firmwares("name='name'", 2, 5, 'query', 'sort') mock_get.assert_called_once_with(2, 5, "name='name'", 'query', 'sort', '', '', '/rest/server-hardware/*/firmware') @mock.patch.object(ResourceHelper, 'do_get') def test_get_firmware_by_id(self, mock_get): self._server_hardware.get_firmware() mock_get.assert_called_once_with('{}/firmware'.format(self.uri)) @mock.patch.object(ResourceHelper, 'do_get') def test_get_firmware_by_uri(self, mock_get): self._server_hardware.get_firmware() mock_get.assert_called_once_with('{}/firmware'.format(self.uri)) @mock.patch.object(ResourcePatchMixin, 'patch_request') def test_patch_called_once(self, mock_patch): self._server_hardware.patch('replace', '/uidState', 'On') mock_patch.assert_called_once_with(self.uri, body=[{ 'op': 'replace', 'path': '/uidState', 'value': 'On' }], custom_headers=None, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_physical_server_hardware(self, mock_get): uri_rest_call = '{}/physicalServerHardware'.format(self.uri) self._server_hardware.get_physical_server_hardware() mock_get.assert_called_once_with(uri_rest_call)
def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection)
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()
def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection)
class ServerHardwareTest(TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection) self.uri = "/rest/server-hardware/1224242424" self._server_hardware.data = {"uri": self.uri} @mock.patch.object(ResourceUtilizationMixin, 'get_utilization') def test_get_utilization_with_all_args(self, mock_get_utilization): self._server_hardware.get_utilization(fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') mock_get_utilization.assert_called_once_with(fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') @mock.patch.object(ResourceHelper, 'do_get') def test_get_utilization_with_defaults(self, mock_get): self._server_hardware.get_utilization() mock_get.assert_called_once_with("{}/utilization".format(self.uri)) @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' self._server_hardware.get_all(2, 500, filter, sort) mock_get_all.assert_called_once_with(start=2, count=500, filter=filter, sort=sort) @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_called_once_with_default_values(self, mock_get_all): self._server_hardware.get_all() mock_get_all.assert_called_once_with(start=0, count=-1, filter='', sort='') @mock.patch.object(ResourceHelper, 'create') def test_add_called_once(self, mock_create): information = { "licensingIntent": "OneView", "configurationState": "Managed" } mock_create.return_value = {} self._server_hardware.add(information) mock_create.assert_called_once_with(information.copy(), None, -1, None, False) @mock.patch.object(ResourceHelper, 'create') def test_add_multiple_servers_called_once(self, mock_create): information = { "licensingIntent": "OneView", "configurationState": "Managed" } mock_create.return_value = {} self._server_hardware.add_multiple_servers(information) mock_create.assert_called_once_with(information.copy(), '/rest/server-hardware/discovery', -1, None, False) @mock.patch.object(ResourceHelper, 'delete') def test_remove_called_once(self, mock_delete): self._server_hardware.remove(force=False) mock_delete.assert_called_once_with(self.uri, force=False, custom_headers=None, timeout=-1) @mock.patch.object(ResourceHelper, 'delete') def test_remove_called_once_with_force(self, mock_delete): self._server_hardware.remove(force=True) mock_delete.assert_called_once_with(self.uri, force=True, custom_headers=None, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_bios(self, mock_get): uri_rest_call = '{}/bios'.format(self.uri) self._server_hardware.get_bios() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_environmental_configuration(self, mock_get): uri_rest_call = '{}/environmentalConfiguration'.format(self.uri) self._server_hardware.get_environmental_configuration() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'update') def test_update_environmental_configuration(self, mock_update): uri_rest_call = '{}/environmentalConfiguration'.format(self.uri) configuration = {"calibratedMaxPower": 2500} configuration_rest_call = configuration.copy() self._server_hardware.update_environmental_configuration( configuration, timeout=-1) mock_update.assert_called_once_with( configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_ilo_sso_url(self, mock_get): uri_rest_call = '{}/iloSsoUrl'.format(self.uri) self._server_hardware.get_ilo_sso_url() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_ilo_sso_url_with_ip(self, mock_get): uri_rest_call = '{}/iloSsoUrl?ip=172.16.8.4'.format(self.uri) self._server_hardware.get_ilo_sso_url(ip='172.16.8.4') mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_java_remote_console(self, mock_get): uri_rest_call = '{}/javaRemoteConsoleUrl'.format(self.uri) self._server_hardware.get_java_remote_console_url() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_java_remote_console_with_ip(self, mock_get): uri_rest_call = '{}/javaRemoteConsoleUrl?ip=172.16.8.4'.format(self.uri) self._server_hardware.get_java_remote_console_url(ip='172.16.8.4') mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'update') def test_refresh_state(self, mock_update): uri_rest_call = '{}/refreshState'.format(self.uri) configuration = {"refreshState": "RefreshPending"} configuration_rest_call = configuration.copy() self._server_hardware.refresh_state( configuration, timeout=-1) mock_update.assert_called_once_with( configuration_rest_call, uri=uri_rest_call, timeout=-1) @mock.patch.object(ResourceHelper, 'update') def test_power_state(self, mock_update): uri_rest_call = '{}/powerState'.format(self.uri) configuration = { "powerState": "Off", "powerControl": "MomentaryPress" } configuration_rest_call = configuration.copy() self._server_hardware.update_power_state(configuration) mock_update.assert_called_once_with( configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_remote_console_url(self, mock_get): uri_rest_call = '{}/remoteConsoleUrl'.format(self.uri) self._server_hardware.get_remote_console_url() mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_get') def test_get_remote_console_url_with_ip(self, mock_get): uri_rest_call = '{}/remoteConsoleUrl?ip=172.16.8.4'.format(self.uri) self._server_hardware.get_remote_console_url(ip='172.16.8.4') mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceHelper, 'do_put') def test_update_mp_firware_version_called_once(self, mock_get): self._server_hardware.update_mp_firware_version() uri = "{}/mpFirmwareVersion".format(self.uri) mock_get.assert_called_once_with(uri, None, -1, None) @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_firmwares_with_defaults(self, mock_get): self._server_hardware.get_all_firmwares() mock_get.assert_called_once_with(0, -1, '', '', '', '', '', '/rest/server-hardware/*/firmware') @mock.patch.object(ResourceHelper, 'get_all') def test_get_all_firmwares_with_all_arguments(self, mock_get): self._server_hardware.get_all_firmwares("name='name'", 2, 5, 'query', 'sort') mock_get.assert_called_once_with(2, 5, "name='name'", 'query', 'sort', '', '', '/rest/server-hardware/*/firmware') @mock.patch.object(ResourceHelper, 'do_get') def test_get_firmware_by_id(self, mock_get): self._server_hardware.get_firmware() mock_get.assert_called_once_with('{}/firmware'.format(self.uri)) @mock.patch.object(ResourceHelper, 'do_get') def test_get_firmware_by_uri(self, mock_get): self._server_hardware.get_firmware() mock_get.assert_called_once_with('{}/firmware'.format(self.uri)) @mock.patch.object(ResourcePatchMixin, 'patch_request') def test_patch_called_once(self, mock_patch): self._server_hardware.patch('replace', '/uidState', 'On') mock_patch.assert_called_once_with(self.uri, body=[{'op': 'replace', 'path': '/uidState', 'value': 'On'}], custom_headers=None, timeout=-1) @mock.patch.object(ResourceHelper, 'do_get') def test_get_physical_server_hardware(self, mock_get): uri_rest_call = '{}/physicalServerHardware'.format(self.uri) self._server_hardware.get_physical_server_hardware() mock_get.assert_called_once_with(uri_rest_call)
def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection) self.uri = "/rest/server-hardware/1224242424" self._server_hardware.data = {"uri": self.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")
class ServerHardwareTest(TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._server_hardware = ServerHardware(self.connection) @mock.patch.object(ResourceClient, 'get_utilization') def test_get_utilization_with_all_args(self, mock_get_utilization): self._server_hardware.get_utilization( '09USE7335NW3', fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') mock_get_utilization.assert_called_once_with( '09USE7335NW3', fields='AmbientTemperature,AveragePower,PeakPower', filter='startDate=2016-05-30T03:29:42.361Z', refresh=True, view='day') @mock.patch.object(ResourceClient, 'get_utilization') def test_get_utilization_with_defaults(self, mock_get): self._server_hardware.get_utilization('09USE7335NW3') mock_get.assert_called_once_with('09USE7335NW3', fields=None, filter=None, refresh=False, view=None) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_called_once(self, mock_get_all): filter = 'name=TestName' sort = 'name:ascending' self._server_hardware.get_all(2, 500, filter, sort) mock_get_all.assert_called_once_with(2, 500, filter=filter, sort=sort) @mock.patch.object(ResourceClient, 'get_all') def test_get_all_called_once_with_default_values(self, mock_get_all): self._server_hardware.get_all() mock_get_all.assert_called_once_with(0, -1, filter='', sort='') @mock.patch.object(ResourceClient, 'get_by') def test_get_by_called_once(self, mock_get_by): self._server_hardware.get_by('name', 'OneViewSDK-Test-Rack-Server') mock_get_by.assert_called_once_with('name', 'OneViewSDK-Test-Rack-Server') @mock.patch.object(ResourceClient, 'create') def test_add_called_once(self, mock_create): information = { "licensingIntent": "OneView", "configurationState": "Managed" } mock_create.return_value = {} self._server_hardware.add(information) mock_create.assert_called_once_with(information.copy(), timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_called_once(self, mock_get): self._server_hardware.get('3518be0e-17c1-4189-8f81-83f3724f6155') mock_get.assert_called_once_with( '3518be0e-17c1-4189-8f81-83f3724f6155') @mock.patch.object(ResourceClient, 'get') def test_get_with_uri_called_once(self, mock_get): uri = '/rest/server-hardware/3518be0e-17c1-4189-8f81-83f3724f6155' self._server_hardware.get(uri) mock_get.assert_called_once_with(uri) @mock.patch.object(ResourceClient, 'delete') def test_remove_called_once(self, mock_delete): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.remove(id, force=False) mock_delete.assert_called_once_with(id, force=False, timeout=-1) @mock.patch.object(ResourceClient, 'delete') def test_remove_called_once_with_force(self, mock_delete): id = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.remove(id, force=True) mock_delete.assert_called_once_with(id, force=True, timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_bios_by_uri(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/bios' self._server_hardware.get_bios(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_bios_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/bios' self._server_hardware.get_bios(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_environmental_configuration_by_uri(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' self._server_hardware.get_environmental_configuration( uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_environmental_configuration_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' self._server_hardware.get_environmental_configuration( id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'update') def test_update_environmental_configuration_by_uri(self, mock_update): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' configuration = {"calibratedMaxPower": 2500} configuration_rest_call = configuration.copy() self._server_hardware.update_environmental_configuration( configuration, uri_server_hardware, timeout=-1) mock_update.assert_called_once_with(configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_update_environmental_configuration_by_id(self, mock_update): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/environmentalConfiguration' configuration = {"calibratedMaxPower": 2500} configuration_rest_call = configuration.copy() self._server_hardware.update_environmental_configuration( configuration, id_server_hardware, timeout=-1) mock_update.assert_called_once_with(configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_ilo_sso_url_by_url(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/iloSsoUrl' self._server_hardware.get_ilo_sso_url(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_ilo_sso_url_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/iloSsoUrl' self._server_hardware.get_ilo_sso_url(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_java_remote_console_by_url(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/javaRemoteConsoleUrl' self._server_hardware.get_java_remote_console_url(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_java_remote_console_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/javaRemoteConsoleUrl' self._server_hardware.get_java_remote_console_url(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'update') def test_refresh_state_by_uri(self, mock_update): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/refreshState' configuration = {"refreshState": "RefreshPending"} configuration_rest_call = configuration.copy() self._server_hardware.refresh_state(configuration, uri_server_hardware, timeout=-1) mock_update.assert_called_once_with(configuration_rest_call, uri=uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_refresh_state_by_id(self, mock_update): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/refreshState' configuration = {"refreshState": "RefreshPending"} configuration_rest_call = configuration.copy() self._server_hardware.refresh_state(configuration, id_server_hardware, timeout=-1) mock_update.assert_called_once_with(configuration_rest_call, uri=uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_power_state_by_uri(self, mock_update): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/powerState' configuration = {"powerState": "Off", "powerControl": "MomentaryPress"} configuration_rest_call = configuration.copy() self._server_hardware.update_power_state(configuration, uri_server_hardware) mock_update.assert_called_once_with(configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'update') def test_power_state_by_id(self, mock_update): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/powerState' configuration = {"powerState": "Off", "powerControl": "MomentaryPress"} configuration_rest_call = configuration.copy() self._server_hardware.update_power_state(configuration, id_server_hardware, -1) mock_update.assert_called_once_with(configuration_rest_call, uri_rest_call, timeout=-1) @mock.patch.object(ResourceClient, 'get') def test_get_remote_console_url_by_url(self, mock_get): uri_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/remoteConsoleUrl' self._server_hardware.get_remote_console_url(uri_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'get') def test_get_remote_console_url_by_id(self, mock_get): id_server_hardware = 'ad28cf21-8b15-4f92-bdcf-51cb2042db32' uri_rest_call = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/remoteConsoleUrl' self._server_hardware.get_remote_console_url(id_server_hardware) mock_get.assert_called_once_with(uri_rest_call) @mock.patch.object(ResourceClient, 'update_with_zero_body') def test_update_mp_firware_version_called_once(self, mock_get): id_server_hardware = '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32' self._server_hardware.update_mp_firware_version(id_server_hardware) mock_get.assert_called_once_with( '/rest/server-hardware/ad28cf21-8b15-4f92-bdcf-51cb2042db32/mpFirmwareVersion', -1)