Merge "Rename ipv6_utils.is_enabled()"

This commit is contained in:
Jenkins 2016-10-27 23:14:55 +00:00 committed by Gerrit Code Review
commit bf81b49a37
6 changed files with 26 additions and 13 deletions

View File

@ -250,7 +250,7 @@ class L3NATAgent(ha.AgentMixin,
super(L3NATAgent, self).__init__(host=self.conf.host)
self.target_ex_net_id = None
self.use_ipv6 = ipv6_utils.is_enabled()
self.use_ipv6 = ipv6_utils.is_enabled_and_bind_by_default()
self.pd = pd.PrefixDelegation(self.context, self.process_monitor,
self.driver,

View File

@ -67,7 +67,7 @@ class IptablesFirewallDriver(firewall.FirewallDriver):
def __init__(self, namespace=None):
self.iptables = iptables_manager.IptablesManager(
use_ipv6=ipv6_utils.is_enabled(),
use_ipv6=ipv6_utils.is_enabled_and_bind_by_default(),
namespace=namespace)
# TODO(majopela, shihanzhang): refactor out ipset to a separate
# driver composed over this one

View File

@ -18,6 +18,7 @@ IPv6-related utilities and helper functions.
"""
import os
from debtcollector import moves
from debtcollector import removals
import netaddr
from neutron_lib import constants as const
@ -53,7 +54,10 @@ def get_ipv6_addr_by_EUI64(prefix, mac):
'EUI-64: %s') % prefix)
def is_enabled():
def is_enabled_and_bind_by_default():
"""Check if host has the IPv6 support and is configured to bind IPv6
address to new interfaces by default.
"""
global _IS_IPV6_ENABLED
if _IS_IPV6_ENABLED is None:
@ -65,10 +69,18 @@ def is_enabled():
else:
_IS_IPV6_ENABLED = False
if not _IS_IPV6_ENABLED:
LOG.info(_LI("IPv6 is not enabled on this system."))
LOG.info(_LI("IPv6 not present or configured not to bind to new "
"interfaces on this system. Please ensure IPv6 is "
"enabled and /proc/sys/net/ipv6/conf/default/"
"disable_ipv6 is set to 1 to enable IPv6."))
return _IS_IPV6_ENABLED
is_enabled = moves.moved_function(is_enabled_and_bind_by_default,
'is_enabled', __name__, version='Ocata',
removal_version='Pike')
def is_auto_address_subnet(subnet):
"""Check if subnet is an auto address subnet."""
modes = [const.IPV6_SLAAC, const.DHCPV6_STATELESS]

View File

@ -74,7 +74,7 @@ class RouterWithMetering(object):
namespace=self.ns_name,
binary_name=WRAP_NAME,
state_less=True,
use_ipv6=ipv6_utils.is_enabled())
use_ipv6=ipv6_utils.is_enabled_and_bind_by_default())
self.metering_labels = {}

View File

@ -98,7 +98,8 @@ class L3HATestCase(framework.L3AgentTestFramework):
self._router_lifecycle(enable_ha=True, dual_stack=True,
v6_ext_gw_with_sub=False)
@testtools.skipUnless(ipv6_utils.is_enabled(), "IPv6 is not enabled")
@testtools.skipUnless(ipv6_utils.is_enabled_and_bind_by_default(),
"IPv6 is not enabled")
def test_ipv6_router_advts_after_router_state_change(self):
# Schedule router to l3 agent, and then add router gateway. Verify
# that router gw interface is configured to receive Router Advts.

View File

@ -55,10 +55,10 @@ class IPv6byEUI64TestCase(base.BaseTestCase):
ipv6_utils.get_ipv6_addr_by_EUI64(prefix, mac))
class TestIsEnabled(base.BaseTestCase):
class TestIsEnabledAndBindByDefault(base.BaseTestCase):
def setUp(self):
super(TestIsEnabled, self).setUp()
super(TestIsEnabledAndBindByDefault, self).setUp()
def reset_detection_flag():
ipv6_utils._IS_IPV6_ENABLED = None
@ -70,25 +70,25 @@ class TestIsEnabled(base.BaseTestCase):
def test_enabled(self):
self.useFixture(tools.OpenFixture(self.proc_path, '0'))
enabled = ipv6_utils.is_enabled()
enabled = ipv6_utils.is_enabled_and_bind_by_default()
self.assertTrue(enabled)
def test_disabled(self):
self.useFixture(tools.OpenFixture(self.proc_path, '1'))
enabled = ipv6_utils.is_enabled()
enabled = ipv6_utils.is_enabled_and_bind_by_default()
self.assertFalse(enabled)
def test_disabled_non_exists(self):
mo = self.useFixture(tools.OpenFixture(self.proc_path, '1')).mock_open
self.mock_exists.return_value = False
enabled = ipv6_utils.is_enabled()
enabled = ipv6_utils.is_enabled_and_bind_by_default()
self.assertFalse(enabled)
self.assertFalse(mo.called)
def test_memoize(self):
mo = self.useFixture(tools.OpenFixture(self.proc_path, '0')).mock_open
ipv6_utils.is_enabled()
enabled = ipv6_utils.is_enabled()
ipv6_utils.is_enabled_and_bind_by_default()
enabled = ipv6_utils.is_enabled_and_bind_by_default()
self.assertTrue(enabled)
mo.assert_called_once_with(self.proc_path, 'r')