From 6ccd411831183df5eb23e14393fb890ac103929e Mon Sep 17 00:00:00 2001 From: Matthew Thode Date: Wed, 10 Dec 2014 15:12:25 -0600 Subject: [PATCH] moving vxlan module check to sanity checks and making practical Instead of checking via modinfo (which only checks if a module is available) this checks actual usage, which is a more reliable way of testing real world problems. Change-Id: Ida78652ed50e2cb16fa0ab7194d8468714b99d61 Closes-Bug: 1339197 --- neutron/cmd/sanity/checks.py | 10 +++++++- neutron/cmd/sanity_check.py | 24 +++++++++++++++---- .../agent/linuxbridge_neutron_agent.py | 11 --------- .../tests/functional/sanity/test_sanity.py | 5 +++- .../unit/linuxbridge/test_lb_neutron_agent.py | 24 ++----------------- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/neutron/cmd/sanity/checks.py b/neutron/cmd/sanity/checks.py index de7de5482..c0c971b25 100644 --- a/neutron/cmd/sanity/checks.py +++ b/neutron/cmd/sanity/checks.py @@ -29,13 +29,21 @@ from neutron.plugins.openvswitch.common import constants as ovs_const LOG = logging.getLogger(__name__) -def vxlan_supported(root_helper, from_ip='192.0.2.1', to_ip='192.0.2.2'): +def ovs_vxlan_supported(root_helper, from_ip='192.0.2.1', to_ip='192.0.2.2'): name = "vxlantest-" + utils.get_random_string(6) with ovs_lib.OVSBridge(name, root_helper) as br: port = br.add_tunnel_port(from_ip, to_ip, const.TYPE_VXLAN) return port != ovs_lib.INVALID_OFPORT +def iproute2_vxlan_supported(root_helper): + ip = ip_lib.IPWrapper(root_helper) + name = "vxlantest-" + utils.get_random_string(4) + port = ip.add_vxlan(name, 3000) + ip.del_veth(name) + return name == port.name + + def patch_supported(root_helper): seed = utils.get_random_string(6) name = "patchtest-" + seed diff --git a/neutron/cmd/sanity_check.py b/neutron/cmd/sanity_check.py index 76bb46b80..2686f1a89 100644 --- a/neutron/cmd/sanity_check.py +++ b/neutron/cmd/sanity_check.py @@ -25,6 +25,8 @@ from oslo.config import cfg LOG = logging.getLogger(__name__) cfg.CONF.import_group('AGENT', 'neutron.plugins.openvswitch.common.config') cfg.CONF.import_group('OVS', 'neutron.plugins.openvswitch.common.config') +cfg.CONF.import_group('VXLAN', 'neutron.plugins.linuxbridge.common.config') +cfg.CONF.import_group('ml2', 'neutron.plugins.ml2.config') cfg.CONF.import_group('ml2_sriov', 'neutron.plugins.ml2.drivers.mech_sriov.mech_driver') @@ -38,7 +40,7 @@ class BoolOptCallback(cfg.BoolOpt): def check_ovs_vxlan(): - result = checks.vxlan_supported(root_helper=cfg.CONF.AGENT.root_helper) + result = checks.ovs_vxlan_supported(root_helper=cfg.CONF.AGENT.root_helper) if not result: LOG.error(_LE('Check for Open vSwitch VXLAN support failed. ' 'Please ensure that the version of openvswitch ' @@ -46,6 +48,15 @@ def check_ovs_vxlan(): return result +def check_iproute2_vxlan(): + result = checks.iproute2_vxlan_supported( + root_helper=cfg.CONF.AGENT.root_helper) + if not result: + LOG.error(_LE('Check for iproute2 VXLAN support failed. Please ensure ' + 'that the iproute2 has VXLAN support.')) + return result + + def check_ovs_patch(): result = checks.patch_supported(root_helper=cfg.CONF.AGENT.root_helper) if not result: @@ -108,9 +119,11 @@ def check_vf_management(): # Define CLI opts to test specific features, with a calback for the test OPTS = [ - BoolOptCallback('ovs_vxlan', check_ovs_vxlan, - help=_('Check for vxlan support')), - BoolOptCallback('ovs_patch', check_ovs_patch, + BoolOptCallback('ovs_vxlan', check_ovs_vxlan, default=False, + help=_('Check for OVS vxlan support')), + BoolOptCallback('iproute2_vxlan', check_iproute2_vxlan, default=False, + help=_('Check for iproute2 vxlan support')), + BoolOptCallback('ovs_patch', check_ovs_patch, default=False, help=_('Check for patch port support')), BoolOptCallback('nova_notify', check_nova_notify, help=_('Check for nova notification support')), @@ -131,6 +144,9 @@ def enable_tests_from_config(): if 'vxlan' in cfg.CONF.AGENT.tunnel_types: cfg.CONF.set_override('ovs_vxlan', True) + if ('vxlan' in cfg.CONF.ml2.type_drivers or + cfg.CONF.VXLAN.enable_vxlan): + cfg.CONF.set_override('iproute2_vxlan', True) if cfg.CONF.AGENT.tunnel_types: cfg.CONF.set_override('ovs_patch', True) if not cfg.CONF.OVS.use_veth_interconnection: diff --git a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py index 7507d404c..b302e199e 100755 --- a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -562,19 +562,8 @@ class LinuxBridgeManager: return False return True - def vxlan_module_supported(self): - try: - utils.execute(cmd=['modinfo', 'vxlan'], log_fail_as_error=False) - return True - except RuntimeError: - return False - def check_vxlan_support(self): self.vxlan_mode = lconst.VXLAN_NONE - if not self.vxlan_module_supported(): - LOG.error(_LE('Linux kernel vxlan module and iproute2 3.8 or ' - 'above are required to enable VXLAN.')) - raise exceptions.VxlanNetworkUnsupported() if self.vxlan_ucast_supported(): self.vxlan_mode = lconst.VXLAN_UCAST diff --git a/neutron/tests/functional/sanity/test_sanity.py b/neutron/tests/functional/sanity/test_sanity.py index 3006ffa5e..87703114e 100644 --- a/neutron/tests/functional/sanity/test_sanity.py +++ b/neutron/tests/functional/sanity/test_sanity.py @@ -45,7 +45,10 @@ class SanityTestCaseRoot(functional_base.BaseSudoTestCase): self.check_sudo_enabled() def test_ovs_vxlan_support_runs(self): - checks.vxlan_supported(self.root_helper) + checks.ovs_vxlan_supported(self.root_helper) + + def test_iproute2_vxlan_support_runs(self): + checks.iproute2_vxlan_supported(self.root_helper) def test_ovs_patch_support_runs(self): checks.patch_supported(self.root_helper) diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py index 1a2bbc4d2..09a5d78cf 100644 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py @@ -829,11 +829,9 @@ class TestLinuxBridgeManager(base.BaseTestCase): self.lbm.delete_vlan("eth1.1") self.assertTrue(exec_fn.called) - def _check_vxlan_support(self, expected, vxlan_module_supported, - vxlan_ucast_supported, vxlan_mcast_supported): + def _check_vxlan_support(self, expected, vxlan_ucast_supported, + vxlan_mcast_supported): with contextlib.nested( - mock.patch.object(self.lbm, 'vxlan_module_supported', - return_value=vxlan_module_supported), mock.patch.object(self.lbm, 'vxlan_ucast_supported', return_value=vxlan_ucast_supported), mock.patch.object(self.lbm, 'vxlan_mcast_supported', @@ -848,37 +846,19 @@ class TestLinuxBridgeManager(base.BaseTestCase): def test_check_vxlan_support(self): self._check_vxlan_support(expected=lconst.VXLAN_UCAST, - vxlan_module_supported=True, vxlan_ucast_supported=True, vxlan_mcast_supported=True) self._check_vxlan_support(expected=lconst.VXLAN_MCAST, - vxlan_module_supported=True, vxlan_ucast_supported=False, vxlan_mcast_supported=True) self._check_vxlan_support(expected=lconst.VXLAN_NONE, - vxlan_module_supported=False, vxlan_ucast_supported=False, vxlan_mcast_supported=False) self._check_vxlan_support(expected=lconst.VXLAN_NONE, - vxlan_module_supported=True, vxlan_ucast_supported=False, vxlan_mcast_supported=False) - def _check_vxlan_module_supported(self, expected, execute_side_effect): - with mock.patch.object( - utils, 'execute', - side_effect=execute_side_effect): - self.assertEqual(expected, self.lbm.vxlan_module_supported()) - - def test_vxlan_module_supported(self): - self._check_vxlan_module_supported( - expected=True, - execute_side_effect=None) - self._check_vxlan_module_supported( - expected=False, - execute_side_effect=RuntimeError()) - def _check_vxlan_ucast_supported( self, expected, l2_population, iproute_arg_supported, fdb_append): cfg.CONF.set_override('l2_population', l2_population, 'VXLAN') -- 2.45.2