Merge "Claim IPv6 is unsupported if no interface with IPv6 configured"
This commit is contained in:
commit
d533c9b792
@ -14,6 +14,11 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import errno
|
||||||
|
import socket
|
||||||
|
|
||||||
|
import fixtures
|
||||||
|
|
||||||
from nova import db
|
from nova import db
|
||||||
from nova import test
|
from nova import test
|
||||||
from nova.tests import utils as test_utils
|
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
|
# The challenge here is to define what exactly such a structure
|
||||||
# must look like.
|
# must look like.
|
||||||
pass
|
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())
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
import errno
|
import errno
|
||||||
import platform
|
import platform
|
||||||
import socket
|
import socket
|
||||||
|
import sys
|
||||||
|
|
||||||
from oslo.config import cfg
|
from oslo.config import cfg
|
||||||
|
|
||||||
@ -177,7 +178,7 @@ def killer_xml_body():
|
|||||||
|
|
||||||
|
|
||||||
def is_ipv6_supported():
|
def is_ipv6_supported():
|
||||||
has_ipv6_support = True
|
has_ipv6_support = socket.has_ipv6
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
@ -185,4 +186,14 @@ def is_ipv6_supported():
|
|||||||
has_ipv6_support = False
|
has_ipv6_support = False
|
||||||
else:
|
else:
|
||||||
raise
|
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
|
return has_ipv6_support
|
||||||
|
Loading…
Reference in New Issue
Block a user