summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/compute/manager.py9
-rw-r--r--nova/tests/test_compute.py21
2 files changed, 20 insertions, 10 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 2eed738c1..db1eee6bf 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -921,17 +921,16 @@ class ComputeManager(manager.SchedulerDependentManager):
self.driver.inject_file(instance_ref, path, file_contents)
@exception.wrap_exception(notifier=notifier, publisher_id=publisher_id())
- @checks_instance_lock
- def agent_update(self, context, instance_id, url, md5hash):
+ @checks_instance_lock_uuid
+ def agent_update(self, context, instance_uuid, url, md5hash):
"""Update agent running on an instance on this host."""
context = context.elevated()
- instance_ref = self.db.instance_get(context, instance_id)
- instance_id = instance_ref['id']
+ instance_ref = self.db.instance_get_by_uuid(context, instance_uuid)
instance_state = instance_ref['power_state']
expected_state = power_state.RUNNING
if instance_state != expected_state:
LOG.warn(_('trying to update agent on a non-running '
- 'instance: %(instance_id)s (state: %(instance_state)s '
+ 'instance: %(instance_uuid)s (state: %(instance_state)s '
'expected: %(expected_state)s)') % locals())
nm = instance_ref['name']
msg = _('instance %(nm)s: updating agent to %(url)s') % locals()
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index f03665d57..5a5d1dd9a 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -396,11 +396,22 @@ class ComputeTestCase(BaseTestCase):
def test_agent_update(self):
"""Ensure instance can have its agent updated"""
- instance_id = self._create_instance()
- self.compute.run_instance(self.context, instance_id)
- self.compute.agent_update(self.context, instance_id,
- 'http://127.0.0.1/agent', '00112233445566778899aabbccddeeff')
- self.compute.terminate_instance(self.context, instance_id)
+ called = {'agent_update': False}
+
+ def fake_driver_agent_update(self2, instance, url, md5hash):
+ called['agent_update'] = True
+ self.assertEqual(url, 'http://fake/url/')
+ self.assertEqual(md5hash, 'fakehash')
+
+ self.stubs.Set(nova.virt.fake.FakeConnection, 'agent_update',
+ fake_driver_agent_update)
+
+ instance = self._create_fake_instance()
+ self.compute.run_instance(self.context, instance['id'])
+ self.compute.agent_update(self.context, instance['uuid'],
+ 'http://fake/url/', 'fakehash')
+ self.assertTrue(called['agent_update'])
+ self.compute.terminate_instance(self.context, instance['id'])
def test_snapshot(self):
"""Ensure instance can be snapshotted"""