]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Replace IPv4 and IPv6 default addresses with constants
authorvijaychundury <vchundur@redhat.com>
Tue, 3 Mar 2015 13:02:02 +0000 (13:02 +0000)
committervijaychundury <vchundur@redhat.com>
Fri, 6 Mar 2015 05:39:44 +0000 (05:39 +0000)
At various places in Neutron we are using IPv4 and IPv6 default addresses in
numeric format. This patch replaces them with constants to ensure consistency.

Closes-Bug: #1427645
Change-Id: I9817a95646546704e44fa70292eaa94635bb7395

neutron/agent/l3/ha_router.py
neutron/agent/linux/dhcp.py
neutron/common/constants.py
neutron/plugins/nec/router_drivers.py
neutron/tests/unit/agent/linux/test_keepalived.py
neutron/tests/unit/db/metering/test_db_metering.py
neutron/tests/unit/test_db_plugin.py
neutron/tests/unit/test_linux_dhcp.py

index fadcae94b6c3f7782171a13c4d520ea7ced47e24..b12813314ebc77ffb87c070b7106fb5c9e9dabda 100644 (file)
@@ -20,6 +20,7 @@ from neutron.agent.l3 import router_info as router
 from neutron.agent.linux import ip_lib
 from neutron.agent.linux import keepalived
 from neutron.agent.metadata import driver as metadata_driver
+from neutron.common import constants as n_consts
 from neutron.common import utils as common_utils
 from neutron.openstack.common import log as logging
 
@@ -178,7 +179,7 @@ class HaRouter(router.RouterInfo):
         instance = self._get_keepalived_instance()
 
         # Filter out all of the old routes while keeping only the default route
-        default_gw = ('::/0', '0.0.0.0/0')
+        default_gw = (n_consts.IPv6_ANY, n_consts.IPv4_ANY)
         instance.virtual_routes = [route for route in instance.virtual_routes
                                    if route.destination in default_gw]
         for route in new_routes:
@@ -192,8 +193,9 @@ class HaRouter(router.RouterInfo):
         gw_ip = ex_gw_port['subnet']['gateway_ip']
         if gw_ip:
             # TODO(Carl) This is repeated everywhere.  A method would be nice.
