Cells: Send instance object for instance_delete_everywhere
The delete method in the compute api expects an instance object to be passed in. So the instance object needs to not be to_primitived in the instance_delete_everywhere rpc method. Change-Id: I620ec57bc28ba11335758455c7cac0bfa63f5b37 Closes-bug: #1293750
This commit is contained in:
parent
5cdf602c37
commit
8e3dc81837
@ -28,6 +28,7 @@ from nova.cells import utils as cells_utils
|
||||
from nova import context
|
||||
from nova import exception
|
||||
from nova import manager
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import importutils
|
||||
from nova.openstack.common import log as logging
|
||||
@ -71,7 +72,7 @@ class CellsManager(manager.Manager):
|
||||
Scheduling requests get passed to the scheduler class.
|
||||
"""
|
||||
|
||||
target = oslo_messaging.Target(version='1.26')
|
||||
target = oslo_messaging.Target(version='1.27')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
LOG.warn(_('The cells feature of Nova is considered experimental '
|
||||
@ -233,6 +234,9 @@ class CellsManager(manager.Manager):
|
||||
an instance was in, but the instance was requested to be
|
||||
deleted or soft_deleted. So, we'll broadcast this everywhere.
|
||||
"""
|
||||
if isinstance(instance, dict):
|
||||
instance = instance_obj.Instance._from_db_object(ctxt,
|
||||
instance_obj.Instance(), instance)
|
||||
self.msg_runner.instance_delete_everywhere(ctxt, instance,
|
||||
delete_type)
|
||||
|
||||
|
@ -89,6 +89,7 @@ class CellsAPI(object):
|
||||
|
||||
1.25 - Adds rebuild_instance()
|
||||
1.26 - Adds service_delete()
|
||||
1.27 - Updates instance_delete_everywhere() for instance objects
|
||||
'''
|
||||
|
||||
VERSION_ALIASES = {
|
||||
@ -168,9 +169,14 @@ class CellsAPI(object):
|
||||
"""
|
||||
if not CONF.cells.enable:
|
||||
return
|
||||
instance_p = jsonutils.to_primitive(instance)
|
||||
self.client.cast(ctxt, 'instance_delete_everywhere',
|
||||
instance=instance_p, delete_type=delete_type)
|
||||
if self.client.can_send_version('1.27'):
|
||||
version = '1.27'
|
||||
else:
|
||||
version = '1.0'
|
||||
instance = jsonutils.to_primitive(instance)
|
||||
cctxt = self.client.prepare(version=version)
|
||||
cctxt.cast(ctxt, 'instance_delete_everywhere', instance=instance,
|
||||
delete_type=delete_type)
|
||||
|
||||
def instance_fault_create_at_top(self, ctxt, instance_fault):
|
||||
"""Create an instance fault at the top."""
|
||||
|
@ -22,6 +22,7 @@ import six
|
||||
from nova.cells import rpcapi as cells_rpcapi
|
||||
from nova import exception
|
||||
from nova import test
|
||||
from nova.tests import fake_instance
|
||||
|
||||
CONF = cfg.CONF
|
||||
CONF.import_opt('topic', 'nova.cells.opts', group='cells')
|
||||
@ -40,11 +41,16 @@ class CellsAPITestCase(test.NoDBTestCase):
|
||||
def _stub_rpc_method(self, rpc_method, result):
|
||||
call_info = {}
|
||||
|
||||
orig_prepare = self.cells_rpcapi.client.prepare
|
||||
|
||||
def fake_rpc_prepare(**kwargs):
|
||||
if 'version' in kwargs:
|
||||
call_info['version'] = kwargs.pop('version')
|
||||
return self.cells_rpcapi.client
|
||||
|
||||
def fake_csv(version):
|
||||
return orig_prepare(version).can_send_version()
|
||||
|
||||
def fake_rpc_method(ctxt, method, **kwargs):
|
||||
call_info['context'] = ctxt
|
||||
call_info['method'] = method
|
||||
@ -52,6 +58,7 @@ class CellsAPITestCase(test.NoDBTestCase):
|
||||
return result
|
||||
|
||||
self.stubs.Set(self.cells_rpcapi.client, 'prepare', fake_rpc_prepare)
|
||||
self.stubs.Set(self.cells_rpcapi.client, 'can_send_version', fake_csv)
|
||||
self.stubs.Set(self.cells_rpcapi.client, rpc_method, fake_rpc_method)
|
||||
|
||||
return call_info
|
||||
@ -195,18 +202,18 @@ class CellsAPITestCase(test.NoDBTestCase):
|
||||
expected_args)
|
||||
|
||||
def test_instance_delete_everywhere(self):
|
||||
fake_instance = {'uuid': 'fake-uuid'}
|
||||
instance = fake_instance.fake_instance_obj(self.fake_context)
|
||||
|
||||
call_info = self._stub_rpc_method('cast', None)
|
||||
|
||||
self.cells_rpcapi.instance_delete_everywhere(
|
||||
self.fake_context, fake_instance,
|
||||
self.fake_context, instance,
|
||||
'fake-type')
|
||||
|
||||
expected_args = {'instance': fake_instance,
|
||||
expected_args = {'instance': instance,
|
||||
'delete_type': 'fake-type'}
|
||||
self._check_result(call_info, 'instance_delete_everywhere',
|
||||
expected_args)
|
||||
expected_args, version='1.27')
|
||||
|
||||
def test_instance_fault_create_at_top(self):
|
||||
fake_instance_fault = {'id': 2,
|
||||
|
Loading…
Reference in New Issue
Block a user