From ff9c7cf1a28736c431e5d8571012f3512e21ba7c Mon Sep 17 00:00:00 2001 From: elajkat Date: Thu, 21 Jul 2022 16:53:45 +0200 Subject: [PATCH] Test: mock out _check_netfilter_for_bridges in unit tests _check_netfilter_for_bridges do some calls which are not for unit tests. Specifically the call for sysctl -N net.bridge seems to be broken with a recent kernel upgrade on bionic (see the irc log for this discussion in [1]). Add OS_TEST_TIMEOUT:180 to tox testenv, this can help to debug such issues. During the rootwrap to privsep change some of these mocks were added, (see [2]) so backporting (before Wallaby mostly) can be done with caution. [1]: https://meetings.opendev.org/irclogs/%23openstack-infra/%23openstack-infra.2022-07-20.log.html#t2022-07-20T12:59:32 [2]: https://review.opendev.org/c/openstack/neutron/+/764015/12/neutron/tests/unit/agent/linux/openvswitch_firewall/test_iptables.py Change-Id: Ic366d67770cc6e19a4412eaf2f1ab53780e98ee8 Closes-Bug: #1982206 (cherry picked from commit 119b82f1b10df50a696e936e80672c7ddb00436f) --- .../linux/openvswitch_firewall/test_iptables.py | 16 ++++++++++------ .../openvswitch/agent/test_ovs_neutron_agent.py | 5 ++++- tox.ini | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/neutron/tests/unit/agent/linux/openvswitch_firewall/test_iptables.py b/neutron/tests/unit/agent/linux/openvswitch_firewall/test_iptables.py index b1af575ddd7..3a72495b296 100644 --- a/neutron/tests/unit/agent/linux/openvswitch_firewall/test_iptables.py +++ b/neutron/tests/unit/agent/linux/openvswitch_firewall/test_iptables.py @@ -73,14 +73,18 @@ class TestHelper(base.BaseTestCase): self.helper.int_br.get_port_name_list.return_value = [ 'tap1234', 'qvo-1234', 'tap9876', 'qvo-fghfhfh'] self.helper.int_br.db_get_val.return_value = {'foo': 'bar'} - self.helper.load_driver_if_needed() - self.assertIsNotNone(self.helper.iptables_driver) + with mock.patch.object(iptables_firewall.IptablesFirewallDriver, + '_check_netfilter_for_bridges'): + self.helper.load_driver_if_needed() + self.assertIsNotNone(self.helper.iptables_driver) def test_get_iptables_driver_instance_has_correct_instance(self): - instance = iptables.get_iptables_driver_instance() - self.assertIsInstance( - instance, - iptables_firewall.OVSHybridIptablesFirewallDriver) + with mock.patch.object(iptables_firewall.IptablesFirewallDriver, + '_check_netfilter_for_bridges'): + instance = iptables.get_iptables_driver_instance() + self.assertIsInstance( + instance, + iptables_firewall.OVSHybridIptablesFirewallDriver) def test_cleanup_port_last_port_marks_cleaned(self): self.helper.iptables_driver = mock.Mock() diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index 000cac0cfe7..db90390e103 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -37,6 +37,7 @@ from neutron.agent.common import ovs_lib from neutron.agent.common import polling from neutron.agent.common import utils from neutron.agent.linux import ip_lib +from neutron.agent.linux import iptables_firewall from neutron.agent.linux import utils as linux_utils from neutron.api.rpc.callbacks import resources from neutron.objects.ports import Port @@ -151,7 +152,9 @@ class TestOvsNeutronAgent(object): 'setup_ancillary_bridges', return_value=[]),\ mock.patch('neutron.agent.linux.ip_lib.get_device_mac', - return_value='00:00:00:00:00:01'),\ + return_value='00:00:00:00:00:01'), \ + mock.patch.object(iptables_firewall.IptablesFirewallDriver, + '_check_netfilter_for_bridges'), \ mock.patch( 'neutron.agent.common.ovs_lib.BaseOVS.get_bridges'),\ mock.patch('oslo_service.loopingcall.FixedIntervalLoopingCall', diff --git a/tox.ini b/tox.ini index 0b93928732d..1ceb5552f81 100644 --- a/tox.ini +++ b/tox.ini @@ -10,6 +10,7 @@ setenv = VIRTUAL_ENV={envdir} OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true} OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true} OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true} + OS_TEST_TIMEOUT={env:OS_TEST_TIMEOUT:180} PYTHONWARNINGS=default::DeprecationWarning,ignore::DeprecationWarning:distutils,ignore::DeprecationWarning:site passenv = TRACE_FAILONLY GENERATE_HASHES http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY TOX_ENV_SRC_MODULES usedevelop = True