From da9ea09647837930f23160ee9205cc63315cd1de Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Sun, 1 Jan 2017 17:25:47 -0500 Subject: [PATCH] Make test_floating_ip* pass with CONF.use_neutron=True by default Some pretty simple changes: - test_floating_ip_dns can only be tested with nova-network as the API isn't implemented for Neutron. - test_floating_ip_pools just needed some more generic mocking. - test_floating_ips just needed more generic mocking and to make the non-Neutron-specific test force use_neutron=False. Part of blueprint use-neutron-by-default Change-Id: If8b8a6662ae01f23bde09fd5804fe635b6340eb4 --- .../api/openstack/compute/test_floating_ip_dns.py | 2 ++ .../api/openstack/compute/test_floating_ip_pools.py | 12 +++++++----- .../unit/api/openstack/compute/test_floating_ips.py | 10 ++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py b/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py index af352858746e..0c5be67b0daa 100644 --- a/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py +++ b/nova/tests/unit/api/openstack/compute/test_floating_ip_dns.py @@ -117,6 +117,8 @@ class FloatingIpDNSTestV21(test.TestCase): def setUp(self): super(FloatingIpDNSTestV21, self).setUp() + # None of these APIs are implemented for Neutron. + self.flags(use_neutron=False) self.stubs.Set(network.api.API, "get_dns_domains", network_get_dns_domains) self.stubs.Set(network.api.API, "get_dns_entries_by_address", diff --git a/nova/tests/unit/api/openstack/compute/test_floating_ip_pools.py b/nova/tests/unit/api/openstack/compute/test_floating_ip_pools.py index d558fa270ba1..215e95b52547 100644 --- a/nova/tests/unit/api/openstack/compute/test_floating_ip_pools.py +++ b/nova/tests/unit/api/openstack/compute/test_floating_ip_pools.py @@ -13,16 +13,17 @@ # License for the specific language governing permissions and limitations # under the License. +import mock + from nova.api.openstack.compute import floating_ip_pools \ as fipp_v21 from nova import context from nova import exception -from nova import network from nova import test from nova.tests.unit.api.openstack import fakes -def fake_get_floating_ip_pools(self, context): +def fake_get_floating_ip_pools(*args, **kwargs): return ['nova', 'other'] @@ -31,8 +32,6 @@ class FloatingIpPoolTestV21(test.NoDBTestCase): def setUp(self): super(FloatingIpPoolTestV21, self).setUp() - self.stubs.Set(network.api.API, "get_floating_ip_pools", - fake_get_floating_ip_pools) self.context = context.RequestContext('fake', 'fake') self.controller = self.floating_ip_pools.FloatingIPPoolsController() @@ -48,7 +47,10 @@ class FloatingIpPoolTestV21(test.NoDBTestCase): pools[1]) def test_floating_ips_pools_list(self): - res_dict = self.controller.index(self.req) + with mock.patch.object(self.controller.network_api, + 'get_floating_ip_pools', + fake_get_floating_ip_pools): + res_dict = self.controller.index(self.req) pools = fake_get_floating_ip_pools(None, self.context) response = {'floating_ip_pools': [{'name': name} for name in pools]} diff --git a/nova/tests/unit/api/openstack/compute/test_floating_ips.py b/nova/tests/unit/api/openstack/compute/test_floating_ips.py index e109af1bdad5..d184769fdbe7 100644 --- a/nova/tests/unit/api/openstack/compute/test_floating_ips.py +++ b/nova/tests/unit/api/openstack/compute/test_floating_ips.py @@ -183,6 +183,7 @@ class FloatingIpTestV21(test.TestCase): def setUp(self): super(FloatingIpTestV21, self).setUp() + self.flags(use_neutron=False) self.stubs.Set(compute.api.API, "get", compute_api_get) self.stubs.Set(network.api.API, "get_floating_ip", @@ -884,13 +885,14 @@ class ExtendedFloatingIpTestV21(test.TestCase): def fake_associate_floating_ip(*args, **kwargs): self.assertEqual(fixed_address, kwargs['fixed_address']) - self.stubs.Set(network.api.API, "associate_floating_ip", - fake_associate_floating_ip) body = dict(addFloatingIp=dict(address=self.floating_ip, fixed_address=fixed_address)) - rsp = self.manager._add_floating_ip(self.fake_req, TEST_INST, - body=body) + with mock.patch.object(self.manager.network_api, + 'associate_floating_ip', + fake_associate_floating_ip): + rsp = self.manager._add_floating_ip(self.fake_req, TEST_INST, + body=body) self.assertEqual(202, rsp.status_int) def test_extended_floating_ip_associate_fixed_not_allocated(self):