Allow get_unused_ip method to skip v6 and fix iter

Skip IPv6 subnets when looking for an unused IP in the
floating IP tests since floating IPs cannot be requested
with v6 addresses.

This also fixes the iterator for the non-allocation pool
case.

Closes-Bug: #1531706
Change-Id: Id0b2c28970ab61e45755818e3e0798daa4453ce7
This commit is contained in:
Kevin Benton 2016-01-06 12:48:28 -08:00
parent 3bcc1c3d4c
commit 8e54248653
2 changed files with 5 additions and 3 deletions

View File

@ -140,7 +140,7 @@ class FloatingIPAdminTestJSON(base.BaseAdminNetworkTest):
@test.attr(type='smoke')
@test.idempotent_id('332a8ae4-402e-4b98-bb6f-532e5a87b8e0')
def test_create_floatingip_with_specified_ip_address(self):
fip = self.get_unused_ip(self.ext_net_id)
fip = self.get_unused_ip(self.ext_net_id, ip_version=4)
body = self.admin_client.create_floatingip(
floating_network_id=self.ext_net_id,
floating_ip_address=fip)

View File

@ -544,7 +544,7 @@ class BaseAdminNetworkTest(BaseNetworkTest):
return service_profile
@classmethod
def get_unused_ip(cls, net_id):
def get_unused_ip(cls, net_id, ip_version=None):
"""Get an unused ip address in a allocaion pool of net"""
body = cls.admin_client.list_ports(network_id=net_id)
ports = body['ports']
@ -556,6 +556,8 @@ class BaseAdminNetworkTest(BaseNetworkTest):
subnets = body['subnets']
for subnet in subnets:
if ip_version and subnet['ip_version'] != ip_version:
continue
cidr = subnet['cidr']
allocation_pools = subnet['allocation_pools']
iterators = []
@ -570,7 +572,7 @@ class BaseAdminNetworkTest(BaseNetworkTest):
for ip in net:
if ip not in (net.network, net.broadcast):
yield ip
iterators.append(_iterip)
iterators.append(iter(_iterip()))
for iterator in iterators:
for ip in iterator: