Merge "Handle instance objects in conductor compute_stop"

This commit is contained in:
Jenkins authored and Gerrit Code Review committed 2013-07-20 00:55:19 +00:00
commit 2706f81c62
3 files changed
+44 -7

No files matched your search

+9 -2
View File
@@ -1,4 +1,4 @@
# Copyright 2012 IBM Corp.
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -32,6 +32,7 @@ from nova import network
from nova.network.security_group import openstack_driver
from nova import notifications
from nova.objects import base as nova_object
from nova.objects import instance as instance_obj
from nova.openstack.common import excutils
from nova.openstack.common import jsonutils
from nova.openstack.common import log as logging
@@ -73,7 +74,7 @@ class ConductorManager(manager.Manager):
namespace. See the ComputeTaskManager class for details.
"""
RPC_API_VERSION = '1.54'
RPC_API_VERSION = '1.55'
def __init__(self, *args, **kwargs):
super(ConductorManager, self).__init__(service_name='conductor',
@@ -514,6 +515,12 @@ class ConductorManager(manager.Manager):
return ec2_ids
def compute_stop(self, context, instance, do_cast=True):
# NOTE(mriedem): Clients using an interface before 1.43 will be sending
# dicts so we need to handle that here since compute/api::stop()
# requires an object.
if isinstance(instance, dict):
instance = instance_obj.Instance._from_db_object(
context, instance_obj.Instance(), instance)
self.compute_api.stop(context, instance, do_cast)
def compute_confirm_resize(self, context, instance, migration_ref):
+10 -5
View File
@@ -1,4 +1,4 @@
# Copyright 2012 IBM Corp.
# Copyright 2013 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@@ -106,6 +106,7 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.52 - Pass instance objects for compute_confirm_resize
1.53 - Added compute_reboot
1.54 - Added 'update_cells' argument to bw_usage_update
1.55 - Pass instance objects for compute_stop
"""
BASE_RPC_API_VERSION = '1.0'
@@ -477,10 +478,14 @@ class ConductorAPI(nova.openstack.common.rpc.proxy.RpcProxy):
return self.call(context, msg, version='1.42')
def compute_stop(self, context, instance, do_cast=True):
instance_p = jsonutils.to_primitive(instance)
msg = self.make_msg('compute_stop', instance=instance_p,
do_cast=do_cast)
return self.call(context, msg, version='1.43')
if not self.can_send_version('1.55'):
instance = jsonutils.to_primitive(
objects_base.obj_to_primitive(instance))
version = '1.43'
else:
version = '1.55'
msg = self.make_msg('compute_stop', instance=instance, do_cast=do_cast)
return self.call(context, msg, version=version)
def compute_confirm_resize(self, context, instance, migration_ref):
migration_p = jsonutils.to_primitive(migration_ref)
+25
View File
@@ -812,6 +812,31 @@ class ConductorTestCase(_BaseTestCase, test.TestCase):
self.conductor.security_groups_trigger_handler(self.context,
'event', ['args'])
def test_compute_stop_with_objects(self):
# use an instance object rather than a dict
instance = self._create_fake_instance()
inst_obj = instance_obj.Instance._from_db_object(
self.context, instance_obj.Instance(), instance)
self.mox.StubOutWithMock(self.conductor_manager.compute_api, 'stop')
self.conductor_manager.compute_api.stop(self.context, inst_obj, True)
self.mox.ReplayAll()
self.conductor.compute_stop(self.context, inst_obj)
def test_compute_confirm_resize_with_objects(self):
# use an instance object rather than a dict
instance = self._create_fake_instance()
inst_obj = instance_obj.Instance._from_db_object(
self.context, instance_obj.Instance(), instance)
self.mox.StubOutWithMock(self.conductor_manager.compute_api,
'confirm_resize')
# make sure the instance object is serialized
primitive_instance = dict(inst_obj.items())
self.conductor_manager.compute_api.confirm_resize(
self.context, primitive_instance, 'migration')
self.mox.ReplayAll()
self.conductor.compute_confirm_resize(self.context, inst_obj,
'migration')
class ConductorRPCAPITestCase(_BaseTestCase, test.TestCase):
"""Conductor RPC API Tests."""