File 0001-Claim-IPv6-is-unsupported-if-no-interface-with-IPv6-.patch of Package openstack-nova

From eb438a32371c6a042af604da7e186c119a9ea945 Mon Sep 17 00:00:00 2001
From: Dirk Mueller <dirk@dmllr.de>
Date: Sun, 21 Jul 2013 16:07:57 +0200
Subject: [PATCH] Claim IPv6 is unsupported if no interface with IPv6
 configured

When IPv6 is supported by glibc but no interface
is configured to use ipv6 (because the ipv6 module
is not loaded), skip ipv6 related checks.

Change-Id: I15aaf3d01f0f51bdc0bd29f30728ca2ab8b5c30a
---
 nova/tests/test_test_utils.py | 30 ++++++++++++++++++++++++++++++
 nova/tests/utils.py           | 13 ++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/nova/tests/test_test_utils.py b/nova/tests/test_test_utils.py
index ef3a6fb..2184d39 100644
--- a/nova/tests/test_test_utils.py
+++ b/nova/tests/test_test_utils.py
@@ -14,6 +14,11 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import errno
+import socket
+
+import fixtures
+
 from nova import db
 from nova import test
 from nova.tests import utils as test_utils
@@ -39,3 +44,28 @@ class TestUtilsTestCase(test.TestCase):
         # The challenge here is to define what exactly such a structure
         # must look like.
         pass
+
+    def test_ipv6_supported(self):
+        self.assertIn(test_utils.is_ipv6_supported(), (False, True))
+
+        def fake_open(path):
+            raise IOError
+
+        def fake_socket_fail(x, y):
+            e = socket.error()
+            e.errno = errno.EAFNOSUPPORT
+            raise e
+
+        def fake_socket_ok(x, y):
+            return
+
+        with fixtures.MonkeyPatch('socket.socket', fake_socket_fail):
+            self.assertFalse(test_utils.is_ipv6_supported())
+
+        with fixtures.MonkeyPatch('socket.socket', fake_socket_ok):
+            with fixtures.MonkeyPatch('sys.platform', 'windows'):
+                self.assertTrue(test_utils.is_ipv6_supported())
+
+            with fixtures.MonkeyPatch('sys.platform', 'linux2'):
+                with fixtures.MonkeyPatch('__builtin__.open', fake_open):
+                    self.assertFalse(test_utils.is_ipv6_supported())
diff --git a/nova/tests/utils.py b/nova/tests/utils.py
index 748a850..20a924c 100644
--- a/nova/tests/utils.py
+++ b/nova/tests/utils.py
@@ -17,6 +17,7 @@
 import errno
 import platform
 import socket
+import sys
 
 from oslo.config import cfg
 
@@ -177,7 +178,7 @@ def killer_xml_body():
 
 
 def is_ipv6_supported():
-    has_ipv6_support = True
+    has_ipv6_support = socket.has_ipv6
     try:
         s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
     except socket.error as e:
@@ -185,4 +186,14 @@ def is_ipv6_supported():
             has_ipv6_support = False
         else:
             raise
+
+    # check if there is at least one interface with ipv6
+    if has_ipv6_support and sys.platform.startswith('linux'):
+        try:
+            with open('/proc/net/if_inet6') as f:
+                if not f.read():
+                    has_ipv6_support = False
+        except IOError:
+            has_ipv6_support = False
+
     return has_ipv6_support
-- 
1.8.4.1

openSUSE Build Service is sponsored by