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
This commit is contained in:
Dirk Mueller 2013-07-21 16:07:57 +02:00
parent ab19f2e9db
commit eb438a3237
2 changed files with 42 additions and 1 deletions

View File

@ -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())

View File

@ -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