Merge "Converting reboot to use instance objects"
This commit is contained in:
commit
0086109850
|
@ -1458,7 +1458,10 @@ class CloudController(object):
|
|||
def reboot_instances(self, context, instance_id, **kwargs):
|
||||
"""instance_id is a list of instance ids"""
|
||||
LOG.audit(_("Reboot instance %r"), instance_id, context=context)
|
||||
self._do_instances(self.compute_api.reboot, context, instance_id)
|
||||
for ec2_id in instance_id:
|
||||
_instance_id = ec2utils.ec2_id_to_id(ec2_id)
|
||||
instance = self.compute_api.get(context, _instance_id)
|
||||
self.compute_api.reboot(context, instance, 'HARD')
|
||||
return True
|
||||
|
||||
def stop_instances(self, context, instance_id, **kwargs):
|
||||
|
|
|
@ -142,6 +142,13 @@ class Controller(object):
|
|||
limited_list = self._limit_items(instance_list, req)
|
||||
return self._build_list(req, limited_list, is_detail=is_detail)
|
||||
|
||||
def _get_server(self, context, instance_uuid):
|
||||
"""Utility function for looking up an instance by uuid"""
|
||||
try:
|
||||
return self.compute_api.get(context, instance_uuid)
|
||||
except exception.NotFound:
|
||||
raise exc.HTTPNotFound()
|
||||
|
||||
def _handle_quota_error(self, error):
|
||||
"""
|
||||
Reraise quota errors as api-specific http exceptions
|
||||
|
@ -609,9 +616,12 @@ class Controller(object):
|
|||
msg = _("Missing argument 'type' for reboot")
|
||||
LOG.exception(msg)
|
||||
raise exc.HTTPBadRequest(explanation=msg)
|
||||
|
||||
context = req.environ['nova.context']
|
||||
instance = self._get_server(context, id)
|
||||
|
||||
try:
|
||||
self.compute_api.reboot(req.environ['nova.context'], id,
|
||||
reboot_type)
|
||||
self.compute_api.reboot(context, instance, reboot_type)
|
||||
except Exception, e:
|
||||
LOG.exception(_("Error in reboot %s"), e)
|
||||
raise exc.HTTPUnprocessableEntity()
|
||||
|
|
|
@ -1178,15 +1178,15 @@ class API(base.Base):
|
|||
return recv_meta
|
||||
|
||||
@scheduler_api.reroute_compute("reboot")
|
||||
def reboot(self, context, instance_id, reboot_type):
|
||||
def reboot(self, context, instance, reboot_type):
|
||||
"""Reboot the given instance."""
|
||||
state = {'SOFT': task_states.REBOOTING,
|
||||
'HARD': task_states.REBOOTING_HARD}[reboot_type]
|
||||
self.update(context,
|
||||
instance_id,
|
||||
instance['id'],
|
||||
vm_state=vm_states.ACTIVE,
|
||||
task_state=state)
|
||||
self._cast_compute_message('reboot_instance', context, instance_id,
|
||||
self._cast_compute_message('reboot_instance', context, instance['id'],
|
||||
params={'reboot_type': reboot_type})
|
||||
|
||||
@scheduler_api.reroute_compute("rebuild")
|
||||
|
|
|
@ -332,6 +332,12 @@ class reroute_compute(object):
|
|||
context and resource id. Derived class should override this."""
|
||||
context = kwargs.get('context', None)
|
||||
instance_id = kwargs.get('instance_id', None)
|
||||
|
||||
#NOTE(blamar): This is going to get worse before it gets better...
|
||||
instance = kwargs.get('instance', None)
|
||||
if instance is not None:
|
||||
instance_id = instance['uuid']
|
||||
|
||||
if len(args) > 0 and not context:
|
||||
context = args[1]
|
||||
if len(args) > 1 and not instance_id:
|
||||
|
|
|
@ -1371,6 +1371,19 @@ class CloudTestCase(test.TestCase):
|
|||
|
||||
self._restart_compute_service()
|
||||
|
||||
def test_reboot_instances(self):
|
||||
kwargs = {'image_id': 'ami-1',
|
||||
'instance_type': FLAGS.default_instance_type,
|
||||
'max_count': 1, }
|
||||
instance_id = self._run_instance(**kwargs)
|
||||
|
||||
# a running instance can't be started. It is just ignored.
|
||||
result = self.cloud.start_instances(self.context, [instance_id])
|
||||
self.assertTrue(result)
|
||||
|
||||
result = self.cloud.reboot_instances(self.context, [instance_id])
|
||||
self.assertTrue(result)
|
||||
|
||||
def _volume_create(self, volume_id=None):
|
||||
kwargs = {'status': 'available',
|
||||
'host': self.volume.host,
|
||||
|
|
|
@ -30,6 +30,10 @@ def return_server_by_uuid(context, uuid):
|
|||
return stub_instance(1, uuid=uuid)
|
||||
|
||||
|
||||
def return_server_by_uuid_not_found(context, uuid):
|
||||
raise exception.NotFound()
|
||||
|
||||
|
||||
def instance_update(context, instance_id, kwargs):
|
||||
return stub_instance(instance_id)
|
||||
|
||||
|
@ -205,28 +209,37 @@ class ServerActionsControllerTest(test.TestCase):
|
|||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.action, req, FAKE_UUID, body)
|
||||
|
||||
def test_server_reboot_hard(self):
|
||||
def test_reboot_hard(self):
|
||||
body = dict(reboot=dict(type="HARD"))
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.controller.action(req, FAKE_UUID, body)
|
||||
|
||||
def test_server_reboot_soft(self):
|
||||
def test_reboot_soft(self):
|
||||
body = dict(reboot=dict(type="SOFT"))
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.controller.action(req, FAKE_UUID, body)
|
||||
|
||||
def test_server_reboot_incorrect_type(self):
|
||||
def test_reboot_incorrect_type(self):
|
||||
body = dict(reboot=dict(type="NOT_A_TYPE"))
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.action, req, FAKE_UUID, body)
|
||||
|
||||
def test_server_reboot_missing_type(self):
|
||||
def test_reboot_missing_type(self):
|
||||
body = dict(reboot=dict())
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.action, req, FAKE_UUID, body)
|
||||
|
||||
def test_reboot_not_found(self):
|
||||
self.stubs.Set(nova.db, 'instance_get_by_uuid',
|
||||
return_server_by_uuid_not_found)
|
||||
|
||||
body = dict(reboot=dict(type="HARD"))
|
||||
req = fakes.HTTPRequest.blank(self.url)
|
||||
self.assertRaises(webob.exc.HTTPNotFound, self.controller.action,
|
||||
req, str(utils.gen_uuid()), body)
|
||||
|
||||
def test_server_rebuild_accepted_minimum(self):
|
||||
new_return_server = return_server_with_attributes(image_ref='2')
|
||||
self.stubs.Set(nova.db, 'instance_get', new_return_server)
|
||||
|
|
|
@ -343,7 +343,7 @@ class ComputeTestCase(test.TestCase):
|
|||
self.compute.resume_instance(self.context, instance_id)
|
||||
self.compute.terminate_instance(self.context, instance_id)
|
||||
|
||||
def test_soft_reboot_api(self):
|
||||
def test_reboot_soft_api(self):
|
||||
"""Ensure instance can be soft rebooted"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
@ -352,14 +352,14 @@ class ComputeTestCase(test.TestCase):
|
|||
self.assertEqual(inst_ref['task_state'], None)
|
||||
|
||||
reboot_type = "SOFT"
|
||||
self.compute_api.reboot(self.context, instance_id, reboot_type)
|
||||
self.compute_api.reboot(self.context, inst_ref, reboot_type)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], task_states.REBOOTING)
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_soft_reboot(self):
|
||||
def test_reboot_soft(self):
|
||||
"""Ensure instance can be soft rebooted"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
@ -375,7 +375,7 @@ class ComputeTestCase(test.TestCase):
|
|||
|
||||
self.compute.terminate_instance(self.context, instance_id)
|
||||
|
||||
def test_hard_reboot_api(self):
|
||||
def test_reboot_hard_api(self):
|
||||
"""Ensure instance can be hard rebooted"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
@ -384,14 +384,14 @@ class ComputeTestCase(test.TestCase):
|
|||
self.assertEqual(inst_ref['task_state'], None)
|
||||
|
||||
reboot_type = "HARD"
|
||||
self.compute_api.reboot(self.context, instance_id, reboot_type)
|
||||
self.compute_api.reboot(self.context, inst_ref, reboot_type)
|
||||
|
||||
inst_ref = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(inst_ref['task_state'], task_states.REBOOTING_HARD)
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_hard_reboot(self):
|
||||
def test_reboot_hard(self):
|
||||
"""Ensure instance can be hard rebooted"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
|
Loading…
Reference in New Issue