Tony Yang | 3d5f163 | 2013-06-06 14:17:57 +0800 | [diff] [blame^] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 IBM 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 | |
| 18 | from tempest.api.compute import base |
| 19 | from tempest import exceptions |
| 20 | from tempest.test import attr |
| 21 | |
| 22 | |
| 23 | class HypervisorAdminTestJSON(base.BaseComputeAdminTest): |
| 24 | |
| 25 | """ |
| 26 | Tests Hypervisors API that require admin privileges |
| 27 | """ |
| 28 | |
| 29 | _interface = 'json' |
| 30 | |
| 31 | @classmethod |
| 32 | def setUpClass(cls): |
| 33 | super(HypervisorAdminTestJSON, cls).setUpClass() |
| 34 | cls.client = cls.os_adm.hypervisor_client |
| 35 | cls.non_adm_client = cls.hypervisor_client |
| 36 | |
| 37 | def _list_hypervisors(self): |
| 38 | # List of hypervisors |
| 39 | resp, hypers = self.client.get_hypervisor_list() |
| 40 | self.assertEqual(200, resp.status) |
| 41 | return hypers |
| 42 | |
| 43 | @attr(type=['positive', 'gate']) |
| 44 | def test_get_hypervisor_list(self): |
| 45 | # List of hypervisor and available hypervisors hostname |
| 46 | hypers = self._list_hypervisors() |
| 47 | self.assertTrue(len(hypers) > 0) |
| 48 | |
| 49 | @attr(type=['positive', 'gate']) |
| 50 | def test_get_hypervisor_list_details(self): |
| 51 | # Display the details of the all hypervisor |
| 52 | resp, hypers = self.client.get_hypervisor_list_details() |
| 53 | self.assertEqual(200, resp.status) |
| 54 | self.assertTrue(len(hypers) > 0) |
| 55 | |
| 56 | @attr(type=['positive', 'gate']) |
| 57 | def test_get_hypervisor_show_details(self): |
| 58 | # Display the details of the specified hypervisor |
| 59 | hypers = self._list_hypervisors() |
| 60 | self.assertTrue(len(hypers) > 0) |
| 61 | |
| 62 | resp, details = (self.client. |
| 63 | get_hypervisor_show_details(hypers[0]['id'])) |
| 64 | self.assertEqual(200, resp.status) |
| 65 | self.assertTrue(len(details) > 0) |
| 66 | self.assertEqual(details['hypervisor_hostname'], |
| 67 | hypers[0]['hypervisor_hostname']) |
| 68 | |
| 69 | @attr(type=['positive', 'gate']) |
| 70 | def test_get_hypervisor_show_servers(self): |
| 71 | # Show instances about the specific hypervisors |
| 72 | hypers = self._list_hypervisors() |
| 73 | self.assertTrue(len(hypers) > 0) |
| 74 | |
| 75 | hostname = hypers[0]['hypervisor_hostname'] |
| 76 | resp, hypervisors = self.client.get_hypervisor_servers(hostname) |
| 77 | self.assertEqual(200, resp.status) |
| 78 | self.assertTrue(len(hypervisors) > 0) |
| 79 | |
| 80 | @attr(type=['positive', 'gate']) |
| 81 | def test_get_hypervisor_stats(self): |
| 82 | # Verify the stats of the all hypervisor |
| 83 | resp, stats = self.client.get_hypervisor_stats() |
| 84 | self.assertEqual(200, resp.status) |
| 85 | self.assertTrue(len(stats) > 0) |
| 86 | |
| 87 | @attr(type=['positive', 'gate']) |
| 88 | def test_get_hypervisor_uptime(self): |
| 89 | # Verify that GET shows the specified hypervisor uptime |
| 90 | hypers = self._list_hypervisors() |
| 91 | |
| 92 | resp, uptime = self.client.get_hypervisor_uptime(hypers[0]['id']) |
| 93 | self.assertEqual(200, resp.status) |
| 94 | self.assertTrue(len(uptime) > 0) |
| 95 | |
| 96 | @attr(type=['negative', 'gate']) |
| 97 | def test_get_hypervisor_list_with_non_admin_user(self): |
| 98 | # List of hypervisor and available services with non admin user |
| 99 | self.assertRaises( |
| 100 | exceptions.Unauthorized, |
| 101 | self.non_adm_client.get_hypervisor_list) |
| 102 | |
| 103 | @attr(type=['negative', 'gate']) |
| 104 | def test_get_hypervisor_list_details_with_non_admin_user(self): |
| 105 | # List of hypervisor details and available services with non admin user |
| 106 | self.assertRaises( |
| 107 | exceptions.Unauthorized, |
| 108 | self.non_adm_client.get_hypervisor_list_details) |
| 109 | |
| 110 | |
| 111 | class HypervisorAdminTestXML(HypervisorAdminTestJSON): |
| 112 | _interface = 'xml' |