diff options
| author | Sindhu Devale <sindhu.devale@intel.com> | 2016-10-06 10:01:59 -0500 |
|---|---|---|
| committer | Dean Troyer <dtroyer@gmail.com> | 2017-04-05 16:12:40 +0000 |
| commit | 763c8c5670f238920398165e670592e006213f32 (patch) | |
| tree | c8b6c7f1dce72d35dc77389a488f5312d88d6cfa /openstackclient/tests/functional | |
| parent | 0e42ea3ae325cf5b168bb966e62cd6b8e9ee0159 (diff) | |
| download | python-openstackclient-763c8c5670f238920398165e670592e006213f32.tar.gz | |
"floating ip set/unset port" for OSC
Implements Neutron feature of floating ip associate/disassociate
into OpenStack Client.
Previously, network.find_ip() function only supported to
search floating ip by UUID. Hence, _find_floating_ip()
function is used in floating_ip.py, to search fip both by UUID
and ip_address. [1] adds the ability to find fip object using both UUID
and ip_address. This functionality however, won't be available until
the SDK is released. Hence, we continue to use _find_floating_ip()
method, which was cleaned up by [2] to remove the use of ip_cache.
Once, the SDK is released, we will remove all the usage of
_find_floating_ip() method and instead only use network.find_ip().
[1] https://review.openstack.org/#/c/449879/2
[2] https://review.openstack.org/#/c/447938/
Change-Id: I6c5222287c46ca42365917d2deae70bdb626347
Co-Authored-By: Reedip<reedip.banerjee@nectechnologies.in>
Co-Authored-By: RuiChen<chenrui.momo@gmail.com>
Closes-Bug: #1560297
Diffstat (limited to 'openstackclient/tests/functional')
| -rw-r--r-- | openstackclient/tests/functional/network/v2/test_floating_ip.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/openstackclient/tests/functional/network/v2/test_floating_ip.py b/openstackclient/tests/functional/network/v2/test_floating_ip.py index 8fbec3d5..5da0e474 100644 --- a/openstackclient/tests/functional/network/v2/test_floating_ip.py +++ b/openstackclient/tests/functional/network/v2/test_floating_ip.py @@ -21,6 +21,10 @@ class FloatingIpTests(base.TestCase): """Functional tests for floating ip""" SUBNET_NAME = uuid.uuid4().hex NETWORK_NAME = uuid.uuid4().hex + PRIVATE_NETWORK_NAME = uuid.uuid4().hex + PRIVATE_SUBNET_NAME = uuid.uuid4().hex + ROUTER = uuid.uuid4().hex + PORT_NAME = uuid.uuid4().hex @classmethod def setUpClass(cls): @@ -30,6 +34,8 @@ class FloatingIpTests(base.TestCase): cls.re_fixed_ip = re.compile("fixed_ip_address\s+\|\s+(\S+)") cls.re_description = re.compile("description\s+\|\s+([^|]+?)\s+\|") cls.re_network_id = re.compile("floating_network_id\s+\|\s+(\S+)") + cls.re_port_id = re.compile("\s+id\s+\|\s+(\S+)") + cls.re_fp_port_id = re.compile("\s+port_id\s+\|\s+(\S+)") # Create a network for the floating ip raw_output = cls.openstack( @@ -37,6 +43,12 @@ class FloatingIpTests(base.TestCase): ) cls.network_id = re.search(cls.re_id, raw_output).group(1) + # Create a private network for the port + raw_output = cls.openstack( + 'network create ' + cls.PRIVATE_NETWORK_NAME + ) + cls.private_network_id = re.search(cls.re_id, raw_output).group(1) + # Try random subnet range for subnet creating # Because we can not determine ahead of time what subnets are already # in use, possibly by another test running in parallel, try 4 times @@ -46,6 +58,10 @@ class FloatingIpTests(base.TestCase): str, (random.randint(0, 223) for _ in range(3)) )) + ".0/26" + cls.private_subnet = ".".join(map( + str, + (random.randint(0, 223) for _ in range(3)) + )) + ".0/26" try: # Create a subnet for the network raw_output = cls.openstack( @@ -54,6 +70,13 @@ class FloatingIpTests(base.TestCase): '--subnet-range ' + cls.subnet + ' ' + cls.SUBNET_NAME ) + # Create a subnet for the private network + priv_raw_output = cls.openstack( + 'subnet create ' + + '--network ' + cls.PRIVATE_NETWORK_NAME + ' ' + + '--subnet-range ' + cls.private_subnet + ' ' + + cls.PRIVATE_SUBNET_NAME + ) except Exception: if (i == 3): # raise the exception at the last time @@ -64,13 +87,19 @@ class FloatingIpTests(base.TestCase): break cls.subnet_id = re.search(cls.re_id, raw_output).group(1) + cls.private_subnet_id = re.search(cls.re_id, priv_raw_output).group(1) @classmethod def tearDownClass(cls): raw_output = cls.openstack('subnet delete ' + cls.SUBNET_NAME) cls.assertOutput('', raw_output) + raw_output = cls.openstack('subnet delete ' + cls.PRIVATE_SUBNET_NAME) + cls.assertOutput('', raw_output) raw_output = cls.openstack('network delete ' + cls.NETWORK_NAME) cls.assertOutput('', raw_output) + raw_output = cls.openstack( + 'network delete ' + cls.PRIVATE_NETWORK_NAME) + cls.assertOutput('', raw_output) def test_floating_ip_delete(self): """Test create, delete multiple""" @@ -168,3 +197,50 @@ class FloatingIpTests(base.TestCase): # re.search(self.re_floating_ip, raw_output).group(1), # ) self.assertIsNotNone(re.search(self.re_network_id, raw_output)) + + def test_floating_ip_set_and_unset_port(self): + """Test Floating IP Set and Unset port""" + raw_output = self.openstack( + 'floating ip create ' + + '--description shosho ' + + self.NETWORK_NAME + ) + re_ip = re.search(self.re_floating_ip, raw_output) + fp_ip = re_ip.group(1) + self.addCleanup(self.openstack, 'floating ip delete ' + fp_ip) + self.assertIsNotNone(fp_ip) + + raw_output1 = self.openstack( + 'port create --network ' + self.PRIVATE_NETWORK_NAME + + ' --fixed-ip subnet=' + self.PRIVATE_SUBNET_NAME + + ' ' + self.PORT_NAME + ) + re_port_id = re.search(self.re_port_id, raw_output1) + self.assertIsNotNone(re_port_id) + port_id = re_port_id.group(1) + + router = self.openstack('router create ' + self.ROUTER) + self.assertIsNotNone(router) + self.addCleanup(self.openstack, 'router delete ' + self.ROUTER) + + self.openstack('router add port ' + self.ROUTER + + ' ' + port_id) + self.openstack('router set --external-gateway ' + self.NETWORK_NAME + + ' ' + self.ROUTER) + + self.addCleanup(self.openstack, 'router unset --external-gateway ' + + self.ROUTER) + self.addCleanup(self.openstack, 'router remove port ' + self.ROUTER + + ' ' + port_id) + + raw_output = self.openstack( + 'floating ip set ' + + fp_ip + ' --port ' + port_id) + self.addCleanup(self.openstack, 'floating ip unset --port ' + fp_ip) + + show_output = self.openstack( + 'floating ip show ' + fp_ip) + + self.assertEqual( + port_id, + re.search(self.re_fp_port_id, show_output).group(1)) |
