Reverse order of get_unused_ip_addresses

If a test author forgets to disable DHCP on a subnet
used for a test (e.g. I17e201ef8822cace86bf805d6bd5a2e4d0e9084d),
returning the first IP address in the subnet can race with the
creation of the DHCP port. As a defensive measure this adjusts
the logic to get unused IP addresses starting with the last
addresses in the subnet instead.

Change-Id: I31b9fcc9140de08e907bec08584a8c29ec6004e9
This commit is contained in:
Kevin Benton 2016-07-13 16:20:06 -07:00
parent a70710bb36
commit 6f455aa398

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import itertools
import netaddr
from tempest.lib import exceptions as lib_exc
@ -39,10 +38,11 @@ def get_unused_ip_addresses(ports_client, subnets_client,
alloc_set.add(fixed_ip['ip_address'])
av_set = subnet_set - alloc_set
ip_list = [str(ip) for ip in itertools.islice(av_set, count)]
if len(ip_list) != count:
msg = "Insufficient IP addresses available"
raise lib_exc.BadRequest(message=msg)
return ip_list
addrs = []
for cidr in reversed(av_set.iter_cidrs()):
for ip in reversed(cidr):
addrs.append(str(ip))
if len(addrs) == count:
return addrs
msg = "Insufficient IP addresses available"
raise lib_exc.BadRequest(message=msg)