How to use cidr_in_use method in tempest

Best Python code snippet using tempest_python

appliance_manager.py

Source:appliance_manager.py Github

copy

Full Screen

...109 if not subnets_client:110 subnets_client = self.subnets_client111 if not routers_client:112 routers_client = self.routers_client113 def cidr_in_use(cidr, tenant_id):114 """Check cidr existence115 :returns: True if subnet with cidr already exist in tenant116 False else117 """118 cidr_in_use = \119 self.os_admin.subnets_client.list_subnets(tenant_id=tenant_id,120 cidr=cidr)['subnets']121 return len(cidr_in_use) != 0122 if ip_version == 6:123 tenant_cidr = (cidr or netaddr.IPNetwork(124 CONF.network.project_network_v6_cidr))125 mask_bits = mask_bits or CONF.network.project_network_v6_mask_bits126 else:127 tenant_cidr = cidr or netaddr.IPNetwork(128 CONF.network.project_network_cidr)129 mask_bits = mask_bits or CONF.network.project_network_mask_bits130 str_cidr = str(tenant_cidr)131 if not cidr:132 # Repeatedly attempt subnet creation with sequential cidr133 # blocks until an unallocated block is found.134 for subnet_cidr in tenant_cidr.subnet(mask_bits):135 str_cidr = str(subnet_cidr)136 if not cidr_in_use(str_cidr, tenant_id=network['tenant_id']):137 break138 else:139 if cidr_in_use(str_cidr, tenant_id=network['tenant_id']):140 LOG.error("Specified subnet %r is in use" % str_cidr)141 raise142 subnet = dict(name=data_utils.rand_name(subnet_name_),143 network_id=network['id'], tenant_id=network['tenant_id'],144 cidr=str_cidr, ip_version=ip_version, **kwargs)145 try:146 result = None147 result = subnets_client.create_subnet(**subnet)148 except lib_exc.Conflict as e:149 is_overlapping_cidr = 'overlaps with another subnet' in str(e)150 if not is_overlapping_cidr:151 raise152 self.assertIsNotNone(result, 'Unable to allocate tenant network')153 subnet = result['subnet']...

Full Screen

Full Screen

base.py

Source:base.py Github

copy

Full Screen

...135 'ip_version': 4}136 if values:137 kwargs.update(values)138 client = client or self.subnets_client139 def cidr_in_use(cidr, project_id):140 """Check cidr existence141 :returns: True if subnet with cidr already exist in tenant142 False else143 """144 cidr_in_use = self.os_admin.subnets_client.list_subnets(145 project_id=project_id, cidr=cidr)['subnets']146 return len(cidr_in_use) != 0147 if allocate_cidr:148 tenant_cidr = netaddr.IPNetwork(CONF.network.project_network_cidr)149 num_bits = CONF.network.project_network_mask_bits150 subnet = None151 str_cidr = None152 # Repeatedly attempt subnet creation with sequential cidr153 # blocks until an unallocated block is found.154 for subnet_cidr in tenant_cidr.subnet(num_bits):155 str_cidr = str(subnet_cidr)156 if cidr_in_use(str_cidr, project_id=network['project_id']):157 continue158 kwargs['cidr'] = str_cidr159 try:160 subnet = client.create_subnet(**kwargs)['subnet']161 self.addCleanup(client.delete_subnet, subnet['id'])162 break163 except lib_exc.Conflict as e:164 is_overlapping_cidr = \165 'overlaps with another subnet' in str(e)166 if not is_overlapping_cidr:167 raise168 self.assertIsNotNone(subnet, 'Unable to allocate tenant network')169 self.assertEqual(subnet['cidr'], str_cidr)170 return subnet...

Full Screen

Full Screen

network_base.py

Source:network_base.py Github

copy

Full Screen

...88 def create_subnet(self, network, client=None,89 namestart='subnet-smoke', **kwargs):90 if not client:91 client = self.subnets_client92 def cidr_in_use(cidr, tenant_id):93 """94 :return True if subnet with cidr already exist in tenant95 False else96 """97 cidr_in_use = self._list_subnets(tenant_id=tenant_id, cidr=cidr)98 return len(cidr_in_use) != 099 ip_version = kwargs.pop('ip_version', 4)100 if ip_version == 6:101 netaddr.IPNetwork(102 CONF.network.project_network_v6_cidr)103 CONF.network.project_network_v6_mask_bits104 else:105 netaddr.IPNetwork(CONF.network.project_network_cidr)106 CONF.network.project_network_mask_bits...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful