Best Python code snippet using tempest_python
test_address_scope.py
Source:test_address_scope.py
...222 plugin = DB_PLUGIN_KLASS223 ext_mgr = AddressScopeTestExtensionManager()224 super(TestSubnetPoolsWithAddressScopes, self).setUp(plugin=plugin,225 ext_mgr=ext_mgr)226 def _test_create_subnetpool(self, prefixes, expected=None,227 admin=False, **kwargs):228 keys = kwargs.copy()229 keys.setdefault('tenant_id', self._tenant_id)230 with self.subnetpool(prefixes, admin, **keys) as subnetpool:231 self._validate_resource(subnetpool, keys, 'subnetpool')232 if expected:233 self._compare_resource(subnetpool, expected, 'subnetpool')234 return subnetpool235 def test_create_subnetpool_associate_address_scope(self):236 with self.address_scope(name='foo-address-scope') as addr_scope:237 address_scope_id = addr_scope['address_scope']['id']238 subnet = netaddr.IPNetwork('10.10.10.0/24')239 expected = {'address_scope_id': address_scope_id}240 self._test_create_subnetpool([subnet.cidr], expected=expected,241 name='foo-subnetpool',242 min_prefixlen='21',243 address_scope_id=address_scope_id)244 def test_create_subnetpool_associate_invalid_address_scope(self):245 self.assertRaises(246 webob.exc.HTTPClientError, self._test_create_subnetpool, [],247 min_prefixlen='21', address_scope_id='foo-addr-scope-id')248 def test_create_subnetpool_assoc_address_scope_with_prefix_intersect(self):249 with self.address_scope(name='foo-address-scope') as addr_scope:250 address_scope_id = addr_scope['address_scope']['id']251 subnet = netaddr.IPNetwork('10.10.10.0/24')252 expected = {'address_scope_id': address_scope_id}253 self._test_create_subnetpool([subnet.cidr], expected=expected,254 name='foo-subnetpool',255 min_prefixlen='21',256 address_scope_id=address_scope_id)257 overlap_subnet = netaddr.IPNetwork('10.10.10.10/24')258 self.assertRaises(259 webob.exc.HTTPClientError, self._test_create_subnetpool,260 [overlap_subnet.cidr], min_prefixlen='21',261 address_scope_id=address_scope_id)262 def test_update_subnetpool_associate_address_scope(self):263 subnet = netaddr.IPNetwork('10.10.10.0/24')264 initial_subnetpool = self._test_create_subnetpool([subnet.cidr],265 name='foo-sp',266 min_prefixlen='21')267 with self.address_scope(name='foo-address-scope') as addr_scope:268 address_scope_id = addr_scope['address_scope']['id']269 data = {'subnetpool': {'address_scope_id': address_scope_id}}270 req = self.new_update_request(271 'subnetpools', data, initial_subnetpool['subnetpool']['id'])272 api = self._api_for_resource('subnetpools')273 res = self.deserialize(self.fmt, req.get_response(api))274 self._compare_resource(res, data['subnetpool'], 'subnetpool')275 def test_update_subnetpool_associate_invalid_address_scope(self):276 subnet = netaddr.IPNetwork('10.10.10.0/24')277 initial_subnetpool = self._test_create_subnetpool([subnet.cidr],278 name='foo-sp',279 min_prefixlen='21')280 data = {'subnetpool': {'address_scope_id': 'foo-addr-scope-id'}}281 req = self.new_update_request(282 'subnetpools', data, initial_subnetpool['subnetpool']['id'])283 api = self._api_for_resource('subnetpools')284 res = req.get_response(api)285 self.assertEqual(webob.exc.HTTPClientError.code, res.status_int)286 def test_update_subnetpool_disassociate_address_scope(self):287 with self.address_scope(name='foo-address-scope') as addr_scope:288 address_scope_id = addr_scope['address_scope']['id']289 subnet = netaddr.IPNetwork('10.10.10.0/24')290 expected = {'address_scope_id': address_scope_id}291 initial_subnetpool = self._test_create_subnetpool(292 [subnet.cidr], expected=expected, name='foo-sp',293 min_prefixlen='21', address_scope_id=address_scope_id)294 data = {'subnetpool': {'address_scope_id': None}}295 req = self.new_update_request(296 'subnetpools', data, initial_subnetpool['subnetpool']['id'])297 api = self._api_for_resource('subnetpools')298 res = self.deserialize(self.fmt, req.get_response(api))299 self._compare_resource(res, data['subnetpool'], 'subnetpool')300 def test_update_subnetpool_associate_another_address_scope(self):301 with self.address_scope(name='foo-address-scope') as addr_scope:302 address_scope_id = addr_scope['address_scope']['id']303 subnet = netaddr.IPNetwork('10.10.10.0/24')304 expected = {'address_scope_id': address_scope_id}305 initial_subnetpool = self._test_create_subnetpool(306 [subnet.cidr], expected=expected, name='foo-sp',307 min_prefixlen='21', address_scope_id=address_scope_id)308 with self.address_scope(name='foo-address-scope') as other_a_s:309 other_a_s_id = other_a_s['address_scope']['id']310 update_data = {'subnetpool': {'address_scope_id':311 other_a_s_id}}312 req = self.new_update_request(313 'subnetpools', update_data,314 initial_subnetpool['subnetpool']['id'])315 api = self._api_for_resource('subnetpools')316 res = self.deserialize(self.fmt, req.get_response(api))317 self._compare_resource(res, update_data['subnetpool'],318 'subnetpool')319 def _test_update_subnetpool_address_scope_notify(self, as_change=True):320 with self.address_scope(name='foo-address-scope') as addr_scope:321 foo_as_id = addr_scope['address_scope']['id']322 subnet = netaddr.IPNetwork('10.10.10.0/24')323 initial_subnetpool = self._test_create_subnetpool(324 [subnet.cidr], name='foo-sp',325 min_prefixlen='21', address_scope_id=foo_as_id)326 subnetpool_id = initial_subnetpool['subnetpool']['id']327 with self.address_scope(name='bar-address-scope') as other_as, \328 self.network() as network:329 data = {'subnet': {330 'network_id': network['network']['id'],331 'subnetpool_id': subnetpool_id,332 'prefixlen': 24,333 'ip_version': 4,334 'tenant_id': network['network']['tenant_id']}}335 req = self.new_create_request('subnets', data)336 subnet = self.deserialize(self.fmt,337 req.get_response(self.api))338 with mock.patch.object(registry, 'notify') as notify:339 plugin = db_base_plugin_v2.NeutronDbPluginV2()340 plugin.is_address_scope_owned_by_tenant = mock.Mock(341 return_value=True)342 plugin._validate_address_scope_id = mock.Mock()343 ctx = context.get_admin_context()344 bar_as_id = other_as['address_scope']['id']345 data = {'subnetpool': {346 'name': 'bar-sp'}}347 if as_change:348 data['subnetpool']['address_scope_id'] = bar_as_id349 updated_sp = plugin.update_subnetpool(350 ctx, subnetpool_id, data)351 self.assertEqual('bar-sp', updated_sp['name'])352 if as_change:353 self.assertEqual(bar_as_id,354 updated_sp['address_scope_id'])355 notify.assert_called_once_with(356 resources.SUBNETPOOL_ADDRESS_SCOPE,357 events.AFTER_UPDATE,358 plugin.update_subnetpool, context=ctx,359 subnetpool_id=subnetpool_id)360 else:361 self.assertEqual(foo_as_id,362 updated_sp['address_scope_id'])363 self.assertFalse(notify.called)364 def test_update_subnetpool_address_scope_notify(self):365 self._test_update_subnetpool_address_scope_notify()366 def test_not_update_subnetpool_address_scope_not_notify(self):367 self._test_update_subnetpool_address_scope_notify(False)368 def test_network_create_contain_address_scope_attr(self):369 with self.network() as network:370 result = self._show('networks', network['network']['id'])371 keys = [ext_address_scope.IPV4_ADDRESS_SCOPE,372 ext_address_scope.IPV6_ADDRESS_SCOPE]373 for k in keys:374 # Correlated address scopes should initially be None375 self.assertIsNone(result['network'][k])376 def test_correlate_network_with_address_scope(self):377 with self.address_scope(name='v4-as') as v4_addr_scope, \378 self.address_scope(379 name='v6-as',380 ip_version=constants.IP_VERSION_6) as v6_addr_scope, \381 self.network() as network:382 v4_as_id = v4_addr_scope['address_scope']['id']383 subnet = netaddr.IPNetwork('10.10.10.0/24')384 v4_subnetpool = self._test_create_subnetpool(385 [subnet.cidr], name='v4-sp',386 min_prefixlen='24', address_scope_id=v4_as_id)387 v4_subnetpool_id = v4_subnetpool['subnetpool']['id']388 v6_as_id = v6_addr_scope['address_scope']['id']389 subnet = netaddr.IPNetwork('fd5c:6ee1:c7ae::/64')390 v6_subnetpool = self._test_create_subnetpool(391 [subnet.cidr], name='v6-sp',392 min_prefixlen='64', address_scope_id=v6_as_id)393 v6_subnetpool_id = v6_subnetpool['subnetpool']['id']394 data = {'subnet': {395 'network_id': network['network']['id'],396 'subnetpool_id': v4_subnetpool_id,397 'ip_version': 4,398 'tenant_id': network['network']['tenant_id']}}399 req = self.new_create_request('subnets', data)400 self.deserialize(self.fmt, req.get_response(self.api))401 data['subnet']['subnetpool_id'] = v6_subnetpool_id402 data['subnet']['ip_version'] = 6403 req = self.new_create_request('subnets', data)404 self.deserialize(self.fmt, req.get_response(self.api))405 result = self._show('networks', network['network']['id'])406 self.assertEqual(407 v4_as_id,408 result['network'][ext_address_scope.IPV4_ADDRESS_SCOPE])409 self.assertEqual(410 v6_as_id,411 result['network'][ext_address_scope.IPV6_ADDRESS_SCOPE])412 def test_delete_address_scope_in_use(self):413 with self.address_scope(name='foo-address-scope') as addr_scope:414 address_scope_id = addr_scope['address_scope']['id']415 subnet = netaddr.IPNetwork('10.10.10.0/24')416 expected = {'address_scope_id': address_scope_id}417 self._test_create_subnetpool([subnet.cidr], expected=expected,418 name='foo-subnetpool',419 min_prefixlen='21',420 address_scope_id=address_scope_id)421 self._delete('address-scopes', address_scope_id,422 expected_code=webob.exc.HTTPConflict.code)423 def test_add_subnetpool_address_scope_wrong_address_family(self):424 with self.address_scope(constants.IP_VERSION_6,425 name='foo-address-scope') as addr_scope:426 address_scope_id = addr_scope['address_scope']['id']427 subnet = netaddr.IPNetwork('10.10.10.0/24')428 self.assertRaises(webob.exc.HTTPClientError,429 self._test_create_subnetpool,430 [subnet.cidr], name='foo-subnetpool',431 min_prefixlen='21',432 address_scope_id=address_scope_id)433 def test_update_subnetpool_associate_address_scope_wrong_family(self):434 with self.address_scope(constants.IP_VERSION_6,435 name='foo-address-scope') as addr_scope:436 address_scope_id = addr_scope['address_scope']['id']437 subnet = netaddr.IPNetwork('2001:db8::/64')438 expected = {'address_scope_id': address_scope_id}439 initial_subnetpool = self._test_create_subnetpool(440 [subnet.cidr], expected=expected, name='foo-sp',441 min_prefixlen='64', address_scope_id=address_scope_id)442 with self.address_scope(name='foo-address-scope') as other_a_s:443 other_a_s_id = other_a_s['address_scope']['id']444 update_data = {'subnetpool': {'address_scope_id':445 other_a_s_id}}446 req = self.new_update_request(447 'subnetpools', update_data,448 initial_subnetpool['subnetpool']['id'])449 api = self._api_for_resource('subnetpools')450 res = req.get_response(api)451 self.assertEqual(webob.exc.HTTPBadRequest.code,...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!