diff options
| author | Eldar Nugaev <enugaev@griddynamics.com> | 2011-04-21 04:20:19 +0400 |
|---|---|---|
| committer | Eldar Nugaev <enugaev@griddynamics.com> | 2011-04-21 04:20:19 +0400 |
| commit | 5fc608bb60dc9c086d8c2c7ac69c0dd6719c061f (patch) | |
| tree | b62c782a52dc4634553dbfc39ee473a3268f131d /nova | |
| parent | fe23f71687e09248feb7542ea97001a496697742 (diff) | |
| parent | 7e345f07edc13ad7d56d50b67b089b16d860cb40 (diff) | |
revert changes that doesn't affect the bug
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/openstack/servers.py | 67 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_extensions.py | 1 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_servers.py | 4 |
3 files changed, 41 insertions, 31 deletions
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py index e0681e597..22a9c632c 100644 --- a/nova/api/openstack/servers.py +++ b/nova/api/openstack/servers.py @@ -294,47 +294,61 @@ class Controller(common.OpenstackController): 'revertResize': self._action_revert_resize, 'rebuild': self._action_rebuild, } + input_dict = self._deserialize(req.body, req.get_content_type()) for key in actions.keys(): if key in input_dict: - try: - context = req.environ['nova.context'] - return actions[key](context, input_dict, id) - except Exception, e: - LOG.exception(_("Error in action %(key)s: %(e)s") % - locals()) - return faults.Fault(exc.HTTPBadRequest()) + return actions[key](input_dict, req, id) return faults.Fault(exc.HTTPNotImplemented()) - def _action_change_password(self, context, input_dict, id): + def _action_change_password(self, input_dict, req, id): return exc.HTTPNotImplemented() - def _action_confirm_resize(self, context, input_dict, id): - self.compute_api.confirm_resize(context, id) + def _action_confirm_resize(self, input_dict, req, id): + try: + self.compute_api.confirm_resize(req.environ['nova.context'], id) + except Exception, e: + LOG.exception(_("Error in confirm-resize %s"), e) + return faults.Fault(exc.HTTPBadRequest()) return exc.HTTPNoContent() - def _action_revert_resize(self, context, input_dict, id): - self.compute_api.revert_resize(context, id) + def _action_revert_resize(self, input_dict, req, id): + try: + self.compute_api.revert_resize(req.environ['nova.context'], id) + except Exception, e: + LOG.exception(_("Error in revert-resize %s"), e) + return faults.Fault(exc.HTTPBadRequest()) return exc.HTTPAccepted() - def _action_rebuild(self, context, input_dict, id): + def _action_rebuild(self, input_dict, req, id): return faults.Fault(exc.HTTPNotImplemented()) - def _action_resize(self, context, input_dict, id): + def _action_resize(self, input_dict, req, id): """ Resizes a given instance to the flavor size requested """ - if 'resize' in input_dict and 'flavorId' in input_dict['resize']: - flavor_id = input_dict['resize']['flavorId'] - self.compute_api.resize(context, id, flavor_id) - else: - LOG.exception(_("Missing arguments for resize")) - return faults.Fault(exc.HTTPUnprocessableEntity()) + try: + if 'resize' in input_dict and 'flavorId' in input_dict['resize']: + flavor_id = input_dict['resize']['flavorId'] + self.compute_api.resize(req.environ['nova.context'], id, + flavor_id) + else: + LOG.exception(_("Missing arguments for resize")) + return faults.Fault(exc.HTTPUnprocessableEntity()) + except Exception, e: + LOG.exception(_("Error in resize %s"), e) + return faults.Fault(exc.HTTPBadRequest()) return faults.Fault(exc.HTTPAccepted()) - def _action_reboot(self, context, input_dict, id): - reboot_type = input_dict['reboot']['type'] - # TODO(gundlach): pass reboot_type, support soft reboot in - # virt driver - self.compute_api.reboot(context, id) + def _action_reboot(self, input_dict, req, id): + try: + reboot_type = input_dict['reboot']['type'] + except Exception: + raise faults.Fault(exc.HTTPNotImplemented()) + try: + # TODO(gundlach): pass reboot_type, support soft reboot in + # virt driver + self.compute_api.reboot(req.environ['nova.context'], id) + except: + return faults.Fault(exc.HTTPUnprocessableEntity()) return exc.HTTPAccepted() @scheduler_api.redirect_handler @@ -618,7 +632,8 @@ class ControllerV11(Controller): def _get_addresses_view_builder(self, req): return nova.api.openstack.views.addresses.ViewBuilderV11(req) - def _action_change_password(self, context, input_dict, id): + def _action_change_password(self, input_dict, req, id): + context = req.environ['nova.context'] if (not 'changePassword' in input_dict or not 'adminPass' in input_dict['changePassword']): msg = _("No adminPass was specified") diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index 6453e96c9..481d34ed1 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -158,7 +158,6 @@ class ActionExtensionTest(unittest.TestCase): request.method = 'POST' request.content_type = 'application/json' request.body = json.dumps(body) - request.environ = {'nova.context': 'context'} response = request.get_response(ext_midware) return response diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index a92da52b1..556046e9d 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -952,7 +952,6 @@ class ServersTest(test.TestCase): req.method = 'POST' req.content_type = 'application/json' req.body = json.dumps(body) - req.environ = {"nova.context": "context"} res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 501) @@ -974,7 +973,6 @@ class ServersTest(test.TestCase): req.method = 'POST' req.content_type = 'application/json' req.body = json.dumps(body) - req.environ = {"nova.context": "context"} res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 202) self.assertEqual(mock_method.instance_id, '1') @@ -995,7 +993,6 @@ class ServersTest(test.TestCase): req.method = 'POST' req.content_type = 'application/json' req.body = json.dumps(body) - req.environ = {"nova.context": "context"} res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) @@ -1005,7 +1002,6 @@ class ServersTest(test.TestCase): req.method = 'POST' req.content_type = 'application/json' req.body = json.dumps(body) - req.environ = {"nova.context": "context"} res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) |
