From 2cf8b77c6933a5294c6f75591544651bee36c9a0 Mon Sep 17 00:00:00 2001 From: John Garbutt Date: Thu, 19 Jan 2012 17:04:36 +0000 Subject: blueprint host-aggregates: maintenance operations to host OSAPI exts This commit introduces sub for a host maintenance_mode option into the osapi. It is required for the host aggregates work. This is part of a series of commits that have started with change: https://review.openstack.org/#change,3035 Change-Id: Ib462ef9ad6b641bf1083cc176dfba6645020ccec --- Authors | 1 + nova/api/openstack/compute/contrib/hosts.py | 8 +++- .../api/openstack/compute/contrib/test_hosts.py | 43 +++++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/Authors b/Authors index 6a80ade28..34661e984 100644 --- a/Authors +++ b/Authors @@ -72,6 +72,7 @@ Joe Heck Joel Moore Johannes Erdfelt John Dewey +John Garbutt John Tran Jonathan Bryce Jordan Rinke diff --git a/nova/api/openstack/compute/contrib/hosts.py b/nova/api/openstack/compute/contrib/hosts.py index 66dd64def..726ccb372 100644 --- a/nova/api/openstack/compute/contrib/hosts.py +++ b/nova/api/openstack/compute/contrib/hosts.py @@ -52,6 +52,7 @@ class HostUpdateTemplate(xmlutil.TemplateBuilder): root = xmlutil.TemplateElement('host') root.set('host') root.set('status') + root.set('maintenance_mode') return xmlutil.MasterTemplate(root, 1) @@ -125,15 +126,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 e6a91477e..106420335 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): self.flags(allow_admin_api=True) result = self.controller.startup(self.req, "host_c1") @@ -118,6 +130,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"}) @@ -143,7 +160,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) @@ -154,6 +171,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() -- cgit