Use different CIDRs for private and public subnets
In test "test_connectivity_dvr_and_no_dvr_routers_in_same_subnet", as
reported in the bug, the public IP (floating IP) and the private IP
are in the same CIDR. This breaks the isolation between networks.
Co-Authored-By: Rodolfo Alonso Hernandez <ralonsoh@redhat.com>
Closes-Bug: #1861282
Change-Id: I39ca6474068d2e169dff1b81d2a0c71a8361c01f
diff --git a/neutron_tempest_plugin/common/ip.py b/neutron_tempest_plugin/common/ip.py
index 265adf7..70a3dd5 100644
--- a/neutron_tempest_plugin/common/ip.py
+++ b/neutron_tempest_plugin/common/ip.py
@@ -348,3 +348,24 @@
return '%s %s %s %s %s %s' % (self.ip_address, self.hw_type,
self.flags, self.mac_address, self.mask,
self.device)
+
+
+def find_valid_cidr(valid_cidr='10.0.0.0/8', used_cidr=None):
+ total_ips = netaddr.IPSet(netaddr.IPNetwork(valid_cidr))
+ if used_cidr:
+ used_network = netaddr.IPNetwork(used_cidr)
+ netmask = used_network.netmask.netmask_bits()
+ valid_ips = total_ips.difference(netaddr.IPSet(used_network))
+ else:
+ valid_ips = total_ips
+ netmask = 24
+
+ for ip in valid_ips:
+ valid_network = netaddr.IPNetwork('%s/%s' % (ip, netmask))
+ if valid_network in valid_ips:
+ return valid_network.cidr
+
+ exception_str = 'No valid CIDR found in %s' % valid_cidr
+ if used_cidr:
+ exception_str += ', used CIDR %s' % used_cidr
+ raise Exception(exception_str)