summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-07-26 16:30:14 -0400
committerRussell Bryant <rbryant@redhat.com>2012-07-26 18:46:32 -0400
commit2203249e190535aff7799a689effff77743fba61 (patch)
tree21df2a1d3b69bd7551138c26892edb0a580008c5
parent6fa8a0860dace7ba71f32207375d82387bbbbb68 (diff)
Send a full instance via rpc for inject_network_info.
Change the inject_network_info method of the compute rpc API to take a full instance over rpc instead of just the instance UUID. This cuts down on database access needed by nova-compute. Part of blueprint no-db-messaging. Change-Id: I1bcf55e2819be321c3ea0a64fe136cd993a2443b
-rw-r--r--nova/compute/manager.py16
-rw-r--r--nova/compute/rpcapi.py8
-rw-r--r--nova/tests/compute/test_compute.py4
-rw-r--r--nova/tests/compute/test_rpcapi.py4
4 files changed, 19 insertions, 13 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 9461faf52..ae47b6caa 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -298,7 +298,7 @@ def _get_additional_capabilities():
class ComputeManager(manager.SchedulerDependentManager):
"""Manages the running instances from creation to destruction."""
- RPC_API_VERSION = '1.18'
+ RPC_API_VERSION = '1.19'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@@ -1690,7 +1690,7 @@ class ComputeManager(manager.SchedulerDependentManager):
instance,
network_id)
- network_info = self._inject_network_info(context, instance['uuid'])
+ network_info = self._inject_network_info(context, instance=instance)
self.reset_network(context, instance['uuid'])
self._notify_about_instance_usage(
@@ -1712,7 +1712,8 @@ class ComputeManager(manager.SchedulerDependentManager):
instance_ref,
address)
- network_info = self._inject_network_info(context, instance_ref['uuid'])
+ network_info = self._inject_network_info(context,
+ instance=instance_ref)
self.reset_network(context, instance_ref['uuid'])
self._notify_about_instance_usage(
@@ -1878,9 +1879,8 @@ class ComputeManager(manager.SchedulerDependentManager):
LOG.debug(_('Reset network'), context=context, instance=instance)
self.driver.reset_network(instance)
- def _inject_network_info(self, context, instance_uuid):
+ def _inject_network_info(self, context, instance):
"""Inject network info for the given instance."""
- instance = self.db.instance_get_by_uuid(context, instance_uuid)
LOG.debug(_('Inject network info'), context=context, instance=instance)
network_info = self._get_instance_nw_info(context, instance)
@@ -1893,9 +1893,11 @@ class ComputeManager(manager.SchedulerDependentManager):
@checks_instance_lock
@wrap_instance_fault
- def inject_network_info(self, context, instance_uuid):
+ def inject_network_info(self, context, instance=None, instance_uuid=None):
"""Inject network info, but don't return the info."""
- self._inject_network_info(context, instance_uuid)
+ if not instance:
+ instance = self.db.instance_get_by_uuid(context, instance_uuid)
+ self._inject_network_info(context, instance)
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
@wrap_instance_fault
diff --git a/nova/compute/rpcapi.py b/nova/compute/rpcapi.py
index 70747e5cc..4b012de78 100644
--- a/nova/compute/rpcapi.py
+++ b/nova/compute/rpcapi.py
@@ -80,6 +80,8 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
1.16 - Remove instance_uuid, add instance argument to get_diagnostics()
1.17 - Remove instance_uuid, add instance argument to get_vnc_console()
1.18 - Remove instance_uuid, add instance argument to inject_file()
+ 1.19 - Remove instance_uuid, add instance argument to
+ inject_network_info()
'''
BASE_RPC_API_VERSION = '1.0'
@@ -224,9 +226,11 @@ class ComputeAPI(nova.openstack.common.rpc.proxy.RpcProxy):
version='1.18')
def inject_network_info(self, ctxt, instance):
+ instance_p = jsonutils.to_primitive(instance)
self.cast(ctxt, self.make_msg('inject_network_info',
- instance_uuid=instance['uuid']),
- topic=_compute_topic(self.topic, ctxt, None, instance))
+ instance=instance),
+ topic=_compute_topic(self.topic, ctxt, None, instance),
+ version='1.19')
def post_live_migration_at_destination(self, ctxt, instance,
block_migration, host):
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index c6d349057..76b3666a7 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -699,10 +699,10 @@ class ComputeTestCase(BaseTestCase):
self.stubs.Set(nova.virt.fake.FakeDriver, 'inject_network_info',
fake_driver_inject_network)
- instance = self._create_fake_instance()
+ instance = jsonutils.to_primitive(self._create_fake_instance())
instance_uuid = instance['uuid']
self.compute.run_instance(self.context, instance_uuid)
- self.compute.inject_network_info(self.context, instance_uuid)
+ self.compute.inject_network_info(self.context, instance=instance)
self.assertTrue(called['inject'])
self.compute.terminate_instance(self.context, instance_uuid)
diff --git a/nova/tests/compute/test_rpcapi.py b/nova/tests/compute/test_rpcapi.py
index fd4b5eb4e..181fbfa91 100644
--- a/nova/tests/compute/test_rpcapi.py
+++ b/nova/tests/compute/test_rpcapi.py
@@ -54,7 +54,7 @@ class ComputeRpcAPITestCase(test.TestCase):
'check_can_live_migrate_source', 'confirm_resize',
'detach_volume', 'finish_resize', 'finish_revert_resize',
'get_console_output', 'get_diagnostics', 'get_vnc_console',
- 'inject_file',
+ 'inject_file', 'inject_network_info',
'pause_instance', 'reboot_instance', 'suspend_instance',
'unpause_instance'
]
@@ -204,7 +204,7 @@ class ComputeRpcAPITestCase(test.TestCase):
def test_inject_network_info(self):
self._test_compute_api('inject_network_info', 'cast',
- instance=self.fake_instance)
+ instance=self.fake_instance, version='1.19')
def test_post_live_migration_at_destination(self):
self._test_compute_api('post_live_migration_at_destination', 'call',