blob: 8ccd36bc4a8cd5582ff1770744a8580705ce7b2f [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
14
Adam Gandelman2a86f1c2014-06-18 11:34:42 -070015from tempest.api.baremetal.admin import base
Adam Gandelman00682612014-09-02 17:10:36 -070016from tempest.common.utils import data_utils
17from tempest.common import waiters
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030018from tempest import exceptions as exc
19from 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',
52 'cpu_num': '12',
53 'storage': '10240',
54 'memory': '1024'}
55
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
Mh Raiesa9bb79d2014-04-17 16:20:17 +053065 self.assertRaises(exc.NotFound, self.client.show_node, node['uuid'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030066
67 @test.attr(type='smoke')
68 def test_show_node(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000069 _, loaded_node = self.client.show_node(self.node['uuid'])
Mh Raiesa9bb79d2014-04-17 16:20:17 +053070 self._assertExpected(self.node, loaded_node)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030071
72 @test.attr(type='smoke')
73 def test_list_nodes(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000074 _, body = self.client.list_nodes()
Mh Raiesa9bb79d2014-04-17 16:20:17 +053075 self.assertIn(self.node['uuid'],
76 [i['uuid'] for i in body['nodes']])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030077
78 @test.attr(type='smoke')
Adam Gandelman00682612014-09-02 17:10:36 -070079 def test_list_nodes_association(self):
80 _, body = self.client.list_nodes(associated=True)
81 self.assertNotIn(self.node['uuid'],
82 [n['uuid'] for n in body['nodes']])
83
84 self._associate_node_with_instance()
85
86 _, body = self.client.list_nodes(associated=True)
87 self.assertIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
88
89 _, body = self.client.list_nodes(associated=False)
90 self.assertNotIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])
91
92 @test.attr(type='smoke')
93 def test_node_port_list(self):
94 _, port = self.create_port(self.node['uuid'],
95 data_utils.rand_mac_address())
96 _, body = self.client.list_node_ports(self.node['uuid'])
97 self.assertIn(port['uuid'],
98 [p['uuid'] for p in body['ports']])
99
100 @test.attr(type='smoke')
101 def test_node_port_list_no_ports(self):
102 _, node = self.create_node(self.chassis['uuid'])
103 _, body = self.client.list_node_ports(node['uuid'])
104 self.assertEmpty(body['ports'])
105
106 @test.attr(type='smoke')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300107 def test_update_node(self):
108 props = {'cpu_arch': 'x86_64',
109 'cpu_num': '12',
110 'storage': '10',
111 'memory': '128'}
112
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000113 _, node = self.create_node(self.chassis['uuid'], **props)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300114
Mh Raiesa9bb79d2014-04-17 16:20:17 +0530115 new_p = {'cpu_arch': 'x86',
116 'cpu_num': '1',
117 'storage': '10000',
118 'memory': '12300'}
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300119
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000120 _, body = self.client.update_node(node['uuid'], properties=new_p)
121 _, node = self.client.show_node(node['uuid'])
Mh Raiesa9bb79d2014-04-17 16:20:17 +0530122 self._assertExpected(new_p, node['properties'])
raiesmh08e5d84572014-06-23 09:49:03 +0530123
124 @test.attr(type='smoke')
125 def test_validate_driver_interface(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000126 _, body = self.client.validate_driver_interface(self.node['uuid'])
raiesmh08e5d84572014-06-23 09:49:03 +0530127 core_interfaces = ['power', 'deploy']
128 for interface in core_interfaces:
129 self.assertIn(interface, body)
Lucas Alvares Gomes5d236cf2014-08-11 15:23:12 +0100130
131 @test.attr(type='smoke')
132 def test_set_node_boot_device(self):
133 body = self.client.set_node_boot_device(self.node['uuid'], 'pxe')
134 # No content
135 self.assertEqual('', body)
136
137 @test.attr(type='smoke')
138 def test_get_node_boot_device(self):
139 body = self.client.get_node_boot_device(self.node['uuid'])
140 self.assertIn('boot_device', body)
141 self.assertIn('persistent', body)
142 self.assertTrue(isinstance(body['boot_device'], six.string_types))
143 self.assertTrue(isinstance(body['persistent'], bool))
144
145 @test.attr(type='smoke')
146 def test_get_node_supported_boot_devices(self):
147 body = self.client.get_node_supported_boot_devices(self.node['uuid'])
148 self.assertIn('supported_boot_devices', body)
149 self.assertTrue(isinstance(body['supported_boot_devices'], list))
Yuiko Takadabbf5cff2014-08-29 17:09:06 +0900150
151 @test.attr(type='smoke')
152 def test_get_console(self):
153 _, body = self.client.get_console(self.node['uuid'])
154 con_info = ['console_enabled', 'console_info']
155 for key in con_info:
156 self.assertIn(key, body)
157
158 @test.attr(type='smoke')
159 def test_set_console_mode(self):
160 self.client.set_console_mode(self.node['uuid'], True)
161
162 _, body = self.client.get_console(self.node['uuid'])
163 self.assertEqual(True, body['console_enabled'])
Adam Gandelman00682612014-09-02 17:10:36 -0700164
165 @test.attr(type='smoke')
166 def test_get_node_by_instance_uuid(self):
167 instance_uuid = self._associate_node_with_instance()
168 _, body = self.client.show_node_by_instance_uuid(instance_uuid)
169 self.assertEqual(len(body['nodes']), 1)
170 self.assertIn(self.node['uuid'], [n['uuid'] for n in body['nodes']])