From 4d321698f7e66bd779526e309b11b51af690e090 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Fri, 26 Aug 2016 10:33:07 -0500 Subject: [PATCH] Rename _get_free_fixed_port to _nat_destination_port The name _get_free_fixed_port is misleading. What the function actually does is find a port attached to the server which is on a network which has a subnet which can be a nat_destination. Such a network is referred to in shade as a "nat_destination" network. So this then is a function which returns a port on that network that is associated with this server. Change-Id: If69ad8f7c08a4df83bc00cb00801565a7473a9a5 --- shade/openstackcloud.py | 18 ++++++++++++------ shade/tests/unit/test_floating_ip_neutron.py | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 7b5e64ef2..a83e9920a 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -3532,7 +3532,7 @@ class OpenStackCloud(object): } if not port: if server: - (port_obj, fixed_ip_address) = self._get_free_fixed_port( + (port_obj, fixed_ip_address) = self._nat_destination_port( server, fixed_address=fixed_address, nat_destination=nat_destination) if port_obj: @@ -3756,9 +3756,15 @@ class OpenStackCloud(object): return server return server - def _get_free_fixed_port(self, server, fixed_address=None, - nat_destination=None): - """Returns server's port. + def _nat_destination_port( + self, server, fixed_address=None, nat_destination=None): + """Returns server port that is on a nat_destination network + + Find a port attached to the server which is on a network which + has a subnet which can be the destination of NAT. Such a network + is referred to in shade as a "nat_destination" network. So this + then is a function which returns a port on such a network that is + associated with the given server. :param server: Server dict. :param fixed_address: Fixed ip address of the port @@ -3859,7 +3865,7 @@ class OpenStackCloud(object): "{0}".format(server['id'])): # Find an available port - (port, fixed_address) = self._get_free_fixed_port( + (port, fixed_address) = self._nat_destination_port( server, fixed_address=fixed_address) if not port: raise OpenStackCloudException( @@ -4151,7 +4157,7 @@ class OpenStackCloud(object): if not networks: return False - (port_obj, fixed_ip_address) = self._get_free_fixed_port( + (port_obj, fixed_ip_address) = self._nat_destination_port( server, nat_destination=nat_destination) if not port_obj or not fixed_ip_address: diff --git a/shade/tests/unit/test_floating_ip_neutron.py b/shade/tests/unit/test_floating_ip_neutron.py index 700c14a81..f26dec6e3 100644 --- a/shade/tests/unit/test_floating_ip_neutron.py +++ b/shade/tests/unit/test_floating_ip_neutron.py @@ -629,14 +629,14 @@ class TestFloatingIP(base.TestCase): floating_ip_id='this-is-a-floating-ip-id', retry=1) @patch.object(OpenStackCloud, '_submit_create_fip') - @patch.object(OpenStackCloud, '_get_free_fixed_port') + @patch.object(OpenStackCloud, '_nat_destination_port') @patch.object(OpenStackCloud, 'get_external_networks') def test_create_floating_ip_no_port( - self, mock_get_ext_nets, mock_get_free_fixed_port, + self, mock_get_ext_nets, mock_nat_destination_port, mock_submit_create_fip): fake_port = dict(id='port-id') mock_get_ext_nets.return_value = [self.mock_get_network_rep] - mock_get_free_fixed_port.return_value = (fake_port, '10.0.0.2') + mock_nat_destination_port.return_value = (fake_port, '10.0.0.2') mock_submit_create_fip.return_value = dict(port_id=None) self.assertRaises(