From 2a215987b8e0a5418a161eaa1cec0339dcb2faeb Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Thu, 5 Feb 2015 15:18:10 -0500 Subject: [PATCH] Correctly mock-out 'ip route...' calls in IPv6 test In neutron/tests/unit/test_linux_interface.py, test TestABCDriver.test_l3_init_with_ipv6() missed mocking-out calls to 'ip route...'. Introduced in commit fc7cffedbe60. This also required forcing init_l3() to always specify that the netaddr library should return a zero-filled network for IPv6. Change-Id: Ic69830ac21113815794def5227fc21664d7fcbb8 Closes-Bug: #1418704 --- neutron/agent/linux/interface.py | 8 +++++++- neutron/tests/unit/test_linux_interface.py | 9 +++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py index eff2cec8cbb..5953f8a060b 100644 --- a/neutron/agent/linux/interface.py +++ b/neutron/agent/linux/interface.py @@ -106,7 +106,13 @@ class LinuxInterfaceDriver(object): del previous[ip_cidr] continue - device.addr.add(net.version, ip_cidr, str(net.broadcast)) + # Make sure the format of this network, if IPv6, is zero-filled. + # The Linux netaddr library seems to do this by default (bug?), + # and the test verifies it, but we should force it just in case + # the behavior changes. It also makes sure that non-Linux-based + # libraries also work correctly (e.g. OSX). + device.addr.add(net.version, ip_cidr, + str(net.broadcast.format(netaddr.ipv6_full))) # clean up any old addresses for ip_cidr, ip_version in previous.items(): diff --git a/neutron/tests/unit/test_linux_interface.py b/neutron/tests/unit/test_linux_interface.py index e1947a80307..ee6967e0675 100644 --- a/neutron/tests/unit/test_linux_interface.py +++ b/neutron/tests/unit/test_linux_interface.py @@ -127,15 +127,20 @@ class TestABCDriver(TestBase): dynamic=False, cidr='2001:db8:a::123/64')] self.ip_dev().addr.list = mock.Mock(return_value=addresses) + self.ip_dev().route.list_onlink_routes.return_value = [] + bc = BaseChild(self.conf) ns = '12345678-1234-5678-90ab-ba0987654321' - bc.init_l3('tap0', ['2001:db8:a::124/64'], namespace=ns) + bc.init_l3('tap0', ['2001:db8:a::124/64'], namespace=ns, + extra_subnets=[{'cidr': '2001:db8:b::/64'}]) self.ip_dev.assert_has_calls( [mock.call('tap0', 'sudo', namespace=ns), mock.call().addr.list(scope='global', filters=['permanent']), mock.call().addr.add(6, '2001:db8:a::124/64', '2001:db8:a:0:ffff:ffff:ffff:ffff'), - mock.call().addr.delete(6, '2001:db8:a::123/64')]) + mock.call().addr.delete(6, '2001:db8:a::123/64'), + mock.call().route.list_onlink_routes(), + mock.call().route.add_onlink_route('2001:db8:b::/64')]) def test_l3_init_with_duplicated_ipv6(self): addresses = [dict(ip_version=6,