summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-11-10 23:20:52 -0500
committerBrian Waldon <brian.waldon@rackspace.com>2011-11-15 09:02:25 -0800
commitd2db9790dd1c2f7a955236e01e37b579a2c87321 (patch)
tree5709f3a32683049662f32b23ecd9243970e01676
parent065a7ea03d97943cd669948ebaabd5271bf2afef (diff)
downloadnova-d2db9790dd1c2f7a955236e01e37b579a2c87321.tar.gz
nova-d2db9790dd1c2f7a955236e01e37b579a2c87321.tar.xz
nova-d2db9790dd1c2f7a955236e01e37b579a2c87321.zip
Converting lock/unlock to use instance objects
Related to blueprint internal-uuids Change-Id: I5a7842953da64cd2a060e5e384d06cdf535c7a1f
-rw-r--r--nova/api/openstack/contrib/admin_actions.py10
-rw-r--r--nova/compute/api.py15
-rw-r--r--nova/tests/test_compute.py19
3 files changed, 35 insertions, 9 deletions
diff --git a/nova/api/openstack/contrib/admin_actions.py b/nova/api/openstack/contrib/admin_actions.py
index 5e0c8571f..81b23a8a0 100644
--- a/nova/api/openstack/contrib/admin_actions.py
+++ b/nova/api/openstack/contrib/admin_actions.py
@@ -156,7 +156,10 @@ class Admin_actions(extensions.ExtensionDescriptor):
"""Permit admins to lock a server"""
context = req.environ['nova.context']
try:
- self.compute_api.lock(context, id)
+ instance = self.compute_api.get(context, id)
+ self.compute_api.lock(context, instance)
+ except exception.InstanceNotFound:
+ raise exc.HTTPNotFound(_("Server not found"))
except Exception:
readable = traceback.format_exc()
LOG.exception(_("Compute.api::lock %s"), readable)
@@ -170,7 +173,10 @@ class Admin_actions(extensions.ExtensionDescriptor):
"""Permit admins to lock a server"""
context = req.environ['nova.context']
try:
- self.compute_api.unlock(context, id)
+ instance = self.compute_api.get(context, id)
+ self.compute_api.unlock(context, instance)
+ except exception.InstanceNotFound:
+ raise exc.HTTPNotFound(_("Server not found"))
except Exception:
readable = traceback.format_exc()
LOG.exception(_("Compute.api::unlock %s"), readable)
diff --git a/nova/compute/api.py b/nova/compute/api.py
index a2ae3f5b8..1128da1de 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1506,18 +1506,19 @@ class API(base.Base):
context,
instance_id)
- def lock(self, context, instance_id):
+ def lock(self, context, instance):
"""Lock the given instance."""
- self._cast_compute_message('lock_instance', context, instance_id)
+ self._cast_compute_message('lock_instance', context, instance['uuid'])
- def unlock(self, context, instance_id):
+ def unlock(self, context, instance):
"""Unlock the given instance."""
- self._cast_compute_message('unlock_instance', context, instance_id)
+ self._cast_compute_message('unlock_instance',
+ context,
+ instance['uuid'])
- def get_lock(self, context, instance_id):
+ def get_lock(self, context, instance):
"""Return the boolean state of given instance's lock."""
- instance = self.get(context, instance_id)
- return instance['locked']
+ return self.get(context, instance['uuid'])['locked']
def reset_network(self, context, instance):
"""Reset networking on the instance."""
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 6ecf1a0f0..9e1887f4e 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -2021,6 +2021,25 @@ class ComputeAPITestCase(BaseTestCase):
self.compute.run_instance(self.context, instance_id)
instance = self.compute_api.get(self.context, instance_id)
self.compute_api.reset_network(self.context, instance)
+
+ def test_lock(self):
+ instance_id = self._create_instance()
+ instance = self.compute_api.get(self.context, instance_id)
+ self.compute_api.lock(self.context, instance)
+ self.compute_api.delete(self.context, instance)
+
+ def test_unlock(self):
+ instance_id = self._create_instance()
+ instance = self.compute_api.get(self.context, instance_id)
+ self.compute_api.unlock(self.context, instance)
+ self.compute_api.delete(self.context, instance)
+
+ def test_get_lock(self):
+ instance_id = self._create_instance()
+ instance = self.compute_api.get(self.context, instance_id)
+ self.assertFalse(self.compute_api.get_lock(self.context, instance))
+ db.instance_update(self.context, instance_id, {'locked': True})
+ self.assertTrue(self.compute_api.get_lock(self.context, instance))
self.compute_api.delete(self.context, instance)
def test_inject_file(self):