| 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 |
from tempest.lib.common.utils import data_utils |
| 14 |
from tempest.lib import decorators |
| 15 |
from tempest.lib import exceptions as lib_exc |
| 16 |
|
| 17 |
from ironic_tempest_plugin.tests.api.admin import api_microversion_fixture |
| 18 |
from ironic_tempest_plugin.tests.api import base |
| 19 |
|
| 20 |
|
| 21 |
class TestPortGroups(base.BaseBaremetalTest): |
| 22 |
"""Basic positive test cases for port groups.""" |
| 23 |
|
| 24 |
min_microversion = '1.26' # portgroup mode and properties introduced |
| 25 |
|
| 26 |
def setUp(self): |
| 27 |
super(TestPortGroups, self).setUp() |
| 28 |
self.useFixture( |
| 29 |
api_microversion_fixture.APIMicroversionFixture( |
| 30 |
self.min_microversion)) |
| 31 |
_, self.chassis = self.create_chassis() |
| 32 |
_, self.node = self.create_node(self.chassis['uuid'], |
| 33 |
network_interface='noop') |
| 34 |
_, self.portgroup = self.create_portgroup( |
| 35 |
self.node['uuid'], address=data_utils.rand_mac_address(), |
| 36 |
name=data_utils.rand_name('portgroup')) |
| 37 |
|
| 38 |
@decorators.idempotent_id('110cd302-256b-4ddc-be10-fc6c9ad8e649') |
| 39 |
def test_create_portgroup_with_address(self): |
| 40 |
"""Create a port group with specific MAC address.""" |
| 41 |
_, body = self.client.show_portgroup(self.portgroup['uuid']) |
| 42 |
self.assertEqual(self.portgroup['address'], body['address']) |
| 43 |
|
| 44 |
@decorators.idempotent_id('4336fa0f-da86-4cec-b788-89f59a7635a5') |
| 45 |
def test_create_portgroup_no_address(self): |
| 46 |
"""Create a port group without setting MAC address.""" |
| 47 |
_, portgroup = self.create_portgroup(self.node['uuid']) |
| 48 |
_, body = self.client.show_portgroup(portgroup['uuid']) |
| 49 |
|
| 50 |
self._assertExpected(portgroup, body) |
| 51 |
self.assertIsNone(body['address']) |
| 52 |
|
| 53 |
@decorators.idempotent_id('8378c69f-f806-454b-8ddd-6b7fd93ab12b') |
| 54 |
def test_delete_portgroup(self): |
| 55 |
"""Delete a port group.""" |
| 56 |
self.delete_portgroup(self.portgroup['uuid']) |
| 57 |
self.assertRaises(lib_exc.NotFound, self.client.show_portgroup, |
| 58 |
self.portgroup['uuid']) |
| 59 |
|
| 60 |
@decorators.idempotent_id('f6be5e70-3e3b-435c-b2fc-bbb2cc9b3185') |
| 61 |
def test_show_portgroup(self): |
| 62 |
"""Show a specified port group.""" |
| 63 |
_, portgroup = self.client.show_portgroup(self.portgroup['uuid']) |
| 64 |
self._assertExpected(self.portgroup, portgroup) |
| 65 |
|
| 66 |
@decorators.idempotent_id('cf2dfd95-5ea1-4109-8ad3-297cd76aa5d3') |
| 67 |
def test_list_portgroups(self): |
| 68 |
"""List port groups.""" |
| 69 |
_, body = self.client.list_portgroups() |
| 70 |
self.assertIn(self.portgroup['uuid'], |
| 71 |
[i['uuid'] for i in body['portgroups']]) |
| 72 |
self.assertIn(self.portgroup['address'], |
| 73 |
[i['address'] for i in body['portgroups']]) |
| 74 |
self.assertIn(self.portgroup['name'], |
| 75 |
[i['name'] for i in body['portgroups']]) |
| 76 |
|
| 77 |
@decorators.idempotent_id('6a491006-2dd5-4c82-be39-a4fa015071c0') |
| 78 |
def test_update_portgroup_replace(self): |
| 79 |
"""Update portgroup by replacing it's address and extra data.""" |
| 80 |
new_address = data_utils.rand_mac_address() |
| 81 |
new_extra = {'foo': 'test'} |
| 82 |
|
| 83 |
patch = [{'path': '/address', |
| 84 |
'op': 'replace', |
| 85 |
'value': new_address}, |
| 86 |
{'path': '/extra/foo', |
| 87 |
'op': 'replace', |
| 88 |
'value': new_extra['foo']}, |
| 89 |
] |
| 90 |
|
| 91 |
self.client.update_portgroup(self.portgroup['uuid'], patch) |
| 92 |
|
| 93 |
_, body = self.client.show_portgroup(self.portgroup['uuid']) |
| 94 |
|
| 95 |
self.assertEqual(new_address, body['address']) |
| 96 |
self._assertExpected(new_extra, body['extra']) |
| 97 |
|
| 98 |
@decorators.idempotent_id('9834a4ec-be41-40b4-a3a4-8e46ad7eb19d') |
| 99 |
def test_update_portgroup_remove_by_key(self): |
| 100 |
"""Update portgroup by removing value from extra data.""" |
| 101 |
self.client.update_portgroup( |
| 102 |
self.portgroup['uuid'], |
| 103 |
[{'path': '/extra/foo', 'op': 'remove'}] |
| 104 |
) |
| 105 |
_, body = self.client.show_portgroup(self.portgroup['uuid']) |
| 106 |
self.assertNotIn('foo', body['extra']) |
| 107 |
self._assertExpected({'open': 'stack'}, body['extra']) |
| 108 |
|
| 109 |
@decorators.idempotent_id('5da2f7c7-03e8-4db0-8c3e-2fe6ebcc4439') |
| 110 |
def test_update_portgroup_remove_collection(self): |
| 111 |
"""Update portgroup by removing collection from extra data.""" |
| 112 |
self.client.update_portgroup( |
| 113 |
self.portgroup['uuid'], |
| 114 |
[{'path': '/extra', 'op': 'remove'}] |
| 115 |
) |
| 116 |
_, body = self.client.show_portgroup(self.portgroup['uuid']) |
| 117 |
self.assertEqual({}, body['extra']) |
| 118 |
|
| 119 |
@decorators.idempotent_id('a1123416-7bb6-4a6a-9f14-859c72550552') |
| 120 |
def test_update_portgroup_add(self): |
| 121 |
"""Update portgroup by adding new extra data and properties.""" |
| 122 |
patch = [{'path': '/extra/key1', |
| 123 |
'op': 'add', |
| 124 |
'value': 'value1'}, |
| 125 |
{'path': '/properties/key1', |
| 126 |
'op': 'add', |
| 127 |
'value': 'value1'}] |
| 128 |
|
| 129 |
self.client.update_portgroup(self.portgroup['uuid'], patch) |
| 130 |
|
| 131 |
_, body = self.client.show_portgroup(self.portgroup['uuid']) |
| 132 |
self._assertExpected({'key1': 'value1'}, body['extra']) |
| 133 |
self._assertExpected({'key1': 'value1'}, body['properties']) |
| 134 |
|
| 135 |
@decorators.idempotent_id('67d5013e-5158-44e8-8d1c-a01d04542be4') |
| 136 |
def test_update_portgroup_mixed_ops(self): |
| 137 |
"""Update port group with add, replace and remove ops in one patch.""" |
| 138 |
new_address = data_utils.rand_mac_address() |
| 139 |
new_extra = {'key3': {'cat': 'meow'}} |
| 140 |
|
| 141 |
patch = [{'path': '/address', |
| 142 |
'op': 'replace', |
| 143 |
'value': new_address}, |
| 144 |
{'path': '/extra/foo', |
| 145 |
'op': 'remove'}, |
| 146 |
{'path': '/extra/key3', |
| 147 |
'op': 'add', |
| 148 |
'value': new_extra['key3']}] |
| 149 |
|
| 150 |
self.client.update_portgroup(self.portgroup['uuid'], patch) |
| 151 |
|
| 152 |
_, body = self.client.show_portgroup(self.portgroup['uuid']) |
| 153 |
self.assertEqual(new_address, body['address']) |
| 154 |
self._assertExpected(new_extra, body['extra']) |
| 155 |
self.assertNotIn('foo', body['extra']) |
| 156 |
|
| 157 |
|
| 158 |
class TestPortGroupsWithJsonExtSupport(base.BaseBaremetalTest): |
| 159 |
"""Basic test cases to validate appending .json extension to a portgroup's |
| 160 |
|
| 161 |
`name` or `uuid` in API versions 1.90 and prior works. |
| 162 |
""" |
| 163 |
|
| 164 |
max_microversion = '1.90' # Max API version allowed for testing: 1.90 |
| 165 |
min_microversion = '1.90' # Min API version allowed for testing: 1.90 |
| 166 |
|
| 167 |
def setUp(self): |
| 168 |
super(TestPortGroupsWithJsonExtSupport, self).setUp() |
| 169 |
self.useFixture( |
| 170 |
api_microversion_fixture.APIMicroversionFixture( |
| 171 |
self.min_microversion)) |
| 172 |
_, self.chassis = self.create_chassis() |
| 173 |
_, self.node = self.create_node(self.chassis['uuid']) |
| 174 |
_, self.portgroup = self.create_portgroup( |
| 175 |
self.node['uuid'], address=data_utils.rand_mac_address(), |
| 176 |
name=data_utils.rand_name('portgroup')) |
| 177 |
|
| 178 |
@decorators.idempotent_id('607ea131-ef5c-44e9-a900-a8e426b804e8') |
| 179 |
def test_delete_portgroup_with_json(self): |
| 180 |
"""Delete a portgroup while appending .json extension to its uuid""" |
| 181 |
self.delete_portgroup('%s.json' % self.portgroup['uuid']) |
| 182 |
self.assertRaises(lib_exc.NotFound, self.client.show_portgroup, |
| 183 |
self.portgroup['uuid']) |
| 184 |
|
| 185 |
@decorators.idempotent_id('9126ecac-310f-440a-81d4-ba9af1767845') |
| 186 |
def test_show_portgroup_with_json(self): |
| 187 |
"""Show a portgroup while appending .json extension to its uuid""" |
| 188 |
_, portgroup = self.client.show_portgroup('%s.json' % |
| 189 |
self.portgroup['uuid']) |
| 190 |
self._assertExpected(self.portgroup, portgroup) |
| 191 |
|
| 192 |
@decorators.idempotent_id('a6f154aa-e447-4576-89e2-9e8951fb7c43') |
| 193 |
def test_update_portgroup_with_json(self): |
| 194 |
"""Update a portgroup while appending .json extension to its uuid""" |
| 195 |
new_address = data_utils.rand_mac_address() |
| 196 |
new_extra = {'foo': 'test'} |
| 197 |
|
| 198 |
patch = [{'path': '/address', |
| 199 |
'op': 'replace', |
| 200 |
'value': new_address}, |
| 201 |
{'path': '/extra/foo', |
| 202 |
'op': 'replace', |
| 203 |
'value': new_extra['foo']}, |
| 204 |
] |
| 205 |
|
| 206 |
self.client.update_portgroup('%s.json' % self.portgroup['uuid'], |
| 207 |
patch) |
| 208 |
|
| 209 |
_, body = self.client.show_portgroup(self.portgroup['uuid']) |
| 210 |
|
| 211 |
self.assertEqual(new_address, body['address']) |
| 212 |
self._assertExpected(new_extra, body['extra']) |
| 213 |
|
| 214 |
|
| 215 |
class TestPortGroupsWithoutJsonExtSupport(base.BaseBaremetalTest): |
| 216 |
"""Basic test cases to validate appending .json extension to a portgroup's |
| 217 |
|
| 218 |
`name` or `uuid` in API versions later than 1.90 is disabled. |
| 219 |
""" |
| 220 |
|
| 221 |
min_microversion = '1.91' # Min API version allowed for testing: 1.91 |
| 222 |
|
| 223 |
def setUp(self): |
| 224 |
super(TestPortGroupsWithoutJsonExtSupport, self).setUp() |
| 225 |
_, self.chassis = self.create_chassis() |
| 226 |
_, self.node = self.create_node(self.chassis['uuid']) |
| 227 |
_, self.portgroup = self.create_portgroup( |
| 228 |
self.node['uuid'], address=data_utils.rand_mac_address(), |
| 229 |
name=data_utils.rand_name('portgroup')) |
| 230 |
|
| 231 |
@decorators.idempotent_id('2aede448-7165-4d54-92de-3be31ae19af0') |
| 232 |
def test_delete_portgroup_with_json(self): |
| 233 |
"""Trying to delete a portgroup while appending .json ext 404s""" |
| 234 |
self.assertRaises(lib_exc.NotFound, self.client.delete_portgroup, |
| 235 |
'%s.json' % self.portgroup['uuid']) |
| 236 |
|
| 237 |
@decorators.idempotent_id('be8ade56-8ac1-49f4-981a-93b403fa1d79') |
| 238 |
def test_show_portgroup_with_json(self): |
| 239 |
"""Trying to show a portgroup while appending .json ext 404s""" |
| 240 |
self.assertRaises(lib_exc.NotFound, self.client.show_portgroup, |
| 241 |
'%s.json' % self.portgroup['uuid']) |
| 242 |
|
| 243 |
@decorators.idempotent_id('f624352a-6560-4ec1-b4ff-ccfe7cda08f2') |
| 244 |
def test_update_portgroup_with_json(self): |
| 245 |
"""Trying to update a portgroup while appending .json ext 404s""" |
| 246 |
new_address = data_utils.rand_mac_address() |
| 247 |
new_extra = {'foo': 'test'} |
| 248 |
|
| 249 |
patch = [{'path': '/address', |
| 250 |
'op': 'replace', |
| 251 |
'value': new_address}, |
| 252 |
{'path': '/extra/foo', |
| 253 |
'op': 'replace', |
| 254 |
'value': new_extra['foo']}, |
| 255 |
] |
| 256 |
|
| 257 |
self.assertRaises(lib_exc.NotFound, self.client.update_portgroup, |
| 258 |
'%s.json' % self.portgroup['uuid'], patch) |