Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 1 | # 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 | |
| 13 | import six |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 14 | from tempest_lib import exceptions as lib_exc |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 15 | |
Adam Gandelman | 2a86f1c | 2014-06-18 11:34:42 -0700 | [diff] [blame] | 16 | from tempest.api.baremetal.admin import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Adam Gandelman | 0068261 | 2014-09-02 17:10:36 -0700 | [diff] [blame] | 18 | from tempest.common import waiters |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 19 | from tempest import test |
| 20 | |
| 21 | |
| 22 | class TestNodes(base.BaseBaremetalTest): |
| 23 | '''Tests for baremetal nodes.''' |
| 24 | |
| 25 | def setUp(self): |
| 26 | super(TestNodes, self).setUp() |
| 27 | |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 28 | _, 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 Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 37 | |
Adam Gandelman | 0068261 | 2014-09-02 17:10:36 -0700 | [diff] [blame] | 38 | 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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 49 | @test.idempotent_id('4e939eb2-8a69-4e84-8652-6fffcbc9db8f') |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 50 | def test_create_node(self): |
| 51 | params = {'cpu_arch': 'x86_64', |
Adam Gandelman | 3ea1eb8 | 2015-02-18 19:13:25 -0800 | [diff] [blame] | 52 | 'cpus': '12', |
| 53 | 'local_gb': '10', |
| 54 | 'memory_mb': '1024'} |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 55 | |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 56 | _, body = self.create_node(self.chassis['uuid'], **params) |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 57 | self._assertExpected(params, body['properties']) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 58 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 59 | @test.idempotent_id('9ade60a4-505e-4259-9ec4-71352cbbaf47') |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 60 | def test_delete_node(self): |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 61 | _, node = self.create_node(self.chassis['uuid']) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 62 | |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 63 | self.delete_node(node['uuid']) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 64 | |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 65 | self.assertRaises(lib_exc.NotFound, self.client.show_node, |
| 66 | node['uuid']) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 67 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 68 | @test.idempotent_id('55451300-057c-4ecf-8255-ba42a83d3a03') |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 69 | def test_show_node(self): |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 70 | _, loaded_node = self.client.show_node(self.node['uuid']) |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 71 | self._assertExpected(self.node, loaded_node) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 72 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 73 | @test.idempotent_id('4ca123c4-160d-4d8d-a3f7-15feda812263') |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 74 | def test_list_nodes(self): |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 75 | _, body = self.client.list_nodes() |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 76 | self.assertIn(self.node['uuid'], |
| 77 | [i['uuid'] for i in body['nodes']]) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 78 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 79 | @test.idempotent_id('85b1f6e0-57fd-424c-aeff-c3422920556f') |
Adam Gandelman | 0068261 | 2014-09-02 17:10:36 -0700 | [diff] [blame] | 80 | 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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 93 | @test.idempotent_id('18c4ebd8-f83a-4df7-9653-9fb33a329730') |
Adam Gandelman | 0068261 | 2014-09-02 17:10:36 -0700 | [diff] [blame] | 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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 101 | @test.idempotent_id('72591acb-f215-49db-8395-710d14eb86ab') |
Adam Gandelman | 0068261 | 2014-09-02 17:10:36 -0700 | [diff] [blame] | 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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 107 | @test.idempotent_id('4fed270a-677a-4d19-be87-fd38ae490320') |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 108 | def test_update_node(self): |
| 109 | props = {'cpu_arch': 'x86_64', |
Adam Gandelman | 3ea1eb8 | 2015-02-18 19:13:25 -0800 | [diff] [blame] | 110 | 'cpus': '12', |
| 111 | 'local_gb': '10', |
| 112 | 'memory_mb': '128'} |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 113 | |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 114 | _, node = self.create_node(self.chassis['uuid'], **props) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 115 | |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 116 | new_p = {'cpu_arch': 'x86', |
Adam Gandelman | 3ea1eb8 | 2015-02-18 19:13:25 -0800 | [diff] [blame] | 117 | 'cpus': '1', |
| 118 | 'local_gb': '10000', |
| 119 | 'memory_mb': '12300'} |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 120 | |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 121 | _, body = self.client.update_node(node['uuid'], properties=new_p) |
| 122 | _, node = self.client.show_node(node['uuid']) |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 123 | self._assertExpected(new_p, node['properties']) |
raiesmh08 | e5d8457 | 2014-06-23 09:49:03 +0530 | [diff] [blame] | 124 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 125 | @test.idempotent_id('cbf1f515-5f4b-4e49-945c-86bcaccfeb1d') |
raiesmh08 | e5d8457 | 2014-06-23 09:49:03 +0530 | [diff] [blame] | 126 | def test_validate_driver_interface(self): |
Swapnil Kulkarni | aa57d6e | 2014-08-19 10:40:35 +0000 | [diff] [blame] | 127 | _, body = self.client.validate_driver_interface(self.node['uuid']) |
raiesmh08 | e5d8457 | 2014-06-23 09:49:03 +0530 | [diff] [blame] | 128 | core_interfaces = ['power', 'deploy'] |
| 129 | for interface in core_interfaces: |
| 130 | self.assertIn(interface, body) |
Lucas Alvares Gomes | 5d236cf | 2014-08-11 15:23:12 +0100 | [diff] [blame] | 131 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 132 | @test.idempotent_id('5519371c-26a2-46e9-aa1a-f74226e9d71f') |
Lucas Alvares Gomes | 5d236cf | 2014-08-11 15:23:12 +0100 | [diff] [blame] | 133 | def test_set_node_boot_device(self): |
ghanshyam | a201637 | 2014-10-24 11:15:01 +0900 | [diff] [blame] | 134 | self.client.set_node_boot_device(self.node['uuid'], 'pxe') |
Lucas Alvares Gomes | 5d236cf | 2014-08-11 15:23:12 +0100 | [diff] [blame] | 135 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 136 | @test.idempotent_id('9ea73775-f578-40b9-bc34-efc639c4f21f') |
Lucas Alvares Gomes | 5d236cf | 2014-08-11 15:23:12 +0100 | [diff] [blame] | 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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 144 | @test.idempotent_id('3622bc6f-3589-4bc2-89f3-50419c66b133') |
Lucas Alvares Gomes | 5d236cf | 2014-08-11 15:23:12 +0100 | [diff] [blame] | 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 Takada | bbf5cff | 2014-08-29 17:09:06 +0900 | [diff] [blame] | 149 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 150 | @test.idempotent_id('f63b6288-1137-4426-8cfe-0d5b7eb87c06') |
Yuiko Takada | bbf5cff | 2014-08-29 17:09:06 +0900 | [diff] [blame] | 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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 157 | @test.idempotent_id('80504575-9b21-4670-92d1-143b948f9437') |
Yuiko Takada | bbf5cff | 2014-08-29 17:09:06 +0900 | [diff] [blame] | 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 Gandelman | 0068261 | 2014-09-02 17:10:36 -0700 | [diff] [blame] | 163 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 164 | @test.idempotent_id('b02a4f38-5e8b-44b2-aed2-a69a36ecfd69') |
Adam Gandelman | 0068261 | 2014-09-02 17:10:36 -0700 | [diff] [blame] | 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']]) |