diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-01-25 15:20:08 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-01-25 15:20:08 +0000 |
| commit | 30ac47bcbd8af06ed6a3ccdca552747c00381829 (patch) | |
| tree | 5933eeadb4546cde8166d2098780d0804bd168cf | |
| parent | 99daaea663ade3839142f538427faa85d0e64c8f (diff) | |
| parent | 2cf8b77c6933a5294c6f75591544651bee36c9a0 (diff) | |
Merge "blueprint host-aggregates: maintenance operations to host OSAPI exts"
| -rw-r--r-- | Authors | 1 | ||||
| -rw-r--r-- | nova/api/openstack/compute/contrib/hosts.py | 8 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_hosts.py | 43 |
3 files changed, 49 insertions, 3 deletions
@@ -74,6 +74,7 @@ Joe Heck <heckj@mac.com> Joel Moore <joelbm24@gmail.com> Johannes Erdfelt <johannes.erdfelt@rackspace.com> John Dewey <john@dewey.ws> +John Garbutt <john.garbutt@citrix.com> John Tran <jtran@attinteractive.com> Jonathan Bryce <jbryce@jbryce.com> Jordan Rinke <jordan@openstack.org> diff --git a/nova/api/openstack/compute/contrib/hosts.py b/nova/api/openstack/compute/contrib/hosts.py index 6ee89859b..b522e6a98 100644 --- a/nova/api/openstack/compute/contrib/hosts.py +++ b/nova/api/openstack/compute/contrib/hosts.py @@ -53,6 +53,7 @@ class HostUpdateTemplate(xmlutil.TemplateBuilder): root = xmlutil.TemplateElement('host') root.set('host') root.set('status') + root.set('maintenance_mode') return xmlutil.MasterTemplate(root, 1) @@ -128,15 +129,18 @@ class HostController(object): # settings may follow. if key == "status": if val[:6] in ("enable", "disabl"): - return self._set_enabled_status(req, id, - enabled=(val.startswith("enable"))) + enabled = val.startswith("enable") else: explanation = _("Invalid status: '%s'") % raw_val raise webob.exc.HTTPBadRequest(explanation=explanation) + elif key == "maintenance_mode": + raise webob.exc.HTTPNotImplemented else: explanation = _("Invalid update setting: '%s'") % raw_key raise webob.exc.HTTPBadRequest(explanation=explanation) + return self._set_enabled_status(req, id, enabled=enabled) + def _set_enabled_status(self, req, host, enabled): """Sets the specified host's ability to accept new instances.""" context = req.environ['nova.context'] diff --git a/nova/tests/api/openstack/compute/contrib/test_hosts.py b/nova/tests/api/openstack/compute/contrib/test_hosts.py index af4818c90..f0547eff7 100644 --- a/nova/tests/api/openstack/compute/contrib/test_hosts.py +++ b/nova/tests/api/openstack/compute/contrib/test_hosts.py @@ -93,6 +93,18 @@ class HostTestCase(test.TestCase): result_c2 = self.controller.update(self.req, "host_c2", body=en_body) self.assertEqual(result_c2["status"], "disabled") + def test_enable_maintainance_mode(self): + body = {"maintenance_mode": "enable"} + self.assertRaises(webob.exc.HTTPNotImplemented, + self.controller.update, + self.req, "host_c1", body=body) + + def test_disable_maintainance_mode_and_enable(self): + body = {"status": "enable", "maintenance_mode": "disable"} + self.assertRaises(webob.exc.HTTPNotImplemented, + self.controller.update, + self.req, "host_c1", body=body) + def test_host_startup(self): result = self.controller.startup(self.req, "host_c1") self.assertEqual(result["power_action"], "startup") @@ -115,6 +127,11 @@ class HostTestCase(test.TestCase): self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, self.req, "host_c1", body=bad_body) + def test_bad_update_key_and_correct_udpate_key(self): + bad_body = {"status": "disable", "crazy": "bad"} + self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, + self.req, "host_c1", body=bad_body) + def test_bad_host(self): self.assertRaises(exception.HostNotFound, self.controller.update, self.req, "bogus_host_name", body={"status": "disable"}) @@ -140,7 +157,7 @@ class HostSerializerTest(test.TestCase): self.assertEqual(HOST_LIST[i]['service'], tree[i].get('service')) - def test_update_serializer(self): + def test_update_serializer_with_status(self): exemplar = dict(host='host_c1', status='enabled') serializer = os_hosts.HostUpdateTemplate() text = serializer.serialize(exemplar) @@ -151,6 +168,30 @@ class HostSerializerTest(test.TestCase): for key, value in exemplar.items(): self.assertEqual(value, tree.get(key)) + def test_update_serializer_with_maintainance_mode(self): + exemplar = dict(host='host_c1', maintenance_mode='enabled') + serializer = os_hosts.HostUpdateTemplate() + text = serializer.serialize(exemplar) + + tree = etree.fromstring(text) + + self.assertEqual('host', tree.tag) + for key, value in exemplar.items(): + self.assertEqual(value, tree.get(key)) + + def test_update_serializer_with_maintainance_mode_and_status(self): + exemplar = dict(host='host_c1', + maintenance_mode='enabled', + status='enabled') + serializer = os_hosts.HostUpdateTemplate() + text = serializer.serialize(exemplar) + + tree = etree.fromstring(text) + + self.assertEqual('host', tree.tag) + for key, value in exemplar.items(): + self.assertEqual(value, tree.get(key)) + def test_action_serializer(self): exemplar = dict(host='host_c1', power_action='reboot') serializer = os_hosts.HostActionTemplate() |
