From 01a44568cc60bb5a6dd7b55d69b20bba57d1b94b Mon Sep 17 00:00:00 2001 From: He Jie Xu Date: Fri, 6 Sep 2013 16:25:26 +0800 Subject: [PATCH] Fix status code of server's action confirm_resize for v3 The status code of confirm_resize should be 202, but it returns 204 now. That because it returns HTTPNoContent that overwrites the status code of decorator 'wsgi.response(202)' And adds API samples for confirm_resize that used to test the status code of confirm_resize. Partially implements blueprint v3-api-unittests Closes-bug: #1233561 Change-Id: I50a3046866af0a1efdb5c41ded40f973b02843e8 --- .../servers/server-action-confirm-resize.json | 3 ++ .../servers/server-action-confirm-resize.xml | 3 ++ .../servers/server-action-resize.json | 5 +++ .../servers/server-action-resize.xml | 4 +++ .../openstack/compute/plugins/v3/servers.py | 1 - .../server-action-confirm-resize.json.tpl | 3 ++ .../server-action-confirm-resize.xml.tpl | 3 ++ .../servers/server-action-resize.json.tpl | 5 +++ .../servers/server-action-resize.xml.tpl | 4 +++ nova/tests/integrated/v3/test_servers.py | 35 +++++++++++++++++++ 10 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 doc/v3/api_samples/servers/server-action-confirm-resize.json create mode 100644 doc/v3/api_samples/servers/server-action-confirm-resize.xml create mode 100644 doc/v3/api_samples/servers/server-action-resize.json create mode 100644 doc/v3/api_samples/servers/server-action-resize.xml create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.xml.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-action-resize.json.tpl create mode 100644 nova/tests/integrated/v3/api_samples/servers/server-action-resize.xml.tpl diff --git a/doc/v3/api_samples/servers/server-action-confirm-resize.json b/doc/v3/api_samples/servers/server-action-confirm-resize.json new file mode 100644 index 000000000000..493a9ffe865c --- /dev/null +++ b/doc/v3/api_samples/servers/server-action-confirm-resize.json @@ -0,0 +1,3 @@ +{ + "confirm_resize" : null +} \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-action-confirm-resize.xml b/doc/v3/api_samples/servers/server-action-confirm-resize.xml new file mode 100644 index 000000000000..20b787e246c7 --- /dev/null +++ b/doc/v3/api_samples/servers/server-action-confirm-resize.xml @@ -0,0 +1,3 @@ + + \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-action-resize.json b/doc/v3/api_samples/servers/server-action-resize.json new file mode 100644 index 000000000000..7dcf7751db29 --- /dev/null +++ b/doc/v3/api_samples/servers/server-action-resize.json @@ -0,0 +1,5 @@ +{ + "resize" : { + "flavor_ref" : "2" + } +} \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-action-resize.xml b/doc/v3/api_samples/servers/server-action-resize.xml new file mode 100644 index 000000000000..f73b8f855e67 --- /dev/null +++ b/doc/v3/api_samples/servers/server-action-resize.xml @@ -0,0 +1,4 @@ + + \ No newline at end of file diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index 6854d99c4d13..a59ded4bd67c 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -953,7 +953,6 @@ class ServersController(wsgi.Controller): except exception.InstanceInvalidState as state_error: common.raise_http_conflict_for_instance_invalid_state(state_error, 'confirm_resize') - return exc.HTTPNoContent() @wsgi.response(202) @wsgi.serializers(xml=FullServerTemplate) diff --git a/nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.json.tpl b/nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.json.tpl new file mode 100644 index 000000000000..1a3a9a4ef857 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.json.tpl @@ -0,0 +1,3 @@ +{ + "confirm_resize" : null +} diff --git a/nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.xml.tpl b/nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.xml.tpl new file mode 100644 index 000000000000..6bc8750ab08b --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-action-confirm-resize.xml.tpl @@ -0,0 +1,3 @@ + + diff --git a/nova/tests/integrated/v3/api_samples/servers/server-action-resize.json.tpl b/nova/tests/integrated/v3/api_samples/servers/server-action-resize.json.tpl new file mode 100644 index 000000000000..368e6bc076ec --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-action-resize.json.tpl @@ -0,0 +1,5 @@ +{ + "resize" : { + "flavor_ref" : "%(id)s" + } +} diff --git a/nova/tests/integrated/v3/api_samples/servers/server-action-resize.xml.tpl b/nova/tests/integrated/v3/api_samples/servers/server-action-resize.xml.tpl new file mode 100644 index 000000000000..677548d8d3a0 --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-action-resize.xml.tpl @@ -0,0 +1,4 @@ + + diff --git a/nova/tests/integrated/v3/test_servers.py b/nova/tests/integrated/v3/test_servers.py index dcba91001294..d807490cba8d 100644 --- a/nova/tests/integrated/v3/test_servers.py +++ b/nova/tests/integrated/v3/test_servers.py @@ -74,3 +74,38 @@ class ServersSampleAllExtensionJsonTest(ServersSampleJsonTest): class ServersSampleAllExtensionXmlTest(ServersSampleXmlTest): all_extensions = True + + +class ServersActionsJsonTest(ServersSampleBase): + sample_dir = 'servers' + + def _test_server_action(self, uuid, action, + subs={}, resp_tpl=None, code=202): + subs.update({'action': action, + 'glance_host': self._get_glance_host()}) + response = self._do_post('servers/%s/action' % uuid, + 'server-action-%s' % action.replace('_', + '-'), + subs) + if resp_tpl: + subs.update(self._get_regexes()) + self._verify_response(resp_tpl, subs, response, code) + else: + self.assertEqual(response.status, code) + self.assertEqual(response.read(), "") + + def test_server_resize(self): + self.flags(allow_resize_to_same_host=True) + uuid = self._post_server() + self._test_server_action(uuid, "resize", + {"id": 2, + "host": self._get_host()}) + return uuid + + def test_server_confirm_resize(self): + uuid = self.test_server_resize() + self._test_server_action(uuid, "confirm_resize") + + +class ServersActionsXmlTest(ServersActionsJsonTest): + ctype = 'xml'