Matthew Treinish | cb05806 | 2014-03-13 18:27:07 -0400 | [diff] [blame] | 1 | # Copyright 2014 IBM Corp. |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
| 15 | import keystoneclient.v2_0.client as keystoneclient |
| 16 | from mock import patch |
| 17 | import neutronclient.v2_0.client as neutronclient |
| 18 | from oslo.config import cfg |
| 19 | |
| 20 | from tempest.common import isolated_creds |
| 21 | from tempest import config |
Matthew Treinish | 23433a0 | 2014-03-17 16:43:50 -0400 | [diff] [blame] | 22 | from tempest import exceptions |
Matthew Treinish | cb05806 | 2014-03-13 18:27:07 -0400 | [diff] [blame] | 23 | from tempest.openstack.common.fixture import mockpatch |
| 24 | from tempest.services.identity.json import identity_client as json_iden_client |
| 25 | from tempest.services.identity.xml import identity_client as xml_iden_client |
| 26 | from tempest.services.network.json import network_client as json_network_client |
| 27 | from tempest.services.network.xml import network_client as xml_network_client |
| 28 | from tempest.tests import base |
| 29 | from tempest.tests import fake_config |
| 30 | |
| 31 | |
| 32 | class TestTenantIsolation(base.TestCase): |
| 33 | |
| 34 | def setUp(self): |
| 35 | super(TestTenantIsolation, self).setUp() |
| 36 | self.useFixture(fake_config.ConfigFixture()) |
| 37 | self.stubs.Set(config, 'TempestConfigPrivate', fake_config.FakePrivate) |
| 38 | |
| 39 | def test_tempest_client(self): |
| 40 | iso_creds = isolated_creds.IsolatedCreds('test class') |
| 41 | self.assertTrue(isinstance(iso_creds.identity_admin_client, |
| 42 | json_iden_client.IdentityClientJSON)) |
| 43 | self.assertTrue(isinstance(iso_creds.network_admin_client, |
| 44 | json_network_client.NetworkClientJSON)) |
| 45 | |
| 46 | def test_official_client(self): |
| 47 | self.useFixture(mockpatch.PatchObject(keystoneclient.Client, |
| 48 | 'authenticate')) |
| 49 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 50 | tempest_client=False) |
| 51 | self.assertTrue(isinstance(iso_creds.identity_admin_client, |
| 52 | keystoneclient.Client)) |
| 53 | self.assertTrue(isinstance(iso_creds.network_admin_client, |
| 54 | neutronclient.Client)) |
| 55 | |
| 56 | def test_tempest_client_xml(self): |
| 57 | iso_creds = isolated_creds.IsolatedCreds('test class', interface='xml') |
| 58 | self.assertEqual(iso_creds.interface, 'xml') |
| 59 | self.assertTrue(isinstance(iso_creds.identity_admin_client, |
| 60 | xml_iden_client.IdentityClientXML)) |
| 61 | self.assertTrue(isinstance(iso_creds.network_admin_client, |
| 62 | xml_network_client.NetworkClientXML)) |
| 63 | |
| 64 | def _mock_user_create(self, id, name): |
| 65 | user_fix = self.useFixture(mockpatch.PatchObject( |
| 66 | json_iden_client.IdentityClientJSON, |
| 67 | 'create_user', |
| 68 | return_value=({'status': 200}, |
| 69 | {'id': id, 'name': name}))) |
| 70 | return user_fix |
| 71 | |
| 72 | def _mock_tenant_create(self, id, name): |
| 73 | tenant_fix = self.useFixture(mockpatch.PatchObject( |
| 74 | json_iden_client.IdentityClientJSON, |
| 75 | 'create_tenant', |
| 76 | return_value=({'status': 200}, |
| 77 | {'id': id, 'name': name}))) |
| 78 | return tenant_fix |
| 79 | |
Matthew Treinish | e672326 | 2014-03-14 13:16:52 -0400 | [diff] [blame] | 80 | def _mock_network_create(self, iso_creds, id, name): |
| 81 | net_fix = self.useFixture(mockpatch.PatchObject( |
| 82 | iso_creds.network_admin_client, |
| 83 | 'create_network', |
| 84 | return_value=({'status': 200}, |
| 85 | {'network': {'id': id, 'name': name}}))) |
| 86 | return net_fix |
| 87 | |
| 88 | def _mock_subnet_create(self, iso_creds, id, name): |
| 89 | subnet_fix = self.useFixture(mockpatch.PatchObject( |
| 90 | iso_creds.network_admin_client, |
| 91 | 'create_subnet', |
| 92 | return_value=({'status': 200}, |
| 93 | {'subnet': {'id': id, 'name': name}}))) |
| 94 | return subnet_fix |
| 95 | |
| 96 | def _mock_router_create(self, id, name): |
| 97 | router_fix = self.useFixture(mockpatch.PatchObject( |
| 98 | json_network_client.NetworkClientJSON, |
| 99 | 'create_router', |
| 100 | return_value=({'status': 200}, |
| 101 | {'router': {'id': id, 'name': name}}))) |
| 102 | return router_fix |
| 103 | |
Matthew Treinish | cb05806 | 2014-03-13 18:27:07 -0400 | [diff] [blame] | 104 | @patch('tempest.common.rest_client.RestClient') |
| 105 | def test_primary_creds(self, MockRestClient): |
| 106 | cfg.CONF.set_default('neutron', False, 'service_available') |
| 107 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 108 | password='fake_password') |
| 109 | self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 110 | self._mock_user_create('1234', 'fake_prim_user') |
| 111 | username, tenant_name, password = iso_creds.get_primary_creds() |
| 112 | self.assertEqual(username, 'fake_prim_user') |
| 113 | self.assertEqual(tenant_name, 'fake_prim_tenant') |
| 114 | # Verify helper methods |
| 115 | tenant = iso_creds.get_primary_tenant() |
| 116 | user = iso_creds.get_primary_user() |
| 117 | self.assertEqual(tenant['id'], '1234') |
| 118 | self.assertEqual(user['id'], '1234') |
| 119 | |
| 120 | @patch('tempest.common.rest_client.RestClient') |
| 121 | def test_admin_creds(self, MockRestClient): |
| 122 | cfg.CONF.set_default('neutron', False, 'service_available') |
| 123 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 124 | password='fake_password') |
| 125 | self._mock_user_create('1234', 'fake_admin_user') |
| 126 | self._mock_tenant_create('1234', 'fake_admin_tenant') |
| 127 | self.useFixture(mockpatch.PatchObject( |
| 128 | json_iden_client.IdentityClientJSON, |
| 129 | 'list_roles', |
| 130 | return_value=({'status': 200}, |
| 131 | [{'id': '1234', 'name': 'admin'}]))) |
| 132 | |
| 133 | user_mock = patch.object(json_iden_client.IdentityClientJSON, |
| 134 | 'assign_user_role') |
| 135 | user_mock.start() |
| 136 | self.addCleanup(user_mock.stop) |
| 137 | with patch.object(json_iden_client.IdentityClientJSON, |
| 138 | 'assign_user_role') as user_mock: |
| 139 | username, tenant_name, password = iso_creds.get_admin_creds() |
| 140 | user_mock.assert_called_once_with('1234', '1234', '1234') |
| 141 | self.assertEqual(username, 'fake_admin_user') |
| 142 | self.assertEqual(tenant_name, 'fake_admin_tenant') |
| 143 | # Verify helper methods |
| 144 | tenant = iso_creds.get_admin_tenant() |
| 145 | user = iso_creds.get_admin_user() |
| 146 | self.assertEqual(tenant['id'], '1234') |
| 147 | self.assertEqual(user['id'], '1234') |
| 148 | |
| 149 | @patch('tempest.common.rest_client.RestClient') |
| 150 | def test_all_cred_cleanup(self, MockRestClient): |
| 151 | cfg.CONF.set_default('neutron', False, 'service_available') |
| 152 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 153 | password='fake_password') |
| 154 | tenant_fix = self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 155 | user_fix = self._mock_user_create('1234', 'fake_prim_user') |
| 156 | username, tenant_name, password = iso_creds.get_primary_creds() |
| 157 | tenant_fix.cleanUp() |
| 158 | user_fix.cleanUp() |
| 159 | tenant_fix = self._mock_tenant_create('12345', 'fake_alt_tenant') |
| 160 | user_fix = self._mock_user_create('12345', 'fake_alt_user') |
| 161 | alt_username, alt_tenant, alt_password = iso_creds.get_alt_creds() |
| 162 | tenant_fix.cleanUp() |
| 163 | user_fix.cleanUp() |
| 164 | tenant_fix = self._mock_tenant_create('123456', 'fake_admin_tenant') |
| 165 | user_fix = self._mock_user_create('123456', 'fake_admin_user') |
| 166 | self.useFixture(mockpatch.PatchObject( |
| 167 | json_iden_client.IdentityClientJSON, |
| 168 | 'list_roles', |
| 169 | return_value=({'status': 200}, |
| 170 | [{'id': '123456', 'name': 'admin'}]))) |
| 171 | with patch.object(json_iden_client.IdentityClientJSON, |
| 172 | 'assign_user_role'): |
| 173 | admin_username, admin_tenant, admin_pass = \ |
| 174 | iso_creds.get_admin_creds() |
| 175 | user_mock = self.patch( |
| 176 | 'tempest.services.identity.json.identity_client.' |
| 177 | 'IdentityClientJSON.delete_user') |
| 178 | tenant_mock = self.patch( |
| 179 | 'tempest.services.identity.json.identity_client.' |
| 180 | 'IdentityClientJSON.delete_tenant') |
| 181 | iso_creds.clear_isolated_creds() |
| 182 | # Verify user delete calls |
| 183 | calls = user_mock.mock_calls |
| 184 | self.assertEqual(len(calls), 3) |
| 185 | args = map(lambda x: x[1][0], calls) |
| 186 | self.assertIn('1234', args) |
| 187 | self.assertIn('12345', args) |
| 188 | self.assertIn('123456', args) |
| 189 | # Verify tenant delete calls |
| 190 | calls = tenant_mock.mock_calls |
| 191 | self.assertEqual(len(calls), 3) |
| 192 | args = map(lambda x: x[1][0], calls) |
| 193 | self.assertIn('1234', args) |
| 194 | self.assertIn('12345', args) |
| 195 | self.assertIn('123456', args) |
Matthew Treinish | e672326 | 2014-03-14 13:16:52 -0400 | [diff] [blame] | 196 | |
| 197 | @patch('tempest.common.rest_client.RestClient') |
| 198 | def test_alt_creds(self, MockRestClient): |
| 199 | cfg.CONF.set_default('neutron', False, 'service_available') |
| 200 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 201 | password='fake_password') |
| 202 | self._mock_user_create('1234', 'fake_alt_user') |
| 203 | self._mock_tenant_create('1234', 'fake_alt_tenant') |
| 204 | username, tenant_name, password = iso_creds.get_alt_creds() |
| 205 | self.assertEqual(username, 'fake_alt_user') |
| 206 | self.assertEqual(tenant_name, 'fake_alt_tenant') |
| 207 | # Verify helper methods |
| 208 | tenant = iso_creds.get_alt_tenant() |
| 209 | user = iso_creds.get_alt_user() |
| 210 | self.assertEqual(tenant['id'], '1234') |
| 211 | self.assertEqual(user['id'], '1234') |
| 212 | |
| 213 | @patch('tempest.common.rest_client.RestClient') |
| 214 | def test_network_creation(self, MockRestClient): |
| 215 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 216 | password='fake_password') |
| 217 | self._mock_user_create('1234', 'fake_prim_user') |
| 218 | self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 219 | self._mock_network_create(iso_creds, '1234', 'fake_net') |
| 220 | self._mock_subnet_create(iso_creds, '1234', 'fake_subnet') |
| 221 | self._mock_router_create('1234', 'fake_router') |
| 222 | router_interface_mock = self.patch( |
| 223 | 'tempest.services.network.json.network_client.NetworkClientJSON.' |
| 224 | 'add_router_interface_with_subnet_id') |
| 225 | username, tenant_name, password = iso_creds.get_primary_creds() |
| 226 | router_interface_mock.called_once_with('1234', '1234') |
| 227 | network = iso_creds.get_primary_network() |
| 228 | subnet = iso_creds.get_primary_subnet() |
| 229 | router = iso_creds.get_primary_router() |
| 230 | self.assertEqual(network['id'], '1234') |
| 231 | self.assertEqual(network['name'], 'fake_net') |
| 232 | self.assertEqual(subnet['id'], '1234') |
| 233 | self.assertEqual(subnet['name'], 'fake_subnet') |
| 234 | self.assertEqual(router['id'], '1234') |
| 235 | self.assertEqual(router['name'], 'fake_router') |
| 236 | |
| 237 | @patch('tempest.common.rest_client.RestClient') |
| 238 | def test_network_cleanup(self, MockRestClient): |
| 239 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 240 | password='fake_password') |
| 241 | # Create primary tenant and network |
| 242 | user_fix = self._mock_user_create('1234', 'fake_prim_user') |
| 243 | tenant_fix = self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 244 | net_fix = self._mock_network_create(iso_creds, '1234', 'fake_net') |
| 245 | subnet_fix = self._mock_subnet_create(iso_creds, '1234', 'fake_subnet') |
| 246 | router_fix = self._mock_router_create('1234', 'fake_router') |
| 247 | router_interface_mock = self.patch( |
| 248 | 'tempest.services.network.json.network_client.NetworkClientJSON.' |
| 249 | 'add_router_interface_with_subnet_id') |
| 250 | username, tenant_name, password = iso_creds.get_primary_creds() |
| 251 | router_interface_mock.called_once_with('1234', '1234') |
| 252 | router_interface_mock.reset_mock() |
| 253 | tenant_fix.cleanUp() |
| 254 | user_fix.cleanUp() |
| 255 | net_fix.cleanUp() |
| 256 | subnet_fix.cleanUp() |
| 257 | router_fix.cleanUp() |
| 258 | # Create alternate tenant and network |
| 259 | user_fix = self._mock_user_create('12345', 'fake_alt_user') |
| 260 | tenant_fix = self._mock_tenant_create('12345', 'fake_alt_tenant') |
| 261 | net_fix = self._mock_network_create(iso_creds, '12345', 'fake_alt_net') |
| 262 | subnet_fix = self._mock_subnet_create(iso_creds, '12345', |
| 263 | 'fake_alt_subnet') |
| 264 | router_fix = self._mock_router_create('12345', 'fake_alt_router') |
| 265 | alt_username, alt_tenant_name, password = iso_creds.get_alt_creds() |
| 266 | router_interface_mock.called_once_with('12345', '12345') |
| 267 | router_interface_mock.reset_mock() |
| 268 | tenant_fix.cleanUp() |
| 269 | user_fix.cleanUp() |
| 270 | net_fix.cleanUp() |
| 271 | subnet_fix.cleanUp() |
| 272 | router_fix.cleanUp() |
| 273 | # Create admin tenant and networks |
| 274 | user_fix = self._mock_user_create('123456', 'fake_admin_user') |
| 275 | tenant_fix = self._mock_tenant_create('123456', 'fake_admin_tenant') |
| 276 | net_fix = self._mock_network_create(iso_creds, '123456', |
| 277 | 'fake_admin_net') |
| 278 | subnet_fix = self._mock_subnet_create(iso_creds, '123456', |
| 279 | 'fake_admin_subnet') |
| 280 | router_fix = self._mock_router_create('123456', 'fake_admin_router') |
| 281 | self.useFixture(mockpatch.PatchObject( |
| 282 | json_iden_client.IdentityClientJSON, |
| 283 | 'list_roles', |
| 284 | return_value=({'status': 200}, |
| 285 | [{'id': '123456', 'name': 'admin'}]))) |
| 286 | with patch.object(json_iden_client.IdentityClientJSON, |
| 287 | 'assign_user_role'): |
| 288 | admin_user, admin_tenant, password = iso_creds.get_admin_creds() |
| 289 | self.patch('tempest.services.identity.json.identity_client.' |
| 290 | 'IdentityClientJSON.delete_user') |
| 291 | self.patch('tempest.services.identity.json.identity_client.' |
| 292 | 'IdentityClientJSON.delete_tenant') |
| 293 | net = patch.object(iso_creds.network_admin_client, |
| 294 | 'delete_network') |
| 295 | net_mock = net.start() |
| 296 | subnet = patch.object(iso_creds.network_admin_client, |
| 297 | 'delete_subnet') |
| 298 | subnet_mock = subnet.start() |
| 299 | router = patch.object(iso_creds.network_admin_client, |
| 300 | 'delete_router') |
| 301 | router_mock = router.start() |
| 302 | remove_router_interface_mock = self.patch( |
| 303 | 'tempest.services.network.json.network_client.NetworkClientJSON.' |
| 304 | 'remove_router_interface_with_subnet_id') |
| 305 | port_list_mock = patch.object(iso_creds.network_admin_client, |
| 306 | 'list_ports', return_value=( |
| 307 | {'status': 200}, {'ports': []})) |
| 308 | port_list_mock.start() |
| 309 | iso_creds.clear_isolated_creds() |
| 310 | # Verify remove router interface calls |
| 311 | calls = remove_router_interface_mock.mock_calls |
| 312 | self.assertEqual(len(calls), 3) |
| 313 | args = map(lambda x: x[1], calls) |
| 314 | self.assertIn(('1234', '1234'), args) |
| 315 | self.assertIn(('12345', '12345'), args) |
| 316 | self.assertIn(('123456', '123456'), args) |
| 317 | # Verify network delete calls |
| 318 | calls = net_mock.mock_calls |
| 319 | self.assertEqual(len(calls), 3) |
| 320 | args = map(lambda x: x[1][0], calls) |
| 321 | self.assertIn('1234', args) |
| 322 | self.assertIn('12345', args) |
| 323 | self.assertIn('123456', args) |
| 324 | # Verify subnet delete calls |
| 325 | calls = subnet_mock.mock_calls |
| 326 | self.assertEqual(len(calls), 3) |
| 327 | args = map(lambda x: x[1][0], calls) |
| 328 | self.assertIn('1234', args) |
| 329 | self.assertIn('12345', args) |
| 330 | self.assertIn('123456', args) |
| 331 | # Verify router delete calls |
| 332 | calls = router_mock.mock_calls |
| 333 | self.assertEqual(len(calls), 3) |
| 334 | args = map(lambda x: x[1][0], calls) |
| 335 | self.assertIn('1234', args) |
| 336 | self.assertIn('12345', args) |
| 337 | self.assertIn('123456', args) |
Matthew Treinish | 23433a0 | 2014-03-17 16:43:50 -0400 | [diff] [blame] | 338 | |
| 339 | @patch('tempest.common.rest_client.RestClient') |
| 340 | def test_network_alt_creation(self, MockRestClient): |
| 341 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 342 | password='fake_password') |
| 343 | self._mock_user_create('1234', 'fake_alt_user') |
| 344 | self._mock_tenant_create('1234', 'fake_alt_tenant') |
| 345 | self._mock_network_create(iso_creds, '1234', 'fake_alt_net') |
| 346 | self._mock_subnet_create(iso_creds, '1234', 'fake_alt_subnet') |
| 347 | self._mock_router_create('1234', 'fake_alt_router') |
| 348 | router_interface_mock = self.patch( |
| 349 | 'tempest.services.network.json.network_client.NetworkClientJSON.' |
| 350 | 'add_router_interface_with_subnet_id') |
| 351 | username, tenant_name, password = iso_creds.get_alt_creds() |
| 352 | router_interface_mock.called_once_with('1234', '1234') |
| 353 | network = iso_creds.get_alt_network() |
| 354 | subnet = iso_creds.get_alt_subnet() |
| 355 | router = iso_creds.get_alt_router() |
| 356 | self.assertEqual(network['id'], '1234') |
| 357 | self.assertEqual(network['name'], 'fake_alt_net') |
| 358 | self.assertEqual(subnet['id'], '1234') |
| 359 | self.assertEqual(subnet['name'], 'fake_alt_subnet') |
| 360 | self.assertEqual(router['id'], '1234') |
| 361 | self.assertEqual(router['name'], 'fake_alt_router') |
| 362 | |
| 363 | @patch('tempest.common.rest_client.RestClient') |
| 364 | def test_network_admin_creation(self, MockRestClient): |
| 365 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 366 | password='fake_password') |
| 367 | self._mock_user_create('1234', 'fake_admin_user') |
| 368 | self._mock_tenant_create('1234', 'fake_admin_tenant') |
| 369 | self._mock_network_create(iso_creds, '1234', 'fake_admin_net') |
| 370 | self._mock_subnet_create(iso_creds, '1234', 'fake_admin_subnet') |
| 371 | self._mock_router_create('1234', 'fake_admin_router') |
| 372 | router_interface_mock = self.patch( |
| 373 | 'tempest.services.network.json.network_client.NetworkClientJSON.' |
| 374 | 'add_router_interface_with_subnet_id') |
| 375 | self.useFixture(mockpatch.PatchObject( |
| 376 | json_iden_client.IdentityClientJSON, |
| 377 | 'list_roles', |
| 378 | return_value=({'status': 200}, |
| 379 | [{'id': '123456', 'name': 'admin'}]))) |
| 380 | with patch.object(json_iden_client.IdentityClientJSON, |
| 381 | 'assign_user_role'): |
| 382 | username, tenant_name, password = iso_creds.get_admin_creds() |
| 383 | router_interface_mock.called_once_with('1234', '1234') |
| 384 | network = iso_creds.get_admin_network() |
| 385 | subnet = iso_creds.get_admin_subnet() |
| 386 | router = iso_creds.get_admin_router() |
| 387 | self.assertEqual(network['id'], '1234') |
| 388 | self.assertEqual(network['name'], 'fake_admin_net') |
| 389 | self.assertEqual(subnet['id'], '1234') |
| 390 | self.assertEqual(subnet['name'], 'fake_admin_subnet') |
| 391 | self.assertEqual(router['id'], '1234') |
| 392 | self.assertEqual(router['name'], 'fake_admin_router') |
| 393 | |
| 394 | @patch('tempest.common.rest_client.RestClient') |
| 395 | def test_no_network_resources(self, MockRestClient): |
| 396 | net_dict = { |
| 397 | 'network': False, |
| 398 | 'router': False, |
| 399 | 'subnet': False, |
| 400 | 'dhcp': False, |
| 401 | } |
| 402 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 403 | password='fake_password', |
| 404 | network_resources=net_dict) |
| 405 | self._mock_user_create('1234', 'fake_prim_user') |
| 406 | self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 407 | net = patch.object(iso_creds.network_admin_client, |
| 408 | 'delete_network') |
| 409 | net_mock = net.start() |
| 410 | subnet = patch.object(iso_creds.network_admin_client, |
| 411 | 'delete_subnet') |
| 412 | subnet_mock = subnet.start() |
| 413 | router = patch.object(iso_creds.network_admin_client, |
| 414 | 'delete_router') |
| 415 | router_mock = router.start() |
| 416 | |
| 417 | username, tenant_name, password = iso_creds.get_primary_creds() |
| 418 | self.assertEqual(net_mock.mock_calls, []) |
| 419 | self.assertEqual(subnet_mock.mock_calls, []) |
| 420 | self.assertEqual(router_mock.mock_calls, []) |
| 421 | network = iso_creds.get_primary_network() |
| 422 | subnet = iso_creds.get_primary_subnet() |
| 423 | router = iso_creds.get_primary_router() |
| 424 | self.assertIsNone(network) |
| 425 | self.assertIsNone(subnet) |
| 426 | self.assertIsNone(router) |
| 427 | |
| 428 | @patch('tempest.common.rest_client.RestClient') |
| 429 | def test_router_without_network(self, MockRestClient): |
| 430 | net_dict = { |
| 431 | 'network': False, |
| 432 | 'router': True, |
| 433 | 'subnet': False, |
| 434 | 'dhcp': False, |
| 435 | } |
| 436 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 437 | password='fake_password', |
| 438 | network_resources=net_dict) |
| 439 | self._mock_user_create('1234', 'fake_prim_user') |
| 440 | self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 441 | self.assertRaises(exceptions.InvalidConfiguration, |
| 442 | iso_creds.get_primary_creds) |
| 443 | |
| 444 | @patch('tempest.common.rest_client.RestClient') |
| 445 | def test_subnet_without_network(self, MockRestClient): |
| 446 | net_dict = { |
| 447 | 'network': False, |
| 448 | 'router': False, |
| 449 | 'subnet': True, |
| 450 | 'dhcp': False, |
| 451 | } |
| 452 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 453 | password='fake_password', |
| 454 | network_resources=net_dict) |
| 455 | self._mock_user_create('1234', 'fake_prim_user') |
| 456 | self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 457 | self.assertRaises(exceptions.InvalidConfiguration, |
| 458 | iso_creds.get_primary_creds) |
| 459 | |
| 460 | @patch('tempest.common.rest_client.RestClient') |
| 461 | def test_dhcp_without_subnet(self, MockRestClient): |
| 462 | net_dict = { |
| 463 | 'network': False, |
| 464 | 'router': False, |
| 465 | 'subnet': False, |
| 466 | 'dhcp': True, |
| 467 | } |
| 468 | iso_creds = isolated_creds.IsolatedCreds('test class', |
| 469 | password='fake_password', |
| 470 | network_resources=net_dict) |
| 471 | self._mock_user_create('1234', 'fake_prim_user') |
| 472 | self._mock_tenant_create('1234', 'fake_prim_tenant') |
| 473 | self.assertRaises(exceptions.InvalidConfiguration, |
| 474 | iso_creds.get_primary_creds) |