summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJohannes Erdfelt <johannes.erdfelt@rackspace.com>2011-06-09 22:04:32 +0000
committerJohannes Erdfelt <johannes.erdfelt@rackspace.com>2011-06-09 22:04:32 +0000
commitfa0b64b500f3a196044459ba4bf8ed0dea214e92 (patch)
tree6719b496fdb1e3b7de3542ee0216fcefdb24debd /nova
parentfdb1e0e788398e1a29d08d6030709280ca93185c (diff)
Add test for agent update
Diffstat (limited to 'nova')
-rw-r--r--nova/compute/manager.py18
-rw-r--r--nova/tests/test_compute.py8
-rw-r--r--nova/virt/driver.py4
-rw-r--r--nova/virt/fake.py15
4 files changed, 45 insertions, 0 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 245958de7..3a91908af 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -472,6 +472,24 @@ class ComputeManager(manager.SchedulerDependentManager):
@exception.wrap_exception
@checks_instance_lock
+ def agent_update(self, context, instance_id, 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_state = instance_ref['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 '
+ 'expected: %(expected_state)s)') % locals())
+ nm = instance_ref['name']
+ msg = _('instance %(nm)s: updating agent to %(url)s') % locals()
+ LOG.audit(msg)
+ self.driver.agent_update(instance_ref, url, md5hash)
+
+ @exception.wrap_exception
+ @checks_instance_lock
def rescue_instance(self, context, instance_id):
"""Rescue an instance on this host."""
context = context.elevated()
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index b4ac2dbc4..dd06e5719 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -266,6 +266,14 @@ class ComputeTestCase(test.TestCase):
"File Contents")
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()
+ 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)
+
def test_snapshot(self):
"""Ensure instance can be snapshotted"""
instance_id = self._create_instance()
diff --git a/nova/virt/driver.py b/nova/virt/driver.py
index eb9626d08..2229291f2 100644
--- a/nova/virt/driver.py
+++ b/nova/virt/driver.py
@@ -234,6 +234,10 @@ class ComputeDriver(object):
"""
raise NotImplementedError()
+ def agent_update(self, instance, url, md5hash):
+ """Update agent on the VM instance."""
+ raise NotImplementedError()
+
def inject_network_info(self, instance):
"""inject network info for specified instance"""
raise NotImplementedError()
diff --git a/nova/virt/fake.py b/nova/virt/fake.py
index 0225797d7..22fbeefd2 100644
--- a/nova/virt/fake.py
+++ b/nova/virt/fake.py
@@ -225,6 +225,21 @@ class FakeConnection(driver.ComputeDriver):
"""
pass
+ def agent_update(self, instance, url, md5hash):
+ """
+ Update agent on the specified instance.
+
+ The first parameter is an instance of nova.compute.service.Instance,
+ and so the instance is being specified as instance.name. The second
+ parameter is the URL of the agent to be fetched and updated on the
+ instance; the third is the md5 hash of the file for verification
+ purposes.
+
+ The work will be done asynchronously. This function returns a
+ task that allows the caller to detect when it is complete.
+ """
+ pass
+
def rescue(self, instance):
"""
Rescue the specified instance.