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
diff --git a/tempest/common/utils/net_utils.py b/tempest/common/utils/net_utils.py
index d98fb32..fd0391d 100644
--- a/tempest/common/utils/net_utils.py
+++ b/tempest/common/utils/net_utils.py
@@ -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 @@
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)