Merge "Fix 'os-start/os-stop' server actions for V2.1 API"

This commit is contained in:
Jenkins 2014-09-16 12:18:45 +00:00 committed by Gerrit Code Review
commit f28c5ff905
7 changed files with 61 additions and 10 deletions

View File

@ -0,0 +1,3 @@
{
"os-start" : null
}

View File

@ -0,0 +1,3 @@
{
"os-stop" : null
}

View File

@ -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']

View File

@ -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()

View File

@ -0,0 +1,3 @@
{
"%(action)s" : null
}

View File

@ -0,0 +1,3 @@
{
"%(action)s" : null
}

View File

@ -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')