From acac3b986be738c5d3eb5f6a7b7bb736b72bba6c Mon Sep 17 00:00:00 2001 From: Jordan Pittier Date: Fri, 14 Oct 2016 17:08:10 +0200 Subject: [PATCH] Fix a NameError exception in _nat_destination_port Yeah, it was burried deep but still. Added a unit test just to quickly exercise this code path. Change-Id: Ibec3f24483214f8af514c8be512b7c3f3840b32e --- shade/openstackcloud.py | 2 +- shade/tests/unit/test_floating_ip_common.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index dde78d2f6..d7314e504 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -4137,7 +4137,7 @@ class OpenStackCloud(_normalize.Normalizer): return port, fixed_address raise OpenStackCloudException( "unable to find a free fixed IPv4 address for server " - "{0}".format(server_id)) + "{0}".format(server['id'])) # unfortunately a port can have more than one fixed IP: # we can't use the search_ports filtering for fixed_address as # they are contained in a list. e.g. diff --git a/shade/tests/unit/test_floating_ip_common.py b/shade/tests/unit/test_floating_ip_common.py index 31515f239..5031e032d 100644 --- a/shade/tests/unit/test_floating_ip_common.py +++ b/shade/tests/unit/test_floating_ip_common.py @@ -20,6 +20,8 @@ Tests floating IP resource methods for Neutron and Nova-network. """ from mock import patch + +from shade import exc from shade import meta from shade import OpenStackCloud from shade.tests.fakes import FakeServer @@ -223,3 +225,12 @@ class TestFloatingIP(base.TestCase): mock_add_auto_ip.assert_called_with( server_dict, wait=False, timeout=60, reuse=True) + + @patch.object(OpenStackCloud, 'search_ports', return_value=[{}]) + def test_nat_destination_port_when_no_free_fixed_ip( + self, mock_search_ports): + server = {'id': 42} + self.assertRaisesRegexp( + exc.OpenStackCloudException, 'server 42$', + self.cloud._nat_destination_port, server + )