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
This commit is contained in:
Matt Riedemann 2017-01-01 17:25:47 -05:00
parent 55df51bd42
commit da9ea09647
3 changed files with 15 additions and 9 deletions

View File

@ -117,6 +117,8 @@ class FloatingIpDNSTestV21(test.TestCase):
def setUp(self): def setUp(self):
super(FloatingIpDNSTestV21, self).setUp() 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", self.stubs.Set(network.api.API, "get_dns_domains",
network_get_dns_domains) network_get_dns_domains)
self.stubs.Set(network.api.API, "get_dns_entries_by_address", self.stubs.Set(network.api.API, "get_dns_entries_by_address",

View File

@ -13,16 +13,17 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import mock
from nova.api.openstack.compute import floating_ip_pools \ from nova.api.openstack.compute import floating_ip_pools \
as fipp_v21 as fipp_v21
from nova import context from nova import context
from nova import exception from nova import exception
from nova import network
from nova import test from nova import test
from nova.tests.unit.api.openstack import fakes 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'] return ['nova', 'other']
@ -31,8 +32,6 @@ class FloatingIpPoolTestV21(test.NoDBTestCase):
def setUp(self): def setUp(self):
super(FloatingIpPoolTestV21, self).setUp() 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.context = context.RequestContext('fake', 'fake')
self.controller = self.floating_ip_pools.FloatingIPPoolsController() self.controller = self.floating_ip_pools.FloatingIPPoolsController()
@ -48,7 +47,10 @@ class FloatingIpPoolTestV21(test.NoDBTestCase):
pools[1]) pools[1])
def test_floating_ips_pools_list(self): 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) pools = fake_get_floating_ip_pools(None, self.context)
response = {'floating_ip_pools': [{'name': name} for name in pools]} response = {'floating_ip_pools': [{'name': name} for name in pools]}

View File

@ -183,6 +183,7 @@ class FloatingIpTestV21(test.TestCase):
def setUp(self): def setUp(self):
super(FloatingIpTestV21, self).setUp() super(FloatingIpTestV21, self).setUp()
self.flags(use_neutron=False)
self.stubs.Set(compute.api.API, "get", self.stubs.Set(compute.api.API, "get",
compute_api_get) compute_api_get)
self.stubs.Set(network.api.API, "get_floating_ip", self.stubs.Set(network.api.API, "get_floating_ip",
@ -884,13 +885,14 @@ class ExtendedFloatingIpTestV21(test.TestCase):
def fake_associate_floating_ip(*args, **kwargs): def fake_associate_floating_ip(*args, **kwargs):
self.assertEqual(fixed_address, kwargs['fixed_address']) 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, body = dict(addFloatingIp=dict(address=self.floating_ip,
fixed_address=fixed_address)) fixed_address=fixed_address))
rsp = self.manager._add_floating_ip(self.fake_req, TEST_INST, with mock.patch.object(self.manager.network_api,
body=body) '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) self.assertEqual(202, rsp.status_int)
def test_extended_floating_ip_associate_fixed_not_allocated(self): def test_extended_floating_ip_associate_fixed_not_allocated(self):