]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Correctly mock-out 'ip route...' calls in IPv6 test
authorBrian Haley <brian.haley@hp.com>
Thu, 5 Feb 2015 20:18:10 +0000 (15:18 -0500)
committerBrian Haley <brian.haley@hp.com>
Sat, 7 Feb 2015 01:04:09 +0000 (20:04 -0500)
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
neutron/tests/unit/test_linux_interface.py

index eff2cec8cbbfc73d207a9e50698332d0f737ac01..5953f8a060bf5ed3f90655db38ccfabde55e43c2 100644 (file)
@@ -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():
index e1947a80307a530bffa135ad19372527a0277d17..ee6967e0675ccabc03e932d2fcfd5806da0a354a 100644 (file)
@@ -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,