blob: 76f47f94663134d53fbc034d7cbfd25ce4463f5d [file] [log] [blame]
Mh Raiesfbe54512014-04-08 12:25:15 +05301# 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
Adam Gandelman2a86f1c2014-06-18 11:34:42 -070015from tempest.api.baremetal.admin import base
Mh Raiesf8ecf232014-04-17 12:43:55 +053016from tempest import exceptions
17from tempest.openstack.common import timeutils
Mh Raiesfbe54512014-04-08 12:25:15 +053018from tempest import test
19
20
21class TestNodeStates(base.BaseBaremetalTest):
22 """Tests for baremetal NodeStates."""
23
24 @classmethod
Mh Raiesf8ecf232014-04-17 12:43:55 +053025 def setUpClass(cls):
26 super(TestNodeStates, cls).setUpClass()
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000027 _, cls.chassis = cls.create_chassis()
28 _, cls.node = cls.create_node(cls.chassis['uuid'])
Mh Raiesf8ecf232014-04-17 12:43:55 +053029
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:
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000037 _, node = self.client.show_node(node_uuid)
Mh Raiesf8ecf232014-04-17 12:43:55 +053038 if node['power_state'] == power_state:
39 return
40 message = ('Failed to set power state within '
41 'the required time: %s sec.' % self.power_timeout)
42 raise exceptions.TimeoutException(message)
Mh Raiesfbe54512014-04-08 12:25:15 +053043
44 @test.attr(type='smoke')
45 def test_list_nodestates(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000046 _, nodestates = self.client.list_nodestates(self.node['uuid'])
Mh Raiesfbe54512014-04-08 12:25:15 +053047 for key in nodestates:
48 self.assertEqual(nodestates[key], self.node[key])
Mh Raiesf8ecf232014-04-17 12:43:55 +053049
50 @test.attr(type='smoke')
51 def test_set_node_power_state(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000052 _, node = self.create_node(self.chassis['uuid'])
Mh Raiesf8ecf232014-04-17 12:43:55 +053053 states = ["power on", "rebooting", "power off"]
54 for state in states:
55 # Set power state
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000056 self.client.set_node_power_state(node['uuid'], state)
Mh Raiesf8ecf232014-04-17 12:43:55 +053057 # Check power state after state is set
58 self._validate_power_state(node['uuid'], state)