diff options
| author | Ed Leafe <ed@leafe.com> | 2011-07-06 16:53:08 +0000 |
|---|---|---|
| committer | Ed Leafe <ed@leafe.com> | 2011-07-06 16:53:08 +0000 |
| commit | 6435ba27edea7e525305d349cafea3d08f5db2c6 (patch) | |
| tree | fa2dfd9d8717c535634a5a08550108c3c1b91b16 /nova | |
| parent | b02b1d78245634f81a27d0ba0a6e29024495c162 (diff) | |
Changed the exception type for invalid requests to webob.exc.HTTPBadRequest.
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/openstack/contrib/hosts.py | 12 | ||||
| -rw-r--r-- | nova/tests/test_hosts.py | 5 |
2 files changed, 10 insertions, 7 deletions
diff --git a/nova/api/openstack/contrib/hosts.py b/nova/api/openstack/contrib/hosts.py index 40a260c20..55e57e1a4 100644 --- a/nova/api/openstack/contrib/hosts.py +++ b/nova/api/openstack/contrib/hosts.py @@ -15,7 +15,7 @@ """The hosts admin extension.""" -from webob import exc +import webob.exc from nova import compute from nova import exception @@ -72,13 +72,15 @@ class HostController(object): # NOTE: (dabo) Right now only 'status' can be set, but other # actions may follow. if key == "status": - if val in ("enable", "disable"): + if val[:6] in ("enable", "disabl"): return self._set_enabled_status(req, id, - enabled=(val == "enable")) + enabled=(val.startswith("enable"))) else: - raise ValueError(_("Invalid status: '%s'") % raw_val) + explanation = _("Invalid status: '%s'") % raw_val + raise webob.exc.HTTPBadRequest(explanation=explanation) else: - raise ValueError(_("Invalid update setting: '%s'") % raw_key) + explanation = _("Invalid update setting: '%s'") % raw_key + raise webob.exc.HTTPBadRequest(explanation=explanation) def _set_enabled_status(self, req, host, enabled): """Sets the specified host's ability to accept new instances.""" diff --git a/nova/tests/test_hosts.py b/nova/tests/test_hosts.py index 9c3344873..c14ea349b 100644 --- a/nova/tests/test_hosts.py +++ b/nova/tests/test_hosts.py @@ -14,6 +14,7 @@ # under the License. import stubout +import webob.exc from nova import context from nova import exception @@ -88,12 +89,12 @@ class HostTestCase(test.TestCase): def test_bad_status_value(self): bad_body = {"status": "bad"} - self.assertRaises(ValueError, self.controller.update, self.req, + self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, self.req, "host_c1", body=bad_body) def test_bad_update_key(self): bad_body = {"crazy": "bad"} - self.assertRaises(ValueError, self.controller.update, self.req, + self.assertRaises(webob.exc.HTTPBadRequest, self.controller.update, self.req, "host_c1", body=bad_body) def test_bad_host(self): |
