]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Check for IPv6 file before reading
authorKevin Benton <blak111@gmail.com>
Tue, 26 Aug 2014 08:52:00 +0000 (01:52 -0700)
committerKevin Benton <blak111@gmail.com>
Wed, 27 Aug 2014 15:04:11 +0000 (08:04 -0700)
Check to see if the IPv6 disabled flag file exists
before trying to read it. This file doesn't exist
on systems with the IPv6 module blacklisted.

Closes-Bug: #1361542
Change-Id: I4064b4189cc9d8f0f0e0e7025cf6f83d5b6ec276

neutron/common/ipv6_utils.py

index 21b86acae192d34eeb58367a820e12d9235af376..96e1ef23440e67b47cdc43023426fdf15b1374d3 100644 (file)
 """
 IPv6-related utilities and helper functions.
 """
+import os
 
 import netaddr
 
+from neutron.openstack.common.gettextutils import _LI
+from neutron.openstack.common import log
 
+
+LOG = log.getLogger(__name__)
 _IS_IPV6_ENABLED = None
 
 
@@ -47,7 +52,12 @@ def is_enabled():
 
     if _IS_IPV6_ENABLED is None:
         disabled_ipv6_path = "/proc/sys/net/ipv6/conf/default/disable_ipv6"
-        with open(disabled_ipv6_path, 'r') as f:
-            disabled = f.read().strip()
-        _IS_IPV6_ENABLED = disabled == "0"
+        if os.path.exists(disabled_ipv6_path):
+            with open(disabled_ipv6_path, 'r') as f:
+                disabled = f.read().strip()
+            _IS_IPV6_ENABLED = disabled == "0"
+        else:
+            _IS_IPV6_ENABLED = False
+        if not _IS_IPV6_ENABLED:
+            LOG.info(_LI("IPv6 is not enabled on this system."))
     return _IS_IPV6_ENABLED