blob: 191922372acb89d279035de4b0b54f8d9b4f44d4 [file] [log] [blame]
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +03001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13import six
Masayuki Igawabfa07602015-01-20 18:47:17 +090014from tempest_lib import exceptions as lib_exc
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030015
Adam Gandelman2a86f1c2014-06-18 11:34:42 -070016from tempest.api.baremetal.admin import base
Adam Gandelman00682612014-09-02 17:10:36 -070017from tempest.common.utils import data_utils
18from tempest.common import waiters
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030019from tempest import test
20
21
22class TestNodes(base.BaseBaremetalTest):
23 '''Tests for baremetal nodes.'''
24
25 def setUp(self):
26 super(TestNodes, self).setUp()
27
Mh Raiesa9bb79d2014-04-17 16:20:17 +053028 _, self.chassis = self.create_chassis()
29 _, self.node = self.create_node(self.chassis['uuid'])
30
31 def _assertExpected(self, expected, actual):
32 # Check if not expected keys/values exists in actual response body
33 for key, value in six.iteritems(expected):
34 if key not in ('created_at', 'updated_at'):
35 self.assertIn(key, actual)
36 self.assertEqual(value, actual[key])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030037
Adam Gandelman00682612014-09-02 17:10:36 -070038 def _associate_node_with_instance(self):
39 self.client.set_node_power_state(self.node['uuid'], 'power off')
40 waiters.wait_for_bm_node_status(self.client, self.node['uuid'],
41 'power_state', 'power off')
42 instance_uuid = data_utils.rand_uuid()
43 self.client.update_node(self.node['uuid'],
44 instance_uuid=instance_uuid)
45 self.addCleanup(self.client.update_node,
46 uuid=self.node['uuid'], instance_uuid=None)
47 return instance_uuid
48
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030049 @test.attr(type='smoke')
50 def test_create_node(self):
51 params = {'cpu_arch': 'x86_64',
Adam Gandelman3ea1eb82015-02-18 19:13:25 -080052 'cpus': '12',
53 'local_gb': '10',
54 'memory_mb': '1024'}
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030055
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000056 _, body = self.create_node(self.chassis['uuid'], **params)
Mh Raiesa9bb79d2014-04-17 16:20:17 +053057 self._assertExpected(params, body['properties'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030058
59 @test.attr(type='smoke')
60 def test_delete_node(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000061 _, node = self.create_node(self.chassis['uuid'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030062
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000063 self.delete_node(node['uuid'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030064
Masayuki Igawabfa07602015-01-20 18:47:17 +090065 self.assertRaises(lib_exc.NotFound, self.client.show_node,
66 node['uuid'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030067
68 @test.attr(type='smoke')
69 def test_show_node(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000070 _, loaded_node = self.client.show_node(self.node['uuid'])
Mh Raiesa9bb79d2014-04-17 16:20:17 +053071 self._assertExpected(self.node, loaded_node)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030072
73 @test.attr(type='smoke')
74 def test_list_nodes(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000075 _, body = self.client.list_nodes()
Mh Raiesa9bb79d2014-04-17 16:20:17 +053076 self.assertIn(self.node['uuid'],
77 [i['uuid'] for i in body['nodes']])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030078
79 @test.attr(type='smoke')
Adam Gandelman00682612014-09-02 17:10:36 -070080 def test_list_nodes_association(self):
81 _, body = self.client.list_nodes(associated=True)
82 self.assertNotIn(self.node['uuid'],
83 [n['uuid'] for n in body['nodes']])
84
85 self._associate_node_with_instance()
86
87 _, body = self.client.list_nodes(associated=True)
88 self.assertIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
89
90 _, body = self.client.list_nodes(associated=False)
91 self.assertNotIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
92
93 @test.attr(type='smoke')
94 def test_node_port_list(self):
95 _, port = self.create_port(self.node['uuid'],
96 data_utils.rand_mac_address())
97 _, body = self.client.list_node_ports(self.node['uuid'])
98 self.assertIn(port['uuid'],
99 [p['uuid'] for p in body['ports']])
100
101 @test.attr(type='smoke')
102 def test_node_port_list_no_ports(self):
103 _, node = self.create_node(self.chassis['uuid'])
104 _, body = self.client.list_node_ports(node['uuid'])
105 self.assertEmpty(body['ports'])
106
107 @test.attr(type='smoke')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300108 def test_update_node(self):
109 props = {'cpu_arch': 'x86_64',
Adam Gandelman3ea1eb82015-02-18 19:13:25 -0800110 'cpus': '12',
111 'local_gb': '10',
112 'memory_mb': '128'}
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300113
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000114 _, node = self.create_node(self.chassis['uuid'], **props)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300115
Mh Raiesa9bb79d2014-04-17 16:20:17 +0530116 new_p = {'cpu_arch': 'x86',
Adam Gandelman3ea1eb82015-02-18 19:13:25 -0800117 'cpus': '1',
118 'local_gb': '10000',
119 'memory_mb': '12300'}
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300120
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000121 _, body = self.client.update_node(node['uuid'], properties=new_p)
122 _, node = self.client.show_node(node['uuid'])
Mh Raiesa9bb79d2014-04-17 16:20:17 +0530123 self._assertExpected(new_p, node['properties'])
raiesmh08e5d84572014-06-23 09:49:03 +0530124
125 @test.attr(type='smoke')
126 def test_validate_driver_interface(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000127 _, body = self.client.validate_driver_interface(self.node['uuid'])
raiesmh08e5d84572014-06-23 09:49:03 +0530128 core_interfaces = ['power', 'deploy']
129 for interface in core_interfaces:
130 self.assertIn(interface, body)
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100131
132 @test.attr(type='smoke')
133 def test_set_node_boot_device(self):
ghanshyama2016372014-10-24 11:15:01 +0900134 self.client.set_node_boot_device(self.node['uuid'], 'pxe')
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100135
136 @test.attr(type='smoke')
137 def test_get_node_boot_device(self):
138 body = self.client.get_node_boot_device(self.node['uuid'])
139 self.assertIn('boot_device', body)
140 self.assertIn('persistent', body)
141 self.assertTrue(isinstance(body['boot_device'], six.string_types))
142 self.assertTrue(isinstance(body['persistent'], bool))
143
144 @test.attr(type='smoke')
145 def test_get_node_supported_boot_devices(self):
146 body = self.client.get_node_supported_boot_devices(self.node['uuid'])
147 self.assertIn('supported_boot_devices', body)
148 self.assertTrue(isinstance(body['supported_boot_devices'], list))
Yuiko Takadabbf5cff2014-08-29 17:09:06 +0900149
150 @test.attr(type='smoke')
151 def test_get_console(self):
152 _, body = self.client.get_console(self.node['uuid'])
153 con_info = ['console_enabled', 'console_info']
154 for key in con_info:
155 self.assertIn(key, body)
156
157 @test.attr(type='smoke')
158 def test_set_console_mode(self):
159 self.client.set_console_mode(self.node['uuid'], True)
160
161 _, body = self.client.get_console(self.node['uuid'])
162 self.assertEqual(True, body['console_enabled'])
Adam Gandelman00682612014-09-02 17:10:36 -0700163
164 @test.attr(type='smoke')
165 def test_get_node_by_instance_uuid(self):
166 instance_uuid = self._associate_node_with_instance()
167 _, body = self.client.show_node_by_instance_uuid(instance_uuid)
168 self.assertEqual(len(body['nodes']), 1)
169 self.assertIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])