Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 NEC Corporation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 19 | from tempest import exceptions |
| 20 | from tempest.test import attr |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class InstanceActionsTestJSON(base.BaseComputeTest): |
| 24 | _interface = 'json' |
| 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(InstanceActionsTestJSON, cls).setUpClass() |
| 29 | cls.client = cls.servers_client |
| 30 | resp, server = cls.create_server(wait_until='ACTIVE') |
| 31 | cls.request_id = resp['x-compute-request-id'] |
| 32 | cls.server_id = server['id'] |
| 33 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 34 | @attr(type=['positive', 'gate']) |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 35 | def test_list_instance_actions(self): |
| 36 | # List actions of the provided server |
| 37 | resp, body = self.client.reboot(self.server_id, 'HARD') |
| 38 | self.client.wait_for_server_status(self.server_id, 'ACTIVE') |
| 39 | |
| 40 | resp, body = self.client.list_instance_actions(self.server_id) |
| 41 | self.assertEqual(200, resp.status) |
| 42 | self.assertTrue(len(body) == 2) |
| 43 | self.assertTrue(any([i for i in body if i['action'] == 'create'])) |
| 44 | self.assertTrue(any([i for i in body if i['action'] == 'reboot'])) |
| 45 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 46 | @attr(type=['positive', 'gate']) |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 47 | def test_get_instance_action(self): |
| 48 | # Get the action details of the provided server |
| 49 | resp, body = self.client.get_instance_action(self.server_id, |
| 50 | self.request_id) |
| 51 | self.assertEqual(200, resp.status) |
| 52 | self.assertEqual(self.server_id, body['instance_uuid']) |
| 53 | self.assertEqual('create', body['action']) |
| 54 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 55 | @attr(type=['negative', 'gate']) |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 56 | def test_list_instance_actions_invalid_server(self): |
| 57 | # List actions of the invalid server id |
| 58 | self.assertRaises(exceptions.NotFound, |
| 59 | self.client.list_instance_actions, 'server-999') |
| 60 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 61 | @attr(type=['negative', 'gate']) |
Leo Toyoda | faca6ff | 2013-04-22 16:52:53 +0900 | [diff] [blame] | 62 | def test_get_instance_action_invalid_request(self): |
| 63 | # Get the action details of the provided server with invalid request |
| 64 | self.assertRaises(exceptions.NotFound, self.client.get_instance_action, |
| 65 | self.server_id, '999') |
| 66 | |
| 67 | |
| 68 | class InstanceActionsTestXML(InstanceActionsTestJSON): |
| 69 | _interface = 'xml' |