class TasksTest(TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._client = Tasks(self.connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get): self._client.get_all( fields='parentTaskUri,owner,name', filter= "\"taskState='Running'&filter=associatedResource.resourceCatgory='appliance'\"", sort='name:ascending', view='day') mock_get.assert_called_once_with( count=-1, fields='parentTaskUri,owner,name', filter='"taskState=\'Running\'&filter=associatedResource' '.resourceCatgory=\'appliance\'"', query='', sort='name:ascending', start=0, view='day') @mock.patch.object(ResourceClient, 'get') def test_get_specific(self, mock_get): self._client.get('35323930-4936-4450-5531-303153474820') mock_get.assert_called_once_with( '35323930-4936-4450-5531-303153474820')
def tasks(self): """ Gets the Tasks API client. Returns: Tasks: """ if not self.__tasks: self.__tasks = Tasks(self.__connection) return self.__tasks
class TasksTest(TestCase): def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._client = Tasks(self.connection) @mock.patch.object(ResourceClient, 'get_all') def test_get_all(self, mock_get): self._client.get_all(fields='parentTaskUri,owner,name', filter="\"taskState='Running'&filter=associatedResource.resourceCatgory='appliance'\"", sort='name:ascending', view='day') mock_get.assert_called_once_with(count=-1, fields='parentTaskUri,owner,name', filter='"taskState=\'Running\'&filter=associatedResource' '.resourceCatgory=\'appliance\'"', query='', sort='name:ascending', start=0, view='day') @mock.patch.object(ResourceClient, 'get') def test_get_specific(self, mock_get): self._client.get('35323930-4936-4450-5531-303153474820') mock_get.assert_called_once_with('35323930-4936-4450-5531-303153474820')
def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._client = Tasks(self.connection)
def test_create_system_without_description(self, time_mock, power_state): """Tests create a redfish System with Network, Storage and Server""" with open('oneview_redfish_toolkit/mockups/oneview/' 'ServerProfileBuiltFromTemplateToCreateASystem.json') as f: expected_server_profile_built = json.load(f) task_without_resource_uri = { "associatedResource": { "resourceUri": None }, "uri": "/rest/tasks/123456" } task_with_resource_uri = { "associatedResource": { "resourceUri": self.server_profile["uri"] }, "uri": "/rest/tasks/123456" } expected_server_profile_built["sanStorage"] = self.san_storage expected_server_profile_built["connectionSettings"][ "connections"].append(self.fc_connection) data_to_create_without_desc = copy.deepcopy(self.data_to_create_system) del expected_server_profile_built['description'] data_to_create_without_desc['Description'] = '' self.run_common_mock_to_server_hardware() power_state.return_value = None self.run_common_mock_to_server_profile_template() self.run_common_mock_to_drives() self.run_common_mock_to_volumes() storage_prool_obj = StoragePools( self.oneview_client, {"storageSystemUri": "/rest/storage-systems/TXQ1000307"}) self.oneview_client.storage_pools.get.return_value = storage_prool_obj # The connection.post return for /rest/server-profiles is a tuple self.oneview_client.connection.post.return_value = \ (task_without_resource_uri, None) # The task will be requested 3 times in this case, # simulating the checking of resource uri task_without_resource_uri_obj = Tasks(self.oneview_client, task_without_resource_uri) task_with_resource_uri_obj = Tasks(self.oneview_client, task_with_resource_uri) self.oneview_client.tasks.get_by_uri.side_effect = [ task_without_resource_uri_obj, task_without_resource_uri_obj, task_with_resource_uri_obj ] response = self.client.post( "/redfish/v1/Systems", data=json.dumps(data_to_create_without_desc), 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( self.common_calls_to_assert_hardware) self.oneview_client.server_profile_templates.get_by_id.assert_has_calls( self.common_calls_to_assert_spt) self.oneview_client.index_resources.get.assert_has_calls( self.common_calls_to_assert_drives) self.oneview_client.server_profiles.create.assert_not_called() self.oneview_client.tasks.get_by_uri.assert_called_with( task_without_resource_uri["uri"]) # self.oneview_client.connection.post.assert_called_once_with( # '/rest/server-profiles', expected_server_profile_built # ) self.assertEqual(self.oneview_client.tasks.get_by_uri.call_count, 3) time_mock.sleep.assert_called_with(3)
def tasks(self): if not self.__tasks: self.__tasks = Tasks(self.__connection) return self.__tasks
def setUp(self): self.host = '127.0.0.1' self.connection = connection(self.host) self._client = Tasks(self.connection)