diff options
| author | Jenkins <jenkins@review.openstack.org> | 2011-12-22 18:53:59 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2011-12-22 18:53:59 +0000 |
| commit | 460dee919eb1be42de147e9cd8279d7fa61394ba (patch) | |
| tree | 33f2ac72542922a5ab0e92f6cb14c79fa1baedde /nova/tests | |
| parent | c83a672d691ec72b3ce832d57e37864f86d0e627 (diff) | |
| parent | 74390d4920e692e7c85462232a6256774c6eabae (diff) | |
Merge "Move 'actions' subresource into extension"
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/v2/contrib/test_server_action_list.py | 65 | ||||
| -rw-r--r-- | nova/tests/api/openstack/v2/test_extensions.py | 1 | ||||
| -rw-r--r-- | nova/tests/api/openstack/v2/test_servers.py | 36 |
3 files changed, 66 insertions, 36 deletions
diff --git a/nova/tests/api/openstack/v2/contrib/test_server_action_list.py b/nova/tests/api/openstack/v2/contrib/test_server_action_list.py new file mode 100644 index 000000000..c6a185e56 --- /dev/null +++ b/nova/tests/api/openstack/v2/contrib/test_server_action_list.py @@ -0,0 +1,65 @@ +# Copyright 2011 Eldar Nugaev +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import datetime +import json + +from nova.api.openstack import v2 +from nova.api.openstack.v2 import extensions +from nova.api.openstack import wsgi +import nova.compute +from nova import test +from nova.tests.api.openstack import fakes +import nova.utils + + +dt = datetime.datetime.utcnow() + + +def fake_get_actions(self, _context, instance_uuid): + return [ + {'action': 'rebuild', 'error': None, 'created_at': dt}, + {'action': 'reboot', 'error': 'Failed!', 'created_at': dt}, + ] + + +def fake_instance_get(self, _context, instance_uuid): + return {'uuid': instance_uuid} + + +class ServerDiagnosticsTest(test.TestCase): + + def setUp(self): + super(ServerDiagnosticsTest, self).setUp() + self.flags(allow_admin_api=True) + self.flags(verbose=True) + self.stubs.Set(nova.compute.API, 'get_actions', fake_get_actions) + self.stubs.Set(nova.compute.API, 'get', fake_instance_get) + self.compute_api = nova.compute.API() + + self.router = v2.APIRouter() + ext_middleware = extensions.ExtensionMiddleware(self.router) + self.app = wsgi.LazySerializationMiddleware(ext_middleware) + + def test_get_actions(self): + uuid = nova.utils.gen_uuid() + req = fakes.HTTPRequest.blank('/fake/servers/%s/actions' % uuid) + res = req.get_response(self.app) + output = json.loads(res.body) + expected = {'actions': [ + {'action': 'rebuild', 'error': None, 'created_at': str(dt)}, + {'action': 'reboot', 'error': 'Failed!', 'created_at': str(dt)}, + ]} + self.assertEqual(output, expected) diff --git a/nova/tests/api/openstack/v2/test_extensions.py b/nova/tests/api/openstack/v2/test_extensions.py index 5c5bf1adf..2063e6e2d 100644 --- a/nova/tests/api/openstack/v2/test_extensions.py +++ b/nova/tests/api/openstack/v2/test_extensions.py @@ -114,6 +114,7 @@ class ExtensionControllerTest(ExtensionTestCase): "Quotas", "Rescue", "SecurityGroups", + "ServerActionList", "ServerDiagnostics", "SimpleTenantUsage", "VSAs", diff --git a/nova/tests/api/openstack/v2/test_servers.py b/nova/tests/api/openstack/v2/test_servers.py index e29049ef7..03627c833 100644 --- a/nova/tests/api/openstack/v2/test_servers.py +++ b/nova/tests/api/openstack/v2/test_servers.py @@ -154,19 +154,6 @@ def fake_compute_api(cls, req, id): return True -_fake_compute_actions = [ - dict( - created_at=str(datetime.datetime(2010, 11, 11, 11, 0, 0)), - action='Fake Action', - error='Fake Error', - ) - ] - - -def fake_compute_actions(_1, _2, _3): - return [InstanceActions(**a) for a in _fake_compute_actions] - - def find_host(self, context, instance_id): return "nova" @@ -205,7 +192,6 @@ class ServersControllerTest(test.TestCase): instance_addresses) self.stubs.Set(nova.db, 'instance_get_floating_address', instance_addresses) - self.stubs.Set(nova.compute.API, "get_actions", fake_compute_actions) self.config_drive = None @@ -1167,28 +1153,6 @@ class ServersControllerTest(test.TestCase): self.assertEqual(s['status'], 'BUILD') self.assertEqual(s['metadata']['seq'], str(i)) - def test_server_actions(self): - req = fakes.HTTPRequest.blank( - "/v2/fake/servers/%s/actions" % FAKE_UUID) - res_dict = self.controller.actions(req, FAKE_UUID) - self.assertEqual(res_dict, {'actions': _fake_compute_actions}) - - def test_server_actions_after_reboot(self): - """ - Bug #897091 was this failure mode -- the /actions call failed if - /action had been called first. - """ - body = dict(reboot=dict(type="HARD")) - req = fakes.HTTPRequest.blank( - '/v2/fake/servers/%s/action' % FAKE_UUID) - # Assume the instance is in ACTIVE state before calling reboot - self.stubs.Set(nova.db, 'instance_get', - return_server_with_state(vm_states.ACTIVE)) - self.stubs.Set(nova.db, 'instance_get_by_uuid', - return_server_with_state(vm_states.ACTIVE)) - self.controller.action(req, FAKE_UUID, body) - self.test_server_actions() - def test_get_all_server_details_with_host(self): ''' We want to make sure that if two instances are on the same host, then |
