Use method is_ipv6_enabled from oslo.utils
oslo.utils provides similar function[1] to check if ipv6 is supported. Though Manila and oslo.utils implemented in different way, we can improve the version of oslo.utils to make it suitable to other projects. [1]https://github.com/openstack/oslo.utils/blob\ /d1e08f533d4351f10b8103e24c254004b6627a29/oslo_utils/netutils.py#L170 TrivialFix Change-Id: I4ff99189943f4ca56f0532e58b1aedc63516074d
This commit is contained in:
parent
a2b79e1d5f
commit
63524af89d
@ -289,35 +289,6 @@ class GenericUtilsTestCase(test.TestCase):
|
|||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
timeutils.utcnow.assert_called_once_with()
|
timeutils.utcnow.assert_called_once_with()
|
||||||
|
|
||||||
def test_is_ipv6_configured0(self):
|
|
||||||
fake_fd = mock.Mock()
|
|
||||||
fake_fd.read.return_value = 'test'
|
|
||||||
with mock.patch('six.moves.builtins.open',
|
|
||||||
mock.Mock(return_value=fake_fd)) as open:
|
|
||||||
self.assertTrue(utils.is_ipv6_configured())
|
|
||||||
|
|
||||||
open.assert_called_once_with('/proc/net/if_inet6')
|
|
||||||
fake_fd.read.assert_called_once_with(32)
|
|
||||||
|
|
||||||
def test_is_ipv6_configured1(self):
|
|
||||||
fake_fd = mock.Mock()
|
|
||||||
fake_fd.read.return_value = ''
|
|
||||||
with mock.patch(
|
|
||||||
'six.moves.builtins.open', mock.Mock(return_value=fake_fd)):
|
|
||||||
self.assertFalse(utils.is_ipv6_configured())
|
|
||||||
|
|
||||||
def test_is_ipv6_configured2(self):
|
|
||||||
with mock.patch('six.moves.builtins.open',
|
|
||||||
mock.Mock(side_effect=IOError(
|
|
||||||
errno.ENOENT, 'Fake no such file error.'))):
|
|
||||||
self.assertFalse(utils.is_ipv6_configured())
|
|
||||||
|
|
||||||
def test_is_ipv6_configured3(self):
|
|
||||||
with mock.patch('six.moves.builtins.open',
|
|
||||||
mock.Mock(side_effect=IOError(
|
|
||||||
errno.EPERM, 'Fake no such file error.'))):
|
|
||||||
self.assertRaises(IOError, utils.is_ipv6_configured)
|
|
||||||
|
|
||||||
def test_is_eventlet_bug105(self):
|
def test_is_eventlet_bug105(self):
|
||||||
fake_dns = mock.Mock()
|
fake_dns = mock.Mock()
|
||||||
fake_dns.getaddrinfo.side_effect = socket.gaierror(errno.EBADF)
|
fake_dns.getaddrinfo.side_effect = socket.gaierror(errno.EBADF)
|
||||||
|
@ -102,7 +102,7 @@ class TestWSGIServer(test.TestCase):
|
|||||||
server.stop()
|
server.stop()
|
||||||
server.wait()
|
server.wait()
|
||||||
|
|
||||||
@testtools.skipIf(not utils.is_ipv6_configured(),
|
@testtools.skipIf(not netutils.is_ipv6_enabled(),
|
||||||
"Test requires an IPV6 configured interface")
|
"Test requires an IPV6 configured interface")
|
||||||
@testtools.skipIf(utils.is_eventlet_bug105(),
|
@testtools.skipIf(utils.is_eventlet_bug105(),
|
||||||
'Eventlet bug #105 affect test results.')
|
'Eventlet bug #105 affect test results.')
|
||||||
@ -212,7 +212,7 @@ class TestWSGIServer(test.TestCase):
|
|||||||
|
|
||||||
server.stop()
|
server.stop()
|
||||||
|
|
||||||
@testtools.skipIf(not utils.is_ipv6_configured(),
|
@testtools.skipIf(not netutils.is_ipv6_enabled(),
|
||||||
"Test requires an IPV6 configured interface")
|
"Test requires an IPV6 configured interface")
|
||||||
@testtools.skipIf(utils.is_eventlet_bug105(),
|
@testtools.skipIf(utils.is_eventlet_bug105(),
|
||||||
'Eventlet bug #105 affect test results.')
|
'Eventlet bug #105 affect test results.')
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
"""Utilities and helper functions."""
|
"""Utilities and helper functions."""
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import errno
|
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import os
|
import os
|
||||||
@ -270,24 +269,6 @@ def get_from_path(items, path):
|
|||||||
return get_from_path(results, remainder)
|
return get_from_path(results, remainder)
|
||||||
|
|
||||||
|
|
||||||
def is_ipv6_configured():
|
|
||||||
"""Check if system contain IPv6 capable network interface.
|
|
||||||
|
|
||||||
:rtype: bool
|
|
||||||
:raises: IOError
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
fd = open('/proc/net/if_inet6')
|
|
||||||
except IOError as e:
|
|
||||||
if e.errno != errno.ENOENT:
|
|
||||||
raise
|
|
||||||
result = False
|
|
||||||
else:
|
|
||||||
result = bool(fd.read(32))
|
|
||||||
fd.close()
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
def is_eventlet_bug105():
|
def is_eventlet_bug105():
|
||||||
"""Check if eventlet support IPv6 addresses.
|
"""Check if eventlet support IPv6 addresses.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user