From 0d25a8595b409f68d84326f5139e28a0f3b7ab2e Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Tue, 28 Mar 2017 15:12:46 +0300 Subject: [PATCH] Skip spawn plugin init methods in unittests Some of the vmware-nsx plugins init methods, cause eventlet.spawn_n to be called. We suspect that this may occasionally fail the unittests on DBNonExistentTable error. This patch mocks those init methods which have no affect on the unittests. Change-Id: Id46e473bb4efb17b366aee670def91ace4985b0d --- vmware_nsx/tests/unit/nsx_v/test_plugin.py | 19 +++++++++++++++++++ vmware_nsx/tests/unit/nsx_v3/test_plugin.py | 8 +++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/tests/unit/nsx_v/test_plugin.py b/vmware_nsx/tests/unit/nsx_v/test_plugin.py index 0b7c4f9137..72e7a1946a 100644 --- a/vmware_nsx/tests/unit/nsx_v/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v/test_plugin.py @@ -158,6 +158,17 @@ class NsxVPluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): mock_delete_dhcp_service = mock.patch("%s.%s" % ( vmware.EDGE_MANAGE_NAME, 'delete_dhcp_edge_service')) mock_delete_dhcp_service.start() + mock_check_backup_edge_pools = mock.patch("%s.%s" % ( + vmware.EDGE_MANAGE_NAME, '_check_backup_edge_pools')) + mock_check_backup_edge_pools.start() + mock_deploy_backup_edges_at_backend = mock.patch("%s.%s" % ( + vmware.EDGE_MANAGE_NAME, '_deploy_backup_edges_at_backend')) + mock_deploy_backup_edges_at_backend.start() + mock_process_security_group_logging = mock.patch( + 'vmware_nsx.plugin.NsxVPlugin.' + '_process_security_groups_rules_logging') + mock_process_security_group_logging.start() + self.default_res_pool = 'respool-28' cfg.CONF.set_override("resource_pool_id", self.default_res_pool, group="nsxv") @@ -3372,6 +3383,14 @@ class NsxVSecurityGroupsTestCase(ext_sg.SecurityGroupDBTestCase): mock_delete_dhcp_service = mock.patch("%s.%s" % ( vmware.EDGE_MANAGE_NAME, 'delete_dhcp_edge_service')) mock_delete_dhcp_service.start() + mock_check_backup_edge_pools = mock.patch("%s.%s" % ( + vmware.EDGE_MANAGE_NAME, '_check_backup_edge_pools')) + mock_check_backup_edge_pools.start() + mock_process_security_group_logging = mock.patch( + 'vmware_nsx.plugin.NsxVPlugin.' + '_process_security_groups_rules_logging') + mock_process_security_group_logging.start() + c_utils.spawn_n = mock.Mock(side_effect=lambda f: f()) super(NsxVSecurityGroupsTestCase, self).setUp(plugin=plugin, ext_mgr=ext_mgr) diff --git a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py index befb57c4f0..2014c65d32 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_plugin.py @@ -160,6 +160,12 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase, 'network_scheduler_driver', 'neutron.scheduler.dhcp_agent_scheduler.AZAwareWeightScheduler') + def mock_plugin_methods(self): + # mock unnecessary call which causes spawn + mock_process_security_group_logging = mock.patch.object( + nsx_plugin.NsxV3Plugin, '_process_security_group_logging') + mock_process_security_group_logging.start() + def setUp(self, plugin=PLUGIN_NAME, ext_mgr=None, service_plugins=None): @@ -168,7 +174,7 @@ class NsxV3PluginTestCaseMixin(test_plugin.NeutronDbPluginV2TestCase, _mock_nsx_backend_calls() self.setup_conf_overrides() - + self.mock_plugin_methods() super(NsxV3PluginTestCaseMixin, self).setUp(plugin=plugin, ext_mgr=ext_mgr)