def create_subnet(cls, network, gateway='', cidr=None, mask_bits=None, ip_version=None, client=None, **kwargs): """Wrapper utility that returns a test subnet.""" # allow tests to use admin client if not client: client = cls.client # The cidr and mask_bits depend on the ip version. ip_version = ip_version if ip_version is not None else cls._ip_version gateway_not_set = gateway == '' if ip_version == 4: cidr = cidr or netaddr.IPNetwork( config.safe_get_config_value('network', 'project_network_cidr')) mask_bits = (mask_bits or config.safe_get_config_value( 'network', 'project_network_mask_bits')) elif ip_version == 6: cidr = (cidr or netaddr.IPNetwork( config.safe_get_config_value('network', 'project_network_v6_cidr'))) mask_bits = (mask_bits or config.safe_get_config_value( 'network', 'project_network_v6_mask_bits')) # Find a cidr that is not in use yet and create a subnet with it for subnet_cidr in cidr.subnet(mask_bits): if gateway_not_set: gateway_ip = str(netaddr.IPAddress(subnet_cidr) + 1) else: gateway_ip = gateway try: body = client.create_subnet(network_id=network['id'], cidr=str(subnet_cidr), ip_version=ip_version, gateway_ip=gateway_ip, **kwargs) break except lib_exc.BadRequest as e: is_overlapping_cidr = 'overlaps with another subnet' in str(e) if not is_overlapping_cidr: raise else: message = 'Available CIDR for subnet creation could not be found' raise ValueError(message) subnet = body['subnet'] if client is cls.client: cls.subnets.append(subnet) else: cls.admin_subnets.append(subnet) return subnet
def test_update_port_with_cidr_address_pair(self): # Update allowed address pair with cidr cidr = str( netaddr.IPNetwork( config.safe_get_config_value('network', 'project_network_cidr'))) self._update_port_with_address(cidr)
def _create_subnet(self, network, ip_version): if ip_version == lib_constants.IP_VERSION_4: cidr = netaddr.IPNetwork('20.0.0.0/24') mask_bits = config.safe_get_config_value( 'network', 'project_network_mask_bits') elif ip_version == lib_constants.IP_VERSION_6: cidr = netaddr.IPNetwork('20:db8::/64') mask_bits = config.safe_get_config_value( 'network', 'project_network_v6_mask_bits') subnet_cidr = next(cidr.subnet(mask_bits)) prefix_len = subnet_cidr.prefixlen subnet = self.create_subnet(network, cidr=subnet_cidr, enable_dhcp=False, mask_bits=mask_bits, ip_version=ip_version) return subnet, prefix_len
def test_subport_connectivity(self): vlan_tag = 10 vlan_network = self.create_network() new_subnet_cidr = get_next_subnet( config.safe_get_config_value('network', 'project_network_cidr')) self.create_subnet(vlan_network, cidr=new_subnet_cidr) servers = [ self._create_server_with_port_and_subport(vlan_network, vlan_tag) for i in range(2) ] for server in servers: self._wait_for_server(server) # Configure VLAN interfaces on server command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag} server['ssh_client'].exec_command(command) # Ping from server1 to server2 via VLAN interface servers[0]['ssh_client'].ping_host( servers[1]['subport']['fixed_ips'][0]['ip_address'])
def test_subport_connectivity(self): vlan_tag = 10 vlan_network = self.create_network() new_subnet_cidr = get_next_subnet( config.safe_get_config_value('network', 'project_network_cidr')) self.create_subnet(vlan_network, gateway=None, cidr=new_subnet_cidr) servers = [ self._create_server_with_port_and_subport(vlan_network, vlan_tag) for i in range(2) ] for server in servers: self._wait_for_server(server) # Configure VLAN interfaces on server command = CONFIGURE_VLAN_INTERFACE_COMMANDS % {'tag': vlan_tag} server['ssh_client'].exec_command(command) out = server['ssh_client'].exec_command( 'PATH=$PATH:/usr/sbin;ip addr list') LOG.debug("Interfaces on server %s: %s", server, out) # Ping from server1 to server2 via VLAN interface should fail because # we haven't allowed ICMP self.check_remote_connectivity( servers[0]['ssh_client'], servers[1]['subport']['fixed_ips'][0]['ip_address'], should_succeed=False) # allow intra-securitygroup traffic self.client.create_security_group_rule( security_group_id=self.secgroup['security_group']['id'], direction='ingress', ethertype='IPv4', protocol='icmp', remote_group_id=self.secgroup['security_group']['id']) self.check_remote_connectivity( servers[0]['ssh_client'], servers[1]['subport']['fixed_ips'][0]['ip_address'], should_succeed=True)
def resource_setup(cls): super(RoutersTest, cls).resource_setup() cls.tenant_cidr = (config.safe_get_config_value( 'network', 'project_network_cidr') if cls._ip_version == 4 else config.safe_get_config_value( 'network', 'project_network_v6_cidr'))