blob: bbd280142ede8dadeae79e1ec7e2f8adcff89d48 [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
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050013from tempest_lib import decorators
Masayuki Igawabfa07602015-01-20 18:47:17 +090014from tempest_lib import exceptions as lib_exc
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050015
Adam Gandelman2a86f1c2014-06-18 11:34:42 -070016from tempest.api.baremetal.admin import base
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030017from tempest.common.utils import data_utils
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030018from tempest import test
19
20
21class TestPorts(base.BaseBaremetalTest):
22 """Tests for ports."""
23
24 def setUp(self):
25 super(TestPorts, self).setUp()
26
Mh Raiesa9bb79d2014-04-17 16:20:17 +053027 _, self.chassis = self.create_chassis()
28 _, self.node = self.create_node(self.chassis['uuid'])
29 _, self.port = self.create_port(self.node['uuid'],
30 data_utils.rand_mac_address())
31
32 def _assertExpected(self, expected, actual):
33 # Check if not expected keys/values exists in actual response body
34 for key, value in expected.iteritems():
35 if key not in ('created_at', 'updated_at'):
36 self.assertIn(key, actual)
37 self.assertEqual(value, actual[key])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030038
39 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080040 @test.idempotent_id('83975898-2e50-42ed-b5f0-e510e36a0b56')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030041 def test_create_port(self):
42 node_id = self.node['uuid']
43 address = data_utils.rand_mac_address()
44
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000045 _, port = self.create_port(node_id=node_id, address=address)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040046
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000047 _, body = self.client.show_port(port['uuid'])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040048
Mh Raiesa9bb79d2014-04-17 16:20:17 +053049 self._assertExpected(port, body)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040050
51 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080052 @test.idempotent_id('d1f6b249-4cf6-4fe6-9ed6-a6e84b1bf67b')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040053 def test_create_port_specifying_uuid(self):
54 node_id = self.node['uuid']
55 address = data_utils.rand_mac_address()
56 uuid = data_utils.rand_uuid()
57
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000058 _, port = self.create_port(node_id=node_id,
59 address=address, uuid=uuid)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040060
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000061 _, body = self.client.show_port(uuid)
Mh Raiesa9bb79d2014-04-17 16:20:17 +053062 self._assertExpected(port, body)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040063
Matthew Treinishc49fcbe2015-02-05 23:37:34 -050064 @decorators.skip_because(bug='1398350')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040065 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080066 @test.idempotent_id('4a02c4b0-6573-42a4-a513-2e36ad485b62')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040067 def test_create_port_with_extra(self):
68 node_id = self.node['uuid']
69 address = data_utils.rand_mac_address()
Lucas Alvares Gomes5ea777f2014-12-02 11:38:29 +000070 extra = {'str': 'value', 'int': 123, 'float': 0.123,
71 'bool': True, 'list': [1, 2, 3], 'dict': {'foo': 'bar'}}
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040072
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000073 _, port = self.create_port(node_id=node_id, address=address,
74 extra=extra)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040075
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000076 _, body = self.client.show_port(port['uuid'])
Mh Raiesa9bb79d2014-04-17 16:20:17 +053077 self._assertExpected(port, body)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030078
79 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080080 @test.idempotent_id('1bf257a9-aea3-494e-89c0-63f657ab4fdd')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030081 def test_delete_port(self):
82 node_id = self.node['uuid']
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040083 address = data_utils.rand_mac_address()
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000084 _, port = self.create_port(node_id=node_id, address=address)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030085
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000086 self.delete_port(port['uuid'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030087
Masayuki Igawabfa07602015-01-20 18:47:17 +090088 self.assertRaises(lib_exc.NotFound, self.client.show_port,
89 port['uuid'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030090
91 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080092 @test.idempotent_id('9fa77ab5-ce59-4f05-baac-148904ba1597')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +030093 def test_show_port(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +000094 _, port = self.client.show_port(self.port['uuid'])
Mh Raiesa9bb79d2014-04-17 16:20:17 +053095 self._assertExpected(self.port, port)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +040096
97 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('7c1114ff-fc3f-47bb-bc2f-68f61620ba8b')
Kan3fd5d892015-01-26 01:36:01 -080099 def test_show_port_by_address(self):
100 _, port = self.client.show_port_by_address(self.port['address'])
101 self._assertExpected(self.port, port['ports'][0])
102
103 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800104 @test.idempotent_id('bd773405-aea5-465d-b576-0ab1780069e5')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400105 def test_show_port_with_links(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000106 _, port = self.client.show_port(self.port['uuid'])
Mh Raiesa9bb79d2014-04-17 16:20:17 +0530107 self.assertIn('links', port.keys())
108 self.assertEqual(2, len(port['links']))
109 self.assertIn(port['uuid'], port['links'][0]['href'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300110
111 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800112 @test.idempotent_id('b5e91854-5cd7-4a8e-bb35-3e0a1314606d')
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300113 def test_list_ports(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000114 _, body = self.client.list_ports()
Mh Raiesa9bb79d2014-04-17 16:20:17 +0530115 self.assertIn(self.port['uuid'],
116 [i['uuid'] for i in body['ports']])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400117 # Verify self links.
118 for port in body['ports']:
119 self.validate_self_link('ports', port['uuid'],
120 port['links'][0]['href'])
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300121
122 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800123 @test.idempotent_id('324a910e-2f80-4258-9087-062b5ae06240')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400124 def test_list_with_limit(self):
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000125 _, body = self.client.list_ports(limit=3)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400126
127 next_marker = body['ports'][-1]['uuid']
128 self.assertIn(next_marker, body['next'])
129
Chris Hoge7579c1a2015-02-26 14:12:15 -0800130 @test.idempotent_id('8a94b50f-9895-4a63-a574-7ecff86e5875')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400131 def test_list_ports_details(self):
132 node_id = self.node['uuid']
133
134 uuids = [
135 self.create_port(node_id=node_id,
136 address=data_utils.rand_mac_address())
Mh Raiesa9bb79d2014-04-17 16:20:17 +0530137 [1]['uuid'] for i in range(0, 5)]
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400138
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000139 _, body = self.client.list_ports_detail()
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400140
Dirk Mueller483c6f72014-05-23 12:23:50 +0200141 ports_dict = dict((port['uuid'], port) for port in body['ports']
142 if port['uuid'] in uuids)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400143
144 for uuid in uuids:
145 self.assertIn(uuid, ports_dict)
146 port = ports_dict[uuid]
147 self.assertIn('extra', port)
148 self.assertIn('node_uuid', port)
149 # never expose the node_id
150 self.assertNotIn('node_id', port)
151 # Verify self link.
152 self.validate_self_link('ports', port['uuid'],
153 port['links'][0]['href'])
154
Chris Hoge7579c1a2015-02-26 14:12:15 -0800155 @test.idempotent_id('8a03f688-7d75-4ecd-8cbc-e06b8f346738')
Yuiko Takada3083fca2014-04-25 11:52:33 +0000156 def test_list_ports_details_with_address(self):
157 node_id = self.node['uuid']
158 address = data_utils.rand_mac_address()
159 self.create_port(node_id=node_id, address=address)
160 for i in range(0, 5):
161 self.create_port(node_id=node_id,
162 address=data_utils.rand_mac_address())
163
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000164 _, body = self.client.list_ports_detail(address=address)
Yuiko Takada3083fca2014-04-25 11:52:33 +0000165 self.assertEqual(1, len(body['ports']))
166 self.assertEqual(address, body['ports'][0]['address'])
167
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400168 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800169 @test.idempotent_id('9c26298b-1bcb-47b7-9b9e-8bdd6e3c4aba')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400170 def test_update_port_replace(self):
171 node_id = self.node['uuid']
172 address = data_utils.rand_mac_address()
173 extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
174
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000175 _, port = self.create_port(node_id=node_id, address=address,
176 extra=extra)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300177
178 new_address = data_utils.rand_mac_address()
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400179 new_extra = {'key1': 'new-value1', 'key2': 'new-value2',
180 'key3': 'new-value3'}
181
182 patch = [{'path': '/address',
183 'op': 'replace',
184 'value': new_address},
185 {'path': '/extra/key1',
186 'op': 'replace',
187 'value': new_extra['key1']},
188 {'path': '/extra/key2',
189 'op': 'replace',
190 'value': new_extra['key2']},
191 {'path': '/extra/key3',
192 'op': 'replace',
193 'value': new_extra['key3']}]
194
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000195 self.client.update_port(port['uuid'], patch)
Roman Prykhodchenko62b1ed12013-10-16 21:51:47 +0300196
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000197 _, body = self.client.show_port(port['uuid'])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400198 self.assertEqual(new_address, body['address'])
199 self.assertEqual(new_extra, body['extra'])
200
201 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800202 @test.idempotent_id('d7e7fece-6ed9-460a-9ebe-9267217e8580')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400203 def test_update_port_remove(self):
204 node_id = self.node['uuid']
205 address = data_utils.rand_mac_address()
206 extra = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
207
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000208 _, port = self.create_port(node_id=node_id, address=address,
209 extra=extra)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400210
211 # Removing one item from the collection
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000212 self.client.update_port(port['uuid'],
213 [{'path': '/extra/key2',
214 'op': 'remove'}])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400215 extra.pop('key2')
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000216 _, body = self.client.show_port(port['uuid'])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400217 self.assertEqual(extra, body['extra'])
218
219 # Removing the collection
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000220 self.client.update_port(port['uuid'], [{'path': '/extra',
221 'op': 'remove'}])
222 _, body = self.client.show_port(port['uuid'])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400223 self.assertEqual({}, body['extra'])
224
225 # Assert nothing else was changed
226 self.assertEqual(node_id, body['node_uuid'])
227 self.assertEqual(address, body['address'])
228
229 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800230 @test.idempotent_id('241288b3-e98a-400f-a4d7-d1f716146361')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400231 def test_update_port_add(self):
232 node_id = self.node['uuid']
233 address = data_utils.rand_mac_address()
234
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000235 _, port = self.create_port(node_id=node_id, address=address)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400236
237 extra = {'key1': 'value1', 'key2': 'value2'}
238
239 patch = [{'path': '/extra/key1',
240 'op': 'add',
241 'value': extra['key1']},
242 {'path': '/extra/key2',
243 'op': 'add',
244 'value': extra['key2']}]
245
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000246 self.client.update_port(port['uuid'], patch)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400247
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000248 _, body = self.client.show_port(port['uuid'])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400249 self.assertEqual(extra, body['extra'])
250
Matthew Treinishc49fcbe2015-02-05 23:37:34 -0500251 @decorators.skip_because(bug='1398350')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400252 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -0800253 @test.idempotent_id('5309e897-0799-4649-a982-0179b04c3876')
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400254 def test_update_port_mixed_ops(self):
255 node_id = self.node['uuid']
256 address = data_utils.rand_mac_address()
257 extra = {'key1': 'value1', 'key2': 'value2'}
258
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000259 _, port = self.create_port(node_id=node_id, address=address,
260 extra=extra)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400261
262 new_address = data_utils.rand_mac_address()
Lucas Alvares Gomes5ea777f2014-12-02 11:38:29 +0000263 new_extra = {'key1': 0.123, 'key3': {'cat': 'meow'}}
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400264
265 patch = [{'path': '/address',
266 'op': 'replace',
267 'value': new_address},
268 {'path': '/extra/key1',
269 'op': 'replace',
270 'value': new_extra['key1']},
271 {'path': '/extra/key2',
272 'op': 'remove'},
273 {'path': '/extra/key3',
274 'op': 'add',
275 'value': new_extra['key3']}]
276
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000277 self.client.update_port(port['uuid'], patch)
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400278
Swapnil Kulkarniaa57d6e2014-08-19 10:40:35 +0000279 _, body = self.client.show_port(port['uuid'])
Sergey Nikitin0d43eb52014-02-03 14:50:02 +0400280 self.assertEqual(new_address, body['address'])
281 self.assertEqual(new_extra, body['extra'])