Set lower addr to avoid IP out of range

Since port creating can result an IP address in the
entire CIDR especially small subnet. And those next
N IP actions can be out of subnet IP range. This
patch gives the original test port a specific IP
addr to prevent this issue.

Closes-Bug: #1812404
Change-Id: I34cb99a518d4469c7d1ca9e2897671608b2b81ad
This commit is contained in:
LIU Yulong 2019-01-18 23:55:03 +08:00 committed by Slawek Kaplonski
parent 53bfd949bd
commit 63ea9d7bcc
1 changed files with 12 additions and 1 deletions

View File

@ -99,7 +99,15 @@ class PortForwardingTestCase(PortForwardingTestCaseBase):
self._set_router_gw(self.router['id'], self.ext_net['id'])
self._add_router_interface(self.router['id'], self.subnet['id'])
self.fip = self._create_floatingip(self.ext_net['id'])
self.port = self._create_port(self.fmt, self.net['id']).json['port']
# We choose an IP address in the middle of the subnet so
# tests that update the IP in the port,
# like test_concurrent_create_port_forwarding_update_port(),
# don't accidentally choose an invalid IP address in
# the subnet, like the broadcast address.
self.port = self._create_port(
self.fmt, self.net['id'],
fixed_ips=[{'subnet_id': self.subnet['id'],
'ip_address': '10.0.0.100'}]).json['port']
self.port_forwarding = {
apidef.RESOURCE_NAME:
{apidef.EXTERNAL_PORT: 2225,
@ -441,6 +449,9 @@ class PortForwardingTestCase(PortForwardingTestCaseBase):
funcs, args_list)
def test_concurrent_create_port_forwarding_update_port(self):
# The initial IP address of the port is in the middle of the
# subnet range, so adding 2 to it should also produce a
# valid IP address.
new_ip = str(
netaddr.IPAddress(self.port['fixed_ips'][0]['ip_address']) + 2)
funcs = [self.pf_plugin.create_floatingip_port_forwarding,