From aecc10974297fbdf0a933b663675c2b4dd6ae43c Mon Sep 17 00:00:00 2001 From: Lingxian Kong Date: Thu, 3 Oct 2013 16:18:46 +0800 Subject: [PATCH] add some negative tests for force_delete/restore - test_force_delete_nonexistent_server_id - test_force_delete_server_invalid_state - test_restore_nonexistent_server_id - test_restore_server_invalid_state negative tests should stay in negative files of corresponding action. Change-Id: Icafcb1e17382f8856937e8e903650fb424b00a25 --- .../compute/servers/test_servers_negative.py | 30 +++++++++++++++++++ .../services/compute/json/servers_client.py | 8 +++++ .../services/compute/xml/servers_client.py | 8 +++++ 3 files changed, 46 insertions(+) diff --git a/tempest/api/compute/servers/test_servers_negative.py b/tempest/api/compute/servers/test_servers_negative.py index 0f753a0e58..c6e000cdb2 100644 --- a/tempest/api/compute/servers/test_servers_negative.py +++ b/tempest/api/compute/servers/test_servers_negative.py @@ -359,6 +359,36 @@ class ServersNegativeTestJSON(base.BaseV2ComputeTest): self.client.get_console_output, nonexistent_server, 10) + @attr(type=['negative', 'gate']) + def test_force_delete_nonexistent_server_id(self): + non_existent_server_id = str(uuid.uuid4()) + + self.assertRaises(exceptions.NotFound, + self.client.force_delete_server, + non_existent_server_id) + + @attr(type=['negative', 'gate']) + def test_force_delete_server_invalid_state(self): + # we can only force-delete a server in 'soft-delete' state + self.assertRaises(exceptions.Conflict, + self.client.force_delete_server, + self.server_id) + + @attr(type=['negative', 'gate']) + def test_restore_nonexistent_server_id(self): + non_existent_server_id = str(uuid.uuid4()) + + self.assertRaises(exceptions.NotFound, + self.client.restore_soft_deleted_server, + non_existent_server_id) + + @attr(type=['negative', 'gate']) + def test_restore_server_invalid_state(self): + # we can only restore-delete a server in 'soft-delete' state + self.assertRaises(exceptions.Conflict, + self.client.restore_soft_deleted_server, + self.server_id) + class ServersNegativeTestXML(ServersNegativeTestJSON): _interface = 'xml' diff --git a/tempest/services/compute/json/servers_client.py b/tempest/services/compute/json/servers_client.py index 07bb6ceab0..55a4a1b992 100644 --- a/tempest/services/compute/json/servers_client.py +++ b/tempest/services/compute/json/servers_client.py @@ -390,3 +390,11 @@ class ServersClientJSON(RestClient): (str(server_id), str(request_id))) body = json.loads(body) return resp, body['instanceAction'] + + def force_delete_server(self, server_id, **kwargs): + """Force delete a server.""" + return self.action(server_id, 'forceDelete', None, **kwargs) + + def restore_soft_deleted_server(self, server_id, **kwargs): + """Restore a soft-deleted server.""" + return self.action(server_id, 'restore', None, **kwargs) diff --git a/tempest/services/compute/xml/servers_client.py b/tempest/services/compute/xml/servers_client.py index 43de4ef85f..e21bfc4222 100644 --- a/tempest/services/compute/xml/servers_client.py +++ b/tempest/services/compute/xml/servers_client.py @@ -600,3 +600,11 @@ class ServersClientXML(RestClientXML): (server_id, request_id), self.headers) body = xml_to_json(etree.fromstring(body)) return resp, body + + def force_delete_server(self, server_id, **kwargs): + """Force delete a server.""" + return self.action(server_id, 'forceDelete', None, **kwargs) + + def restore_soft_deleted_server(self, server_id, **kwargs): + """Restore a soft-deleted server.""" + return self.action(server_id, 'restore', None, **kwargs)