diff options
| author | Alex Meade <alex.meade@rackspace.com> | 2011-11-23 15:56:46 -0500 |
|---|---|---|
| committer | Alex Meade <alex.meade@rackspace.com> | 2011-11-23 15:56:46 -0500 |
| commit | ee3a4dfd50dc5a69e5d23387fd57dbddfb21173b (patch) | |
| tree | aa2b77113c739d268449cecf8441a2099dff28bb | |
| parent | 1670bccfa42c48e964c691e94c76359d56a73e59 (diff) | |
| download | nova-ee3a4dfd50dc5a69e5d23387fd57dbddfb21173b.tar.gz nova-ee3a4dfd50dc5a69e5d23387fd57dbddfb21173b.tar.xz nova-ee3a4dfd50dc5a69e5d23387fd57dbddfb21173b.zip | |
reset/inject network info in compute to use uuid
Related to blueprint internal-uuids.
Change-Id: I88a3eadf0fb07b0a827039db757d00498dd1cd9c
| -rw-r--r-- | nova/compute/api.py | 7 | ||||
| -rw-r--r-- | nova/compute/manager.py | 28 | ||||
| -rw-r--r-- | nova/tests/test_compute.py | 48 |
3 files changed, 59 insertions, 24 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py index 60a54ae91..e7064e276 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -1514,13 +1514,12 @@ class API(base.Base): def reset_network(self, context, instance): """Reset networking on the instance.""" - instance_id = instance['id'] - self._cast_compute_message('reset_network', context, instance_id) + self._cast_compute_message('reset_network', context, instance['uuid']) def inject_network_info(self, context, instance): """Inject network info for the instance.""" - instance_id = instance['id'] - self._cast_compute_message('inject_network_info', context, instance_id) + self._cast_compute_message('inject_network_info', context, + instance['uuid']) def attach_volume(self, context, instance, volume_id, device): """Attach an existing volume to an existing instance.""" diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 2f0b0c71c..73089e97b 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1196,8 +1196,8 @@ class ComputeManager(manager.SchedulerDependentManager): 'compute.instance.create_ip', notifier.INFO, usage) - self.inject_network_info(context, instance_id) - self.reset_network(context, instance_id) + self.inject_network_info(context, instance_ref['uuid']) + self.reset_network(context, instance_ref['uuid']) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @checks_instance_lock @@ -1214,11 +1214,11 @@ class ComputeManager(manager.SchedulerDependentManager): 'compute.instance.delete_ip', notifier.INFO, usage) - self.inject_network_info(context, instance_id) - self.reset_network(context, instance_id) + self.inject_network_info(context, instance_ref['uuid']) + self.reset_network(context, instance_ref['uuid']) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) - @checks_instance_lock + @checks_instance_lock_uuid def pause_instance(self, context, instance_uuid): """Pause an instance on this host.""" LOG.audit(_('instance %s: pausing'), instance_uuid, context=context) @@ -1235,7 +1235,7 @@ class ComputeManager(manager.SchedulerDependentManager): task_state=None) @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) - @checks_instance_lock + @checks_instance_lock_uuid def unpause_instance(self, context, instance_uuid): """Unpause a paused instance on this host.""" LOG.audit(_('instance %s: unpausing'), instance_uuid, context=context) @@ -1333,20 +1333,20 @@ class ComputeManager(manager.SchedulerDependentManager): instance_ref = self.db.instance_get(context, instance_id) return instance_ref['locked'] - @checks_instance_lock - def reset_network(self, context, instance_id): + @checks_instance_lock_uuid + def reset_network(self, context, instance_uuid): """Reset networking on the given instance.""" - instance = self.db.instance_get(context, instance_id) - LOG.debug(_('instance %s: reset network'), instance_id, + instance = self.db.instance_get_by_uuid(context, instance_uuid) + LOG.debug(_('instance %s: reset network'), instance_uuid, context=context) self.driver.reset_network(instance) - @checks_instance_lock - def inject_network_info(self, context, instance_id): + @checks_instance_lock_uuid + def inject_network_info(self, context, instance_uuid): """Inject network info for the given instance.""" - LOG.debug(_('instance %s: inject network info'), instance_id, + LOG.debug(_('instance %s: inject network info'), instance_uuid, context=context) - instance = self.db.instance_get(context, instance_id) + instance = self.db.instance_get_by_uuid(context, instance_uuid) network_info = self._get_instance_nw_info(context, instance) LOG.debug(_("network_info to inject: |%s|"), network_info) diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 20db94f4e..bb8192f66 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -325,6 +325,42 @@ class ComputeTestCase(BaseTestCase): "File Contents") self.compute.terminate_instance(self.context, instance_id) + def test_inject_network_info(self): + """Ensure we can inject network info""" + called = {'inject': False} + + def fake_driver_inject_network(self, instance, network_info): + called['inject'] = True + + self.stubs.Set(nova.virt.fake.FakeConnection, 'inject_network_info', + fake_driver_inject_network) + + instance = self._create_fake_instance() + instance_id = instance['id'] + instance_uuid = instance['uuid'] + self.compute.run_instance(self.context, instance_id) + self.compute.inject_network_info(self.context, instance_uuid) + self.assertTrue(called['inject']) + self.compute.terminate_instance(self.context, instance_id) + + def test_reset_network(self): + """Ensure we can reset networking on an instance""" + called = {'reset': False} + + def fake_driver_reset_network(self, instance): + called['reset'] = True + + self.stubs.Set(nova.virt.fake.FakeConnection, 'reset_network', + fake_driver_reset_network) + + instance = self._create_fake_instance() + instance_id = instance['id'] + instance_uuid = instance['uuid'] + self.compute.run_instance(self.context, instance_id) + self.compute.reset_network(self.context, instance_uuid) + self.assertTrue(called['reset']) + self.compute.terminate_instance(self.context, instance_id) + def test_agent_update(self): """Ensure instance can have its agent updated""" instance_id = self._create_instance() @@ -2137,16 +2173,16 @@ class ComputeAPITestCase(BaseTestCase): self.compute_api.attach_volume(self.context, instance, 1, '/dev/vdb') def test_inject_network_info(self): - instance_id = self._create_instance() - self.compute.run_instance(self.context, instance_id) - instance = self.compute_api.get(self.context, instance_id) + instance = self._create_fake_instance() + self.compute.run_instance(self.context, instance['id']) + instance = self.compute_api.get(self.context, instance['uuid']) self.compute_api.inject_network_info(self.context, instance) self.compute_api.delete(self.context, instance) def test_reset_network(self): - instance_id = self._create_instance() - self.compute.run_instance(self.context, instance_id) - instance = self.compute_api.get(self.context, instance_id) + instance = self._create_fake_instance() + self.compute.run_instance(self.context, instance['id']) + instance = self.compute_api.get(self.context, instance['uuid']) self.compute_api.reset_network(self.context, instance) def test_lock(self): |