-            default_gw = ('0.0.0.0/0' if netaddr.IPAddress(gw_ip).version == 4
-                          else '::/0')
+            default_gw = (n_consts.IPv4_ANY if
+                          netaddr.IPAddress(gw_ip).version == 4 else
+                          n_consts.IPv6_ANY)
             instance = self._get_keepalived_instance()
             instance.virtual_routes = (
                 [route for route in instance.virtual_routes
index 6b8d034d30febb5e69651f9b89339910596eca96..8ba7bcf6006a4a258804cb68619144d110da8259 100644 (file)
@@ -589,7 +589,7 @@ class Dnsmasq(DhcpLocalProcess):
             gateway = subnet.gateway_ip
             host_routes = []
             for hr in subnet.host_routes:
-                if hr.destination == "0.0.0.0/0":
+                if hr.destination == constants.IPv4_ANY:
                     if not gateway:
                         gateway = hr.nexthop
                 else:
@@ -613,7 +613,8 @@ class Dnsmasq(DhcpLocalProcess):
 
                 if host_routes:
                     if gateway:
-                        host_routes.append("%s,%s" % ("0.0.0.0/0", gateway))
+                        host_routes.append("%s,%s" % (constants.IPv4_ANY,
+                                                      gateway))
                     options.append(
                         self._format_option(subnet.ip_version, i,
                                             'classless-static-route',
index b30458a6e68bb8c014c77ac9bfaf94ea3e4b21b1..c7e3f5e98c40af474ab16ea5ff68f61a391b5e50 100644 (file)
@@ -68,6 +68,9 @@ IPv6 = 'IPv6'
 IPv4_BITS = 32
 IPv6_BITS = 128
 
+IPv4_ANY = '0.0.0.0/0'
+IPv6_ANY = '::/0'
+
 DHCP_RESPONSE_PORT = 68
 
 MIN_VLAN_TAG = 1
index cb647d11e9de8d578811c7ece2779bba1e9de460..70458c888db949df26e3770006b0fdaf9eb9cbc8 100644 (file)
@@ -18,6 +18,7 @@ import httplib
 from oslo_utils import excutils
 import six
 
+from neutron.common import constants
 from neutron.common import log as call_log
 from neutron.common import utils
 from neutron.i18n import _LE, _LW
@@ -95,7 +96,7 @@ class RouterOpenFlowDriver(RouterDriverBase):
 
     def _process_gw_port(self, gw_info, routes):
         if gw_info and gw_info['gateway_ip']:
-            routes.append({'destination': '0.0.0.0/0',
+            routes.append({'destination': constants.IPv4_ANY,
                            'nexthop': gw_info['gateway_ip']})
 
     @call_log.log
index 874449b286e560952449605cb75a4f54795fda04..f0ed6c52219272b8a7b5011c3079fe6d60aed438 100644 (file)
@@ -15,6 +15,7 @@
 import testtools
 
 from neutron.agent.linux import keepalived
+from neutron.common import constants as n_consts
 from neutron.tests import base
 
 # Keepalived user guide:
@@ -84,7 +85,7 @@ class KeepalivedConfBaseMixin(object):
         instance1.vips.append(vip_address3)
         instance1.vips.append(vip_address_ex)
 
-        virtual_route = keepalived.KeepalivedVirtualRoute("0.0.0.0/0",
+        virtual_route = keepalived.KeepalivedVirtualRoute(n_consts.IPv4_ANY,
                                                           "192.168.1.1",
                                                           "eth1")
         instance1.virtual_routes.append(virtual_route)
@@ -282,7 +283,7 @@ class KeepalivedVipAddressTestCase(base.BaseTestCase):
 
 class KeepalivedVirtualRouteTestCase(base.BaseTestCase):
     def test_virtual_route_with_dev(self):
-        route = keepalived.KeepalivedVirtualRoute('0.0.0.0/0', '1.2.3.4',
+        route = keepalived.KeepalivedVirtualRoute(n_consts.IPv4_ANY, '1.2.3.4',
                                                   'eth0')
         self.assertEqual('0.0.0.0/0 via 1.2.3.4 dev eth0',
                          route.build_config())
index 5691f1d22666760d82f91f4e641c6367cbdf3475..56c36d802d6279a1de71ceb818201a9d0472a343 100644 (file)
@@ -18,6 +18,7 @@ import webob.exc
 
 from neutron.api import extensions
 from neutron.common import config
+from neutron.common import constants as n_consts
 from neutron import context
 import neutron.extensions
 from neutron.extensions import metering
@@ -253,7 +254,7 @@ class TestMetering(MeteringPluginDbTestCase):
                                          excluded),
                 self.metering_label_rule(metering_label_id,
                                          direction,
-                                         '0.0.0.0/0',
+                                         n_consts.IPv4_ANY,
                                          False)) as metering_label_rule:
 
                 self._test_list_resources('metering-label-rule',
index ae88c86a024ba0a0aedff3d40b47965276fdf580..d79056be7a45481a171f47dbff959eebb8f700fb 100644 (file)
@@ -2572,7 +2572,7 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase):
     def test_create_subnet_bad_V4_cidr_prefix_len(self):
         with self.network() as network:
             data = {'subnet': {'network_id': network['network']['id'],
-                    'cidr': '0.0.0.0/0',
+                    'cidr': constants.IPv4_ANY,
                     'ip_version': '4',
                     'tenant_id': network['network']['tenant_id'],
                     'gateway_ip': '0.0.0.1'}}
index e51285dfbda809df0d951a5d4842df6e72253951..6b30e79f4031cdd16fe2110d3fa5d1cc6e3406b1 100644 (file)
@@ -196,7 +196,7 @@ class FakeV4HostRoute(object):
 
 
 class FakeV4HostRouteGateway(object):
-    destination = '0.0.0.0/0'
+    destination = constants.IPv4_ANY
     nexthop = '10.0.0.1'