diff --git a/doc/v3/api_samples/servers/server-action-start.json b/doc/v3/api_samples/servers/server-action-start.json new file mode 100644 index 000000000000..bab802449beb --- /dev/null +++ b/doc/v3/api_samples/servers/server-action-start.json @@ -0,0 +1,3 @@ +{ + "os-start" : null +} \ No newline at end of file diff --git a/doc/v3/api_samples/servers/server-action-stop.json b/doc/v3/api_samples/servers/server-action-stop.json new file mode 100644 index 000000000000..d4b59a3fdd9c --- /dev/null +++ b/doc/v3/api_samples/servers/server-action-stop.json @@ -0,0 +1,3 @@ +{ + "os-stop" : null +} \ 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 5f530691f0ad..8e45fdb5174a 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -1019,7 +1019,7 @@ class ServersController(wsgi.Controller): raise webob.exc.HTTPNotFound(explanation=e.format_message()) @extensions.expected_errors((404, 409)) - @wsgi.action('start') + @wsgi.action('os-start') def _start_server(self, req, id, body): """Start an instance.""" context = req.environ['nova.context'] @@ -1034,7 +1034,7 @@ class ServersController(wsgi.Controller): return webob.Response(status_int=202) @extensions.expected_errors((404, 409)) - @wsgi.action('stop') + @wsgi.action('os-stop') def _stop_server(self, req, id, body): """Stop an instance.""" context = req.environ['nova.context'] diff --git a/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py b/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py index bc5b132258bf..ad190100201a 100644 --- a/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py +++ b/nova/tests/api/openstack/compute/contrib/test_server_start_stop.py @@ -15,7 +15,11 @@ import mox import webob -from nova.api.openstack.compute.contrib import server_start_stop +from nova.api.openstack.compute.contrib import server_start_stop \ + as server_v2 +from nova.api.openstack.compute import plugins +from nova.api.openstack.compute.plugins.v3 import servers \ + as server_v21 from nova.compute import api as compute_api from nova import db from nova import exception @@ -49,11 +53,18 @@ def fake_start_stop_invalid_state(self, context, instance): raise exception.InstanceIsLocked(instance_uuid=instance['uuid']) -class ServerStartStopTest(test.TestCase): +class ServerStartStopTestV21(test.TestCase): + start_policy = "compute:v3:servers:start" + stop_policy = "compute:v3:servers:stop" def setUp(self): - super(ServerStartStopTest, self).setUp() - self.controller = server_start_stop.ServerStartStopActionController() + super(ServerStartStopTestV21, self).setUp() + self._setup_controller() + + def _setup_controller(self): + ext_info = plugins.LoadedExtensionInfo() + self.controller = server_v21.ServersController( + extension_info=ext_info) def test_start(self): self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get) @@ -67,7 +78,7 @@ class ServerStartStopTest(test.TestCase): def test_start_policy_failed(self): rules = { - "compute:start": + self.start_policy: common_policy.parse_rule("project_id:non_fake") } policy.set_rules(rules) @@ -77,7 +88,7 @@ class ServerStartStopTest(test.TestCase): exc = self.assertRaises(exception.PolicyNotAuthorized, self.controller._start_server, req, 'test_inst', body) - self.assertIn('compute:start', exc.format_message()) + self.assertIn(self.start_policy, exc.format_message()) def test_start_not_ready(self): self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get) @@ -115,7 +126,7 @@ class ServerStartStopTest(test.TestCase): def test_stop_policy_failed(self): rules = { - "compute:stop": + self.stop_policy: common_policy.parse_rule("project_id:non_fake") } policy.set_rules(rules) @@ -125,7 +136,7 @@ class ServerStartStopTest(test.TestCase): exc = self.assertRaises(exception.PolicyNotAuthorized, self.controller._stop_server, req, 'test_inst', body) - self.assertIn("compute:stop", exc.format_message()) + self.assertIn(self.stop_policy, exc.format_message()) def test_stop_not_ready(self): self.stubs.Set(db, 'instance_get_by_uuid', fake_instance_get) @@ -162,3 +173,11 @@ class ServerStartStopTest(test.TestCase): body = dict(stop="") self.assertRaises(webob.exc.HTTPNotFound, self.controller._stop_server, req, 'test_inst', body) + + +class ServerStartStopTestV2(ServerStartStopTestV21): + start_policy = "compute:start" + stop_policy = "compute:stop" + + def _setup_controller(self): + self.controller = server_v2.ServerStartStopActionController() diff --git a/nova/tests/integrated/v3/api_samples/servers/server-action-start.json.tpl b/nova/tests/integrated/v3/api_samples/servers/server-action-start.json.tpl new file mode 100644 index 000000000000..883d0247a2bc --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-action-start.json.tpl @@ -0,0 +1,3 @@ +{ + "%(action)s" : null +} diff --git a/nova/tests/integrated/v3/api_samples/servers/server-action-stop.json.tpl b/nova/tests/integrated/v3/api_samples/servers/server-action-stop.json.tpl new file mode 100644 index 000000000000..883d0247a2bc --- /dev/null +++ b/nova/tests/integrated/v3/api_samples/servers/server-action-stop.json.tpl @@ -0,0 +1,3 @@ +{ + "%(action)s" : null +} diff --git a/nova/tests/integrated/v3/test_servers.py b/nova/tests/integrated/v3/test_servers.py index b7da97a46149..9dbcb4beb227 100644 --- a/nova/tests/integrated/v3/test_servers.py +++ b/nova/tests/integrated/v3/test_servers.py @@ -158,3 +158,23 @@ class ServersActionsJsonTest(ServersSampleBase): uuid = self._post_server() self._test_server_action(uuid, 'create_image', {'name': 'foo-image'}) + + +class ServerStartStopJsonTest(ServersSampleBase): + sample_dir = 'servers' + + def _test_server_action(self, uuid, action, req_tpl): + response = self._do_post('servers/%s/action' % uuid, + req_tpl, + {'action': action}) + self.assertEqual(response.status, 202) + self.assertEqual(response.read(), "") + + def test_server_start(self): + uuid = self._post_server() + self._test_server_action(uuid, 'os-stop', 'server-action-stop') + self._test_server_action(uuid, 'os-start', 'server-action-start') + + def test_server_stop(self): + uuid = self._post_server() + self._test_server_action(uuid, 'os-stop', 'server-action-stop') \ No newline at end of file