Mh Raies | fbe5451 | 2014-04-08 12:25:15 +0530 | [diff] [blame] | 1 | # Copyright 2014 NEC Corporation. All rights reserved. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | from tempest.api.baremetal import base |
Mh Raies | f8ecf23 | 2014-04-17 12:43:55 +0530 | [diff] [blame] | 16 | from tempest import exceptions |
| 17 | from tempest.openstack.common import timeutils |
Mh Raies | fbe5451 | 2014-04-08 12:25:15 +0530 | [diff] [blame] | 18 | from tempest import test |
| 19 | |
| 20 | |
| 21 | class TestNodeStates(base.BaseBaremetalTest): |
| 22 | """Tests for baremetal NodeStates.""" |
| 23 | |
| 24 | @classmethod |
Mh Raies | f8ecf23 | 2014-04-17 12:43:55 +0530 | [diff] [blame] | 25 | def setUpClass(cls): |
| 26 | super(TestNodeStates, cls).setUpClass() |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 27 | resp, cls.chassis = cls.create_chassis() |
| 28 | resp, cls.node = cls.create_node(cls.chassis['uuid']) |
Mh Raies | f8ecf23 | 2014-04-17 12:43:55 +0530 | [diff] [blame] | 29 | |
| 30 | def _validate_power_state(self, node_uuid, power_state): |
| 31 | # Validate that power state is set within timeout |
| 32 | if power_state == 'rebooting': |
| 33 | power_state = 'power on' |
| 34 | start = timeutils.utcnow() |
| 35 | while timeutils.delta_seconds( |
| 36 | start, timeutils.utcnow()) < self.power_timeout: |
| 37 | resp, node = self.client.show_node(node_uuid) |
| 38 | self.assertEqual(200, resp.status) |
| 39 | if node['power_state'] == power_state: |
| 40 | return |
| 41 | message = ('Failed to set power state within ' |
| 42 | 'the required time: %s sec.' % self.power_timeout) |
| 43 | raise exceptions.TimeoutException(message) |
Mh Raies | fbe5451 | 2014-04-08 12:25:15 +0530 | [diff] [blame] | 44 | |
| 45 | @test.attr(type='smoke') |
| 46 | def test_list_nodestates(self): |
| 47 | resp, nodestates = self.client.list_nodestates(self.node['uuid']) |
| 48 | self.assertEqual('200', resp['status']) |
| 49 | for key in nodestates: |
| 50 | self.assertEqual(nodestates[key], self.node[key]) |
Mh Raies | f8ecf23 | 2014-04-17 12:43:55 +0530 | [diff] [blame] | 51 | |
| 52 | @test.attr(type='smoke') |
| 53 | def test_set_node_power_state(self): |
Adam Gandelman | b3348f7 | 2014-06-17 00:16:54 -0700 | [diff] [blame] | 54 | resp, node = self.create_node(self.chassis['uuid']) |
| 55 | self.assertEqual('201', resp['status']) |
Mh Raies | f8ecf23 | 2014-04-17 12:43:55 +0530 | [diff] [blame] | 56 | states = ["power on", "rebooting", "power off"] |
| 57 | for state in states: |
| 58 | # Set power state |
| 59 | resp, _ = self.client.set_node_power_state(node['uuid'], |
| 60 | state) |
| 61 | self.assertEqual('202', resp['status']) |
| 62 | # Check power state after state is set |
| 63 | self._validate_power_state(node['uuid'], state) |