]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move gateway processing out of init_router_port
authorCarl Baldwin <carl.baldwin@hp.com>
Fri, 28 Aug 2015 21:04:26 +0000 (21:04 +0000)
committerCarl Baldwin <carl.baldwin@hpe.com>
Mon, 5 Oct 2015 21:07:10 +0000 (21:07 +0000)
This method is a bit overloaded

Change-Id: Idc8526c3714856feb3e75d7bab9f6acc33499e3f
Partially-Implements: blueprint address-scopes

neutron/agent/l3/router_info.py
neutron/agent/linux/interface.py
neutron/tests/unit/agent/l3/test_agent.py
neutron/tests/unit/agent/linux/test_interface.py

index 15699211caaf185c65c6a9a8021481572500b1d0..dfeeaea241d129a581c2ae35b318bad9af786bba 100644 (file)
@@ -509,11 +509,17 @@ class RouterInfo(object):
             interface_name,
             ip_cidrs,
             namespace=ns_name,
-            gateway_ips=gateway_ips,
             extra_subnets=ex_gw_port.get('extra_subnets', []),
             preserve_ips=preserve_ips,
-            enable_ra_on_gw=enable_ra_on_gw,
             clean_connections=True)
+
+        device = ip_lib.IPDevice(interface_name, namespace=ns_name)
+        for ip in gateway_ips or []:
+            device.route.add_gateway(ip)
+
+        if enable_ra_on_gw:
+            self.driver.configure_ipv6_ra(ns_name, interface_name)
+
         for fixed_ip in ex_gw_port['fixed_ips']:
             ip_lib.send_ip_addr_adv_notif(ns_name,
                                           interface_name,
index 44a0ad834befec09aca8515b2e42604fecf0394a..bcdf06c59e5bc17090bcf494a807240f911881b7 100644 (file)
@@ -105,13 +105,12 @@ class LinuxInterfaceDriver(object):
         return False
 
     def init_l3(self, device_name, ip_cidrs, namespace=None,
-                preserve_ips=[], gateway_ips=None,
+                preserve_ips=[],
                 clean_connections=False):
         """Set the L3 settings for the interface using data from the port.
 
         ip_cidrs: list of 'X.X.X.X/YY' strings
         preserve_ips: list of ip cidrs that should not be removed from device
-        gateway_ips: For gateway ports, list of external gateway ip addresses
         clean_connections: Boolean to indicate if we should cleanup connections
           associated to removed ips
         """
@@ -146,24 +145,17 @@ class LinuxInterfaceDriver(object):
                 else:
                     device.addr.delete(ip_cidr)
 
-        for gateway_ip in gateway_ips or []:
-            device.route.add_gateway(gateway_ip)
-
     def init_router_port(self,
                          device_name,
                          ip_cidrs,
                          namespace,
                          preserve_ips=None,
-                         gateway_ips=None,
                          extra_subnets=None,
-                         enable_ra_on_gw=False,
                          clean_connections=False):
         """Set the L3 settings for a router interface using data from the port.
 
         ip_cidrs: list of 'X.X.X.X/YY' strings
         preserve_ips: list of ip cidrs that should not be removed from device
-        gateway_ips: For gateway ports, list of external gateway ip addresses
-        enable_ra_on_gw: Boolean to indicate configuring acceptance of IPv6 RA
         clean_connections: Boolean to indicate if we should cleanup connections
           associated to removed ips
         extra_subnets: An iterable of cidrs to add as routes without address
@@ -174,12 +166,8 @@ class LinuxInterfaceDriver(object):
                      ip_cidrs=ip_cidrs,
                      namespace=namespace,
                      preserve_ips=preserve_ips or [],
-                     gateway_ips=gateway_ips,
                      clean_connections=clean_connections)
 
-        if enable_ra_on_gw:
-            self.configure_ipv6_ra(namespace, device_name)
-
         device = ip_lib.IPDevice(device_name, namespace=namespace)
 
         # Manage on-link routes (routes without an associated address)
index 3be71f5c07ede8bd44fe030bed39b460aec75c59..4b2f16dfcd92b11e7d686f530ebae9976cfef562 100644 (file)
@@ -381,7 +381,6 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
         self._test_internal_network_action_dist('remove')
 
     def _add_external_gateway(self, ri, router, ex_gw_port, interface_name,
-                              enable_ra_on_gw=False,
                               use_fake_fip=False,
                               no_subnet=False, no_sub_gw=None,
                               dual_stack=False):
@@ -401,14 +400,9 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
             if no_subnet and not dual_stack:
                 self.assertEqual(self.send_adv_notif.call_count, 0)
                 ip_cidrs = []
-                gateway_ips = []
-                if no_sub_gw:
-                    gateway_ips.append(no_sub_gw)
                 kwargs = {'preserve_ips': [],
-                          'gateway_ips': gateway_ips,
                           'namespace': 'qrouter-' + router['id'],
                           'extra_subnets': [],
-                          'enable_ra_on_gw': enable_ra_on_gw,
                           'clean_connections': True}
             else:
                 exp_arp_calls = [mock.call(ri.ns_name, interface_name,
@@ -419,18 +413,12 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
                                                 mock.ANY)]
                 self.send_adv_notif.assert_has_calls(exp_arp_calls)
                 ip_cidrs = ['20.0.0.30/24']
-                gateway_ips = ['20.0.0.1']
                 if dual_stack:
-                    if no_sub_gw:
-                        gateway_ips.append(no_sub_gw)
-                    else:
+                    if not no_sub_gw:
                         ip_cidrs.append('2001:192:168:100::2/64')
-                        gateway_ips.append('2001:192:168:100::1')
                 kwargs = {'preserve_ips': ['192.168.1.34/32'],
-                          'gateway_ips': gateway_ips,
                           'namespace': 'qrouter-' + router['id'],
                           'extra_subnets': [{'cidr': '172.16.0.0/24'}],
-                          'enable_ra_on_gw': enable_ra_on_gw,
                           'clean_connections': True}
             self.mock_driver.init_router_port.assert_called_with(
                 interface_name, ip_cidrs, **kwargs)
@@ -499,7 +487,7 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
         elif action == 'add_no_sub':
             ri.use_ipv6 = True
             self._add_external_gateway(ri, router, ex_gw_port_no_sub,
-                                       interface_name, enable_ra_on_gw=True,
+                                       interface_name,
                                        no_subnet=True)
 
         elif action == 'add_no_sub_v6_gw':
@@ -569,10 +557,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
             ip_cidrs.append('2001:192:168:100::2/64')
             gateway_ips.append('2001:192:168:100::1')
         kwargs = {'preserve_ips': ['192.168.1.34/32'],
-                  'gateway_ips': gateway_ips,
                   'namespace': 'qrouter-' + router['id'],
                   'extra_subnets': [{'cidr': '172.16.0.0/24'}],
-                  'enable_ra_on_gw': False,
                   'clean_connections': True}
         self.mock_driver.init_router_port.assert_called_with(interface_name,
                                                              ip_cidrs,
index 38185ead6880d46f86a055fc34c7dca97d8aa514..130abf1853a0249d1c977548f9be5d88300361d4 100644 (file)
@@ -154,7 +154,7 @@ class TestABCDriver(TestBase):
     def test_l3_init_without_clean_connections(self):
         self._test_l3_init_clean_connections(False)
 
-    def _test_init_router_port_with_ipv6(self, include_gw_ip):
+    def test_init_router_port_ipv6_with_gw_ip(self):
         addresses = [dict(scope='global',
                           dynamic=False,
                           cidr='2001:db8:a::123/64')]
@@ -166,17 +166,12 @@ class TestABCDriver(TestBase):
         new_cidr = '2001:db8:a::124/64'
         kwargs = {'namespace': ns,
                   'extra_subnets': [{'cidr': '2001:db8:b::/64'}]}
-        if include_gw_ip:
-            kwargs['gateway_ips'] = ['2001:db8:a::1']
         bc.init_router_port('tap0', [new_cidr], **kwargs)
         expected_calls = (
             [mock.call('tap0', namespace=ns),
              mock.call().addr.list(filters=['permanent']),
              mock.call().addr.add('2001:db8:a::124/64'),
              mock.call().addr.delete('2001:db8:a::123/64')])
-        if include_gw_ip:
-            expected_calls += (
-                [mock.call().route.add_gateway('2001:db8:a::1')])
         expected_calls += (
              [mock.call('tap0', namespace=ns),
               mock.call().route.list_onlink_routes(constants.IP_VERSION_4),
@@ -184,12 +179,6 @@ class TestABCDriver(TestBase):
               mock.call().route.add_onlink_route('2001:db8:b::/64')])
         self.ip_dev.assert_has_calls(expected_calls)
 
-    def test_init_router_port_ipv6_with_gw_ip(self):
-        self._test_init_router_port_with_ipv6(include_gw_ip=True)
-
-    def test_init_router_port_ipv6_without_gw_ip(self):
-        self._test_init_router_port_with_ipv6(include_gw_ip=False)
-
     def test_init_router_port_ext_gw_with_dual_stack(self):
         old_addrs = [dict(ip_version=4, scope='global',
                           dynamic=False, cidr='172.16.77.240/24'),