blob: 3044bc6eb53cdf2ec052dc27e133068d8b74c5e9 [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
15from tempest.api.baremetal 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()
Adam Gandelmanb3348f72014-06-17 00:16:54 -070027 resp, cls.chassis = cls.create_chassis()
28 resp, 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:
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 Raiesfbe54512014-04-08 12:25:15 +053044
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 Raiesf8ecf232014-04-17 12:43:55 +053051
52 @test.attr(type='smoke')
53 def test_set_node_power_state(self):
Adam Gandelmanb3348f72014-06-17 00:16:54 -070054 resp, node = self.create_node(self.chassis['uuid'])
55 self.assertEqual('201', resp['status'])
Mh Raiesf8ecf232014-04-17 12:43:55 +053056 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)