Do not use subnet broadcast address in unit test

neutron.tests.unit.services.revisions.test_revision_plugin.\
    TestRevisionPlugin.test_port_ip_update_revises
occasionally fails in the gate, because it assumes that a random
IP+1 is also a valid IP. However the +1 address may be the subnet
broadcast address which is then rejected by neutron.

This change makes sure to use a free IP from the subnet instead of
the +1 address.

Change-Id: I1b27cac301cdc1acf426b0e71c037c157e93cd45
Closes-Bug: #1821948
This commit is contained in:
Bence Romsics 2019-03-27 16:37:51 +01:00
parent 1ea9326fda
commit 765691d1e2
1 changed files with 3 additions and 5 deletions

View File

@ -13,7 +13,6 @@
# under the License.
#
import netaddr
from neutron_lib import context as nctx
from neutron_lib.db import api as db_api
from neutron_lib.plugins import constants
@ -161,13 +160,12 @@ class TestRevisionPlugin(test_plugin.Ml2PluginV2TestCase):
expected_code=exc.HTTPPreconditionFailed.code)
def test_port_ip_update_revises(self):
with self.port() as port:
with self.subnet() as subnet, self.port() as port:
rev = port['port']['revision_number']
new = {'port': {'fixed_ips': port['port']['fixed_ips']}}
# ensure adding an IP allocation updates the port
next_ip = str(netaddr.IPAddress(
new['port']['fixed_ips'][0]['ip_address']) + 1)
new['port']['fixed_ips'].append({'ip_address': next_ip})
free_ip = self._find_ip_address(subnet['subnet'])
new['port']['fixed_ips'].append({'ip_address': free_ip})
response = self._update('ports', port['port']['id'], new)
self.assertEqual(2, len(response['port']['fixed_ips']))
new_rev = response['port']['revision_number']