Use get_unused_ip_addresses to obtain IP
Performing arithmetic operations to find unallocated IPs is unreliable
due to inconsistencies in IP allocation.
Related-Prod: PRODX-53911
Change-Id: Id9dbbbe3f327b39beb0f517495f0c6377f0b97c8
diff --git a/neutron_tempest_plugin/scenario/test_dhcp.py b/neutron_tempest_plugin/scenario/test_dhcp.py
index 31d2930..defe37b 100644
--- a/neutron_tempest_plugin/scenario/test_dhcp.py
+++ b/neutron_tempest_plugin/scenario/test_dhcp.py
@@ -11,7 +11,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
-import netaddr
from neutron_lib import constants
from oslo_log import log
from paramiko import ssh_exception as ssh_exc
@@ -160,12 +159,10 @@
dhcp_port = self.dhcp_ports[0]
# modify DHCP port IP address
- old_dhcp_port_ip = netaddr.IPAddress(
- dhcp_port['fixed_ips'][0]['ip_address'])
- if str(old_dhcp_port_ip) != subnet['allocation_pools'][0]['end']:
- new_dhcp_port_ip = str(old_dhcp_port_ip + 1)
- else:
- new_dhcp_port_ip = str(old_dhcp_port_ip - 1)
+ new_dhcp_port_ip = utils.net_utils.get_unused_ip_addresses(
+ ports_client=self.client, subnets_client=self.client,
+ network_id=self.network['id'], subnet_id=subnet['id'],
+ count=1)[0]
self.update_port(port=dhcp_port,
fixed_ips=[{'subnet_id': subnet['id'],
'ip_address': new_dhcp_port_ip}])