blob: e74dd04c6d7b61c047400b9562c38c4e8633b50b [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000015from oslo_utils import timeutils
16
Adam Gandelman2a86f1c2014-06-18 11:34:42 -070017from tempest.api.baremetal.admin import base
guo yunxianebb15f22016-11-01 21:03:35 +080018from tempest.lib import exceptions
Mh Raiesfbe54512014-04-08 12:25:15 +053019from tempest import test
20
21
22class TestNodeStates(base.BaseBaremetalTest):
23 """Tests for baremetal NodeStates."""
24
25 @classmethod
Andrea Frittoliba240c32014-09-15 13:14:53 +010026 def resource_setup(cls):
27 super(TestNodeStates, cls).resource_setup()
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000028 _, cls.chassis = cls.create_chassis()
29 _, cls.node = cls.create_node(cls.chassis['uuid'])
Mh Raiesf8ecf232014-04-17 12:43:55 +053030
31 def _validate_power_state(self, node_uuid, power_state):
32 # Validate that power state is set within timeout
33 if power_state == 'rebooting':
34 power_state = 'power on'
35 start = timeutils.utcnow()
36 while timeutils.delta_seconds(
37 start, timeutils.utcnow()) < self.power_timeout:
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000038 _, node = self.client.show_node(node_uuid)
Mh Raiesf8ecf232014-04-17 12:43:55 +053039 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
Chris Hoge7579c1a2015-02-26 14:12:15 -080045 @test.idempotent_id('cd8afa5e-3f57-4e43-8185-beb83d3c9015')
Mh Raiesfbe54512014-04-08 12:25:15 +053046 def test_list_nodestates(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000047 _, nodestates = self.client.list_nodestates(self.node['uuid'])
Mh Raiesfbe54512014-04-08 12:25:15 +053048 for key in nodestates:
49 self.assertEqual(nodestates[key], self.node[key])
Mh Raiesf8ecf232014-04-17 12:43:55 +053050
Chris Hoge7579c1a2015-02-26 14:12:15 -080051 @test.idempotent_id('fc5b9320-0c98-4e5a-8848-877fe5a0322c')
Mh Raiesf8ecf232014-04-17 12:43:55 +053052 def test_set_node_power_state(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000053 _, node = self.create_node(self.chassis['uuid'])
Mh Raiesf8ecf232014-04-17 12:43:55 +053054 states = ["power on", "rebooting", "power off"]
55 for state in states:
56 # Set power state
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000057 self.client.set_node_power_state(node['uuid'], state)
Mh Raiesf8ecf232014-04-17 12:43:55 +053058 # Check power state after state is set
59 self._validate_power_state(node['uuid'], state)