Merge "Claim IPv6 is unsupported if no interface with IPv6 configured"

This commit is contained in:
Jenkins 2013-10-29 20:08:53 +00:00 committed by Gerrit Code Review
commit d533c9b792
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