From 1e0ea5217a93fadb915c3dcdf4c260738bed70ac Mon Sep 17 00:00:00 2001 From: rossella Date: Thu, 10 Apr 2014 09:33:43 +0000 Subject: [PATCH] Remove mock.patch.stop from tests that inherit from BaseTestCase The tests that inherit from BaseTestCase don't need to stop their patches, since this is already done in the base class Change-Id: Ibb1183e521686d6e948046997b32f4044d91d9e7 Closes-bug: #1305656 --- neutron/tests/unit/cisco/test_nexus_plugin.py | 1 - .../unit/linuxbridge/test_lb_neutron_agent.py | 3 - .../tests/unit/midonet/test_midonet_driver.py | 1 - .../tests/unit/mlnx/test_mlnx_comm_utils.py | 1 - .../drivers/linux/test_iptables_fwaas.py | 2 - .../metering/drivers/test_iptables_driver.py | 2 - neutron/tests/unit/test_agent_linux_utils.py | 1 - neutron/tests/unit/test_api_v2.py | 3 - neutron/tests/unit/test_db_migration.py | 1 - neutron/tests/unit/test_db_plugin.py | 212 ++++++++---------- neutron/tests/unit/test_dhcp_agent.py | 20 -- .../tests/unit/test_extension_ext_gw_mode.py | 1 - neutron/tests/unit/test_iptables_firewall.py | 2 - neutron/tests/unit/test_linux_daemon.py | 8 - .../tests/unit/test_linux_external_process.py | 1 - neutron/tests/unit/test_linux_interface.py | 4 - neutron/tests/unit/test_linux_ip_lib.py | 2 - neutron/tests/unit/test_metadata_agent.py | 3 - .../unit/test_metadata_namespace_proxy.py | 1 - neutron/tests/unit/test_neutron_context.py | 1 - neutron/tests/unit/test_policy.py | 2 - neutron/tests/unit/test_quota_ext.py | 1 - .../unit/vmware/extensions/test_networkgw.py | 1 - neutron/tests/unit/vmware/nsxlib/base.py | 2 - neutron/tests/unit/vmware/nsxlib/test_lsn.py | 1 - neutron/tests/unit/vmware/test_dhcpmeta.py | 3 - neutron/tests/unit/vmware/test_nsx_opts.py | 2 - neutron/tests/unit/vmware/test_nsx_sync.py | 4 - .../unit/vmware/vshield/test_vcns_driver.py | 1 - 29 files changed, 91 insertions(+), 196 deletions(-) diff --git a/neutron/tests/unit/cisco/test_nexus_plugin.py b/neutron/tests/unit/cisco/test_nexus_plugin.py index 395c40643..58bf90f1f 100644 --- a/neutron/tests/unit/cisco/test_nexus_plugin.py +++ b/neutron/tests/unit/cisco/test_nexus_plugin.py @@ -151,7 +151,6 @@ class TestCiscoNexusPlugin(base.BaseTestCase): self.patch_obj = mock.patch.dict('sys.modules', {'ncclient': self.mock_ncclient}) self.patch_obj.start() - self.addCleanup(self.patch_obj.stop) with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin, '__init__', new=new_nexus_init): diff --git a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py index f4c5d41c7..fed96aa88 100644 --- a/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py +++ b/neutron/tests/unit/linuxbridge/test_lb_neutron_agent.py @@ -105,12 +105,10 @@ class TestLinuxBridgeAgent(base.BaseTestCase): group='SECURITYGROUP') self.execute_p = mock.patch.object(ip_lib.IPWrapper, '_execute') self.execute = self.execute_p.start() - self.addCleanup(self.execute_p.stop) self.execute.return_value = '\n'.join(self.LINK_SAMPLE) self.get_mac_p = mock.patch('neutron.agent.linux.utils.' 'get_interface_mac') self.get_mac = self.get_mac_p.start() - self.addCleanup(self.get_mac_p.stop) self.get_mac.return_value = '00:00:00:00:00:01' def test_update_devices_failed(self): @@ -761,7 +759,6 @@ class TestLinuxBridgeRpcCallbacks(base.BaseTestCase): self.u_execute_p = mock.patch('neutron.agent.linux.utils.execute') self.u_execute = self.u_execute_p.start() - self.addCleanup(self.u_execute_p.stop) class FakeLBAgent(object): def __init__(self): diff --git a/neutron/tests/unit/midonet/test_midonet_driver.py b/neutron/tests/unit/midonet/test_midonet_driver.py index dc33bcef1..84c3b62a5 100644 --- a/neutron/tests/unit/midonet/test_midonet_driver.py +++ b/neutron/tests/unit/midonet/test_midonet_driver.py @@ -45,7 +45,6 @@ class TestDhcpNoOpDriver(base.BaseTestCase): self.conf.use_namespaces = True instance = mock.patch("neutron.agent.linux.dhcp.DeviceManager") self.mock_mgr = instance.start() - self.addCleanup(instance.stop) def test_disable_no_retain_port(self): dhcp_driver = driver.DhcpNoOpDriver(self.conf, FakeNetwork()) diff --git a/neutron/tests/unit/mlnx/test_mlnx_comm_utils.py b/neutron/tests/unit/mlnx/test_mlnx_comm_utils.py index 00659e02c..75d235759 100644 --- a/neutron/tests/unit/mlnx/test_mlnx_comm_utils.py +++ b/neutron/tests/unit/mlnx/test_mlnx_comm_utils.py @@ -31,7 +31,6 @@ class TestRetryDecorator(base.BaseTestCase): super(TestRetryDecorator, self).setUp() self.sleep_fn_p = mock.patch.object(RetryDecorator, 'sleep_fn') self.sleep_fn = self.sleep_fn_p.start() - self.addCleanup(self.sleep_fn_p.stop) def test_no_retry_required(self): self.counter = 0 diff --git a/neutron/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py b/neutron/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py index 85a6c155c..f3fba7da5 100644 --- a/neutron/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py +++ b/neutron/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py @@ -43,11 +43,9 @@ class IptablesFwaasTestCase(base.BaseTestCase): self.utils_exec_p = mock.patch( 'neutron.agent.linux.utils.execute') self.utils_exec = self.utils_exec_p.start() - self.addCleanup(self.utils_exec_p.stop) self.iptables_cls_p = mock.patch( 'neutron.agent.linux.iptables_manager.IptablesManager') self.iptables_cls_p.start() - self.addCleanup(self.iptables_cls_p.stop) self.firewall = fwaas.IptablesFwaasDriver() def _fake_rules_v4(self, fwid, apply_list): diff --git a/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py b/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py index f78382dd1..c6131154c 100644 --- a/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py +++ b/neutron/tests/unit/services/metering/drivers/test_iptables_driver.py @@ -33,11 +33,9 @@ class IptablesDriverTestCase(base.BaseTestCase): self.utils_exec_p = mock.patch( 'neutron.agent.linux.utils.execute') self.utils_exec = self.utils_exec_p.start() - self.addCleanup(self.utils_exec_p.stop) self.iptables_cls_p = mock.patch( 'neutron.agent.linux.iptables_manager.IptablesManager') self.iptables_cls = self.iptables_cls_p.start() - self.addCleanup(self.iptables_cls_p.stop) self.iptables_inst = mock.Mock() self.v4filter_inst = mock.Mock() self.v6filter_inst = mock.Mock() diff --git a/neutron/tests/unit/test_agent_linux_utils.py b/neutron/tests/unit/test_agent_linux_utils.py index b0904c3ff..fd085b883 100644 --- a/neutron/tests/unit/test_agent_linux_utils.py +++ b/neutron/tests/unit/test_agent_linux_utils.py @@ -29,7 +29,6 @@ class AgentUtilsExecuteTest(base.BaseTestCase): open(self.test_file, 'w').close() self.mock_popen_p = mock.patch("subprocess.Popen.communicate") self.mock_popen = self.mock_popen_p.start() - self.addCleanup(self.mock_popen_p.stop) def test_without_helper(self): expected = "%s\n" % self.test_file diff --git a/neutron/tests/unit/test_api_v2.py b/neutron/tests/unit/test_api_v2.py index 34bcaa54f..23441f0a3 100644 --- a/neutron/tests/unit/test_api_v2.py +++ b/neutron/tests/unit/test_api_v2.py @@ -113,7 +113,6 @@ class APIv2TestBase(base.BaseTestCase): instance = self.plugin.return_value instance._NeutronPluginBaseV2__native_pagination_support = True instance._NeutronPluginBaseV2__native_sorting_support = True - self.addCleanup(self._plugin_patcher.stop) api = router.APIRouter() self.api = webtest.TestApp(api) @@ -1143,7 +1142,6 @@ class SubresourceTest(base.BaseTestCase): self._plugin_patcher = mock.patch(plugin, autospec=True) self.plugin = self._plugin_patcher.start() - self.addCleanup(self._plugin_patcher.stop) router.SUB_RESOURCES['dummy'] = { 'collection_name': 'dummies', @@ -1434,7 +1432,6 @@ class ExtensionTestCase(base.BaseTestCase): def tearDown(self): super(ExtensionTestCase, self).tearDown() - self._plugin_patcher.stop() self.api = None self.plugin = None # Restore the global RESOURCE_ATTRIBUTE_MAP diff --git a/neutron/tests/unit/test_db_migration.py b/neutron/tests/unit/test_db_migration.py index 2cd489a1e..20f979648 100644 --- a/neutron/tests/unit/test_db_migration.py +++ b/neutron/tests/unit/test_db_migration.py @@ -42,7 +42,6 @@ class TestCli(base.BaseTestCase): self.do_alembic_cmd = self.do_alembic_cmd_p.start() self.mock_alembic_err = mock.patch('alembic.util.err').start() self.mock_alembic_err.side_effect = SystemExit - self.addCleanup(self.do_alembic_cmd_p.stop) def _main_test_helper(self, argv, func_name, exp_args=(), exp_kwargs={}): with mock.patch.object(sys, 'argv', argv): diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index 436928020..d6bf0c090 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -993,20 +993,17 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s 'neutron.api.v2.base.Controller._get_sorting_helper', new=_fake_get_sorting_helper) helper_patcher.start() - try: - cfg.CONF.set_default('allow_overlapping_ips', True) - with contextlib.nested(self.port(admin_state_up='True', - mac_address='00:00:00:00:00:01'), - self.port(admin_state_up='False', - mac_address='00:00:00:00:00:02'), - self.port(admin_state_up='False', - mac_address='00:00:00:00:00:03') - ) as (port1, port2, port3): - self._test_list_with_sort('port', (port3, port2, port1), - [('admin_state_up', 'asc'), - ('mac_address', 'desc')]) - finally: - helper_patcher.stop() + cfg.CONF.set_default('allow_overlapping_ips', True) + with contextlib.nested(self.port(admin_state_up='True', + mac_address='00:00:00:00:00:01'), + self.port(admin_state_up='False', + mac_address='00:00:00:00:00:02'), + self.port(admin_state_up='False', + mac_address='00:00:00:00:00:03') + ) as (port1, port2, port3): + self._test_list_with_sort('port', (port3, port2, port1), + [('admin_state_up', 'asc'), + ('mac_address', 'desc')]) def test_list_ports_with_pagination_native(self): if self._skip_native_pagination: @@ -1025,17 +1022,14 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s 'neutron.api.v2.base.Controller._get_pagination_helper', new=_fake_get_pagination_helper) helper_patcher.start() - try: - cfg.CONF.set_default('allow_overlapping_ips', True) - with contextlib.nested(self.port(mac_address='00:00:00:00:00:01'), - self.port(mac_address='00:00:00:00:00:02'), - self.port(mac_address='00:00:00:00:00:03') - ) as (port1, port2, port3): - self._test_list_with_pagination('port', - (port1, port2, port3), - ('mac_address', 'asc'), 2, 2) - finally: - helper_patcher.stop() + cfg.CONF.set_default('allow_overlapping_ips', True) + with contextlib.nested(self.port(mac_address='00:00:00:00:00:01'), + self.port(mac_address='00:00:00:00:00:02'), + self.port(mac_address='00:00:00:00:00:03') + ) as (port1, port2, port3): + self._test_list_with_pagination('port', + (port1, port2, port3), + ('mac_address', 'asc'), 2, 2) def test_list_ports_with_pagination_reverse_native(self): if self._skip_native_pagination: @@ -1055,18 +1049,15 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s 'neutron.api.v2.base.Controller._get_pagination_helper', new=_fake_get_pagination_helper) helper_patcher.start() - try: - cfg.CONF.set_default('allow_overlapping_ips', True) - with contextlib.nested(self.port(mac_address='00:00:00:00:00:01'), - self.port(mac_address='00:00:00:00:00:02'), - self.port(mac_address='00:00:00:00:00:03') - ) as (port1, port2, port3): - self._test_list_with_pagination_reverse('port', - (port1, port2, port3), - ('mac_address', 'asc'), - 2, 2) - finally: - helper_patcher.stop() + cfg.CONF.set_default('allow_overlapping_ips', True) + with contextlib.nested(self.port(mac_address='00:00:00:00:00:01'), + self.port(mac_address='00:00:00:00:00:02'), + self.port(mac_address='00:00:00:00:00:03') + ) as (port1, port2, port3): + self._test_list_with_pagination_reverse('port', + (port1, port2, port3), + ('mac_address', 'asc'), + 2, 2) def test_show_port(self): with self.port() as port: @@ -2074,19 +2065,16 @@ class TestNetworksV2(NeutronDbPluginV2TestCase): 'neutron.api.v2.base.Controller._get_sorting_helper', new=_fake_get_sorting_helper) helper_patcher.start() - try: - with contextlib.nested(self.network(admin_status_up=True, - name='net1'), - self.network(admin_status_up=False, - name='net2'), - self.network(admin_status_up=False, - name='net3') - ) as (net1, net2, net3): - self._test_list_with_sort('network', (net3, net2, net1), - [('admin_state_up', 'asc'), - ('name', 'desc')]) - finally: - helper_patcher.stop() + with contextlib.nested(self.network(admin_status_up=True, + name='net1'), + self.network(admin_status_up=False, + name='net2'), + self.network(admin_status_up=False, + name='net3') + ) as (net1, net2, net3): + self._test_list_with_sort('network', (net3, net2, net1), + [('admin_state_up', 'asc'), + ('name', 'desc')]) def test_list_networks_with_pagination_native(self): if self._skip_native_pagination: @@ -2104,37 +2092,31 @@ class TestNetworksV2(NeutronDbPluginV2TestCase): 'neutron.api.v2.base.Controller._get_pagination_helper', new=_fake_get_pagination_helper) helper_patcher.start() - try: - with contextlib.nested(self.network(name='net1'), - self.network(name='net2'), - self.network(name='net3') - ) as (net1, net2, net3): - self._test_list_with_pagination('network', - (net1, net2, net3), - ('name', 'asc'), 2, 2) - finally: - helper_patcher.stop() + with contextlib.nested(self.network(name='net1'), + self.network(name='net2'), + self.network(name='net3') + ) as (net1, net2, net3): + self._test_list_with_pagination('network', + (net1, net2, net3), + ('name', 'asc'), 2, 2) def test_list_networks_without_pk_in_fields_pagination_emulated(self): helper_patcher = mock.patch( 'neutron.api.v2.base.Controller._get_pagination_helper', new=_fake_get_pagination_helper) helper_patcher.start() - try: - with contextlib.nested(self.network(name='net1', - shared=True), - self.network(name='net2', - shared=False), - self.network(name='net3', - shared=True) - ) as (net1, net2, net3): - self._test_list_with_pagination('network', - (net1, net2, net3), - ('name', 'asc'), 2, 2, - query_params="fields=name", - verify_key='name') - finally: - helper_patcher.stop() + with contextlib.nested(self.network(name='net1', + shared=True), + self.network(name='net2', + shared=False), + self.network(name='net3', + shared=True) + ) as (net1, net2, net3): + self._test_list_with_pagination('network', + (net1, net2, net3), + ('name', 'asc'), 2, 2, + query_params="fields=name", + verify_key='name') def test_list_networks_without_pk_in_fields_pagination_native(self): if self._skip_native_pagination: @@ -2165,16 +2147,13 @@ class TestNetworksV2(NeutronDbPluginV2TestCase): 'neutron.api.v2.base.Controller._get_pagination_helper', new=_fake_get_pagination_helper) helper_patcher.start() - try: - with contextlib.nested(self.network(name='net1'), - self.network(name='net2'), - self.network(name='net3') - ) as (net1, net2, net3): - self._test_list_with_pagination_reverse('network', - (net1, net2, net3), - ('name', 'asc'), 2, 2) - finally: - helper_patcher.stop() + with contextlib.nested(self.network(name='net1'), + self.network(name='net2'), + self.network(name='net3') + ) as (net1, net2, net3): + self._test_list_with_pagination_reverse('network', + (net1, net2, net3), + ('name', 'asc'), 2, 2) def test_list_networks_with_parameters(self): with contextlib.nested(self.network(name='net1', @@ -3360,21 +3339,18 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'neutron.api.v2.base.Controller._get_sorting_helper', new=_fake_get_sorting_helper) helper_patcher.start() - try: - with contextlib.nested(self.subnet(enable_dhcp=True, - cidr='10.0.0.0/24'), - self.subnet(enable_dhcp=False, - cidr='11.0.0.0/24'), - self.subnet(enable_dhcp=False, - cidr='12.0.0.0/24') - ) as (subnet1, subnet2, subnet3): - self._test_list_with_sort('subnet', (subnet3, - subnet2, - subnet1), - [('enable_dhcp', 'asc'), - ('cidr', 'desc')]) - finally: - helper_patcher.stop() + with contextlib.nested(self.subnet(enable_dhcp=True, + cidr='10.0.0.0/24'), + self.subnet(enable_dhcp=False, + cidr='11.0.0.0/24'), + self.subnet(enable_dhcp=False, + cidr='12.0.0.0/24') + ) as (subnet1, subnet2, subnet3): + self._test_list_with_sort('subnet', (subnet3, + subnet2, + subnet1), + [('enable_dhcp', 'asc'), + ('cidr', 'desc')]) def test_list_subnets_with_pagination_native(self): if self._skip_native_pagination: @@ -3392,16 +3368,13 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'neutron.api.v2.base.Controller._get_pagination_helper', new=_fake_get_pagination_helper) helper_patcher.start() - try: - with contextlib.nested(self.subnet(cidr='10.0.0.0/24'), - self.subnet(cidr='11.0.0.0/24'), - self.subnet(cidr='12.0.0.0/24') - ) as (subnet1, subnet2, subnet3): - self._test_list_with_pagination('subnet', - (subnet1, subnet2, subnet3), - ('cidr', 'asc'), 2, 2) - finally: - helper_patcher.stop() + with contextlib.nested(self.subnet(cidr='10.0.0.0/24'), + self.subnet(cidr='11.0.0.0/24'), + self.subnet(cidr='12.0.0.0/24') + ) as (subnet1, subnet2, subnet3): + self._test_list_with_pagination('subnet', + (subnet1, subnet2, subnet3), + ('cidr', 'asc'), 2, 2) def test_list_subnets_with_pagination_reverse_native(self): if self._skip_native_sorting: @@ -3420,17 +3393,14 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'neutron.api.v2.base.Controller._get_pagination_helper', new=_fake_get_pagination_helper) helper_patcher.start() - try: - with contextlib.nested(self.subnet(cidr='10.0.0.0/24'), - self.subnet(cidr='11.0.0.0/24'), - self.subnet(cidr='12.0.0.0/24') - ) as (subnet1, subnet2, subnet3): - self._test_list_with_pagination_reverse('subnet', - (subnet1, subnet2, - subnet3), - ('cidr', 'asc'), 2, 2) - finally: - helper_patcher.stop() + with contextlib.nested(self.subnet(cidr='10.0.0.0/24'), + self.subnet(cidr='11.0.0.0/24'), + self.subnet(cidr='12.0.0.0/24') + ) as (subnet1, subnet2, subnet3): + self._test_list_with_pagination_reverse('subnet', + (subnet1, subnet2, + subnet3), + ('cidr', 'asc'), 2, 2) def test_invalid_ip_version(self): with self.network() as network: diff --git a/neutron/tests/unit/test_dhcp_agent.py b/neutron/tests/unit/test_dhcp_agent.py index 21b01e4f9..61b63d4b2 100644 --- a/neutron/tests/unit/test_dhcp_agent.py +++ b/neutron/tests/unit/test_dhcp_agent.py @@ -488,15 +488,6 @@ class TestDhcpAgentEventHandler(base.BaseTestCase): ) self.external_process = self.external_process_p.start() - def tearDown(self): - self.external_process_p.stop() - self.call_driver_p.stop() - self.cache_p.stop() - self.plugin_p.stop() - self.mock_makedirs_p.stop() - self.mock_init_p.stop() - super(TestDhcpAgentEventHandler, self).tearDown() - def _enable_dhcp_helper(self, isolated_metadata=False): if isolated_metadata: cfg.CONF.set_override('enable_isolated_metadata', True) @@ -849,11 +840,6 @@ class TestDhcpPluginApiProxy(base.BaseTestCase): self.make_msg_p = mock.patch.object(self.proxy, 'make_msg') self.make_msg = self.make_msg_p.start() - def tearDown(self): - self.make_msg_p.stop() - self.call_p.stop() - super(TestDhcpPluginApiProxy, self).tearDown() - def test_get_network_info(self): self.call.return_value = dict(a=1) retval = self.proxy.get_network_info('netid') @@ -1118,12 +1104,6 @@ class TestDeviceManager(base.BaseTestCase): driver_cls.return_value = self.mock_driver iproute_cls.return_value = self.mock_iproute - def tearDown(self): - self.dvr_cls_p.stop() - self.device_exists_p.stop() - self.iproute_cls_p.stop() - super(TestDeviceManager, self).tearDown() - def _test_setup_helper(self, device_exists, net=None, port=None): net = net or fake_network port = port or fake_port1 diff --git a/neutron/tests/unit/test_extension_ext_gw_mode.py b/neutron/tests/unit/test_extension_ext_gw_mode.py index 4e1aa9d5e..cabb1428e 100644 --- a/neutron/tests/unit/test_extension_ext_gw_mode.py +++ b/neutron/tests/unit/test_extension_ext_gw_mode.py @@ -85,7 +85,6 @@ class TestL3GwModeMixin(base.BaseTestCase): ctx_patcher = mock.patch('neutron.context', autospec=True) mock_context = ctx_patcher.start() self.addCleanup(db_api.clear_db) - self.addCleanup(ctx_patcher.stop) self.context = mock_context.get_admin_context() # This ensure also calls to elevated work in unit tests self.context.elevated.return_value = self.context diff --git a/neutron/tests/unit/test_iptables_firewall.py b/neutron/tests/unit/test_iptables_firewall.py index c1451fb31..ff2b8106f 100644 --- a/neutron/tests/unit/test_iptables_firewall.py +++ b/neutron/tests/unit/test_iptables_firewall.py @@ -42,11 +42,9 @@ class IptablesFirewallTestCase(base.BaseTestCase): self.utils_exec_p = mock.patch( 'neutron.agent.linux.utils.execute') self.utils_exec = self.utils_exec_p.start() - self.addCleanup(self.utils_exec_p.stop) self.iptables_cls_p = mock.patch( 'neutron.agent.linux.iptables_manager.IptablesManager') iptables_cls = self.iptables_cls_p.start() - self.addCleanup(self.iptables_cls_p.stop) self.iptables_inst = mock.Mock() self.v4filter_inst = mock.Mock() self.v6filter_inst = mock.Mock() diff --git a/neutron/tests/unit/test_linux_daemon.py b/neutron/tests/unit/test_linux_daemon.py index 9c40c7b82..12e7d9f35 100644 --- a/neutron/tests/unit/test_linux_daemon.py +++ b/neutron/tests/unit/test_linux_daemon.py @@ -1,4 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 # # Copyright 2012 New Dream Network, LLC (DreamHost) # @@ -33,12 +32,10 @@ class TestPidfile(base.BaseTestCase): super(TestPidfile, self).setUp() self.os_p = mock.patch.object(daemon, 'os') self.os = self.os_p.start() - self.addCleanup(self.os_p.stop) self.os.open.return_value = FAKE_FD self.fcntl_p = mock.patch.object(daemon, 'fcntl') self.fcntl = self.fcntl_p.start() - self.addCleanup(self.fcntl_p.stop) self.fcntl.flock.return_value = 0 def test_init(self): @@ -132,11 +129,6 @@ class TestDaemon(base.BaseTestCase): self.pidfile_p = mock.patch.object(daemon, 'Pidfile') self.pidfile = self.pidfile_p.start() - def tearDown(self): - self.pidfile_p.stop() - self.os_p.stop() - super(TestDaemon, self).tearDown() - def test_init(self): d = daemon.Daemon('pidfile') self.assertEqual(d.procname, 'python') diff --git a/neutron/tests/unit/test_linux_external_process.py b/neutron/tests/unit/test_linux_external_process.py index 36146a2ba..9207e5df0 100644 --- a/neutron/tests/unit/test_linux_external_process.py +++ b/neutron/tests/unit/test_linux_external_process.py @@ -27,7 +27,6 @@ class TestProcessManager(base.BaseTestCase): super(TestProcessManager, self).setUp() self.execute_p = mock.patch('neutron.agent.linux.utils.execute') self.execute = self.execute_p.start() - self.addCleanup(self.execute_p.stop) self.conf = mock.Mock() self.conf.external_pids = '/var/path' diff --git a/neutron/tests/unit/test_linux_interface.py b/neutron/tests/unit/test_linux_interface.py index 81a6cc0ae..9d278ea51 100644 --- a/neutron/tests/unit/test_linux_interface.py +++ b/neutron/tests/unit/test_linux_interface.py @@ -65,13 +65,10 @@ class TestBase(base.BaseTestCase): config.register_root_helper(self.conf) self.ip_dev_p = mock.patch.object(ip_lib, 'IPDevice') self.ip_dev = self.ip_dev_p.start() - self.addCleanup(self.ip_dev_p.stop) self.ip_p = mock.patch.object(ip_lib, 'IPWrapper') self.ip = self.ip_p.start() - self.addCleanup(self.ip_p.stop) self.device_exists_p = mock.patch.object(ip_lib, 'device_exists') self.device_exists = self.device_exists_p.start() - self.addCleanup(self.device_exists_p.stop) class TestABCDriver(TestBase): @@ -377,7 +374,6 @@ class TestMetaInterfaceDriver(TestBase): self.conf.register_opts(dhcp.OPTS) self.client_cls_p = mock.patch('neutronclient.v2_0.client.Client') client_cls = self.client_cls_p.start() - self.addCleanup(self.client_cls_p.stop) self.client_inst = mock.Mock() client_cls.return_value = self.client_inst diff --git a/neutron/tests/unit/test_linux_ip_lib.py b/neutron/tests/unit/test_linux_ip_lib.py index 7eb58ad7b..7d56c01b0 100644 --- a/neutron/tests/unit/test_linux_ip_lib.py +++ b/neutron/tests/unit/test_linux_ip_lib.py @@ -148,7 +148,6 @@ class TestSubProcessBase(base.BaseTestCase): super(TestSubProcessBase, self).setUp() self.execute_p = mock.patch('neutron.agent.linux.utils.execute') self.execute = self.execute_p.start() - self.addCleanup(self.execute_p.stop) def test_execute_wrapper(self): ip_lib.SubProcessBase._execute('o', 'link', ('list',), 'sudo') @@ -200,7 +199,6 @@ class TestIpWrapper(base.BaseTestCase): super(TestIpWrapper, self).setUp() self.execute_p = mock.patch.object(ip_lib.IPWrapper, '_execute') self.execute = self.execute_p.start() - self.addCleanup(self.execute_p.stop) def test_get_devices(self): self.execute.return_value = '\n'.join(LINK_SAMPLE) diff --git a/neutron/tests/unit/test_metadata_agent.py b/neutron/tests/unit/test_metadata_agent.py index 6f7f926ac..0e9236ccc 100644 --- a/neutron/tests/unit/test_metadata_agent.py +++ b/neutron/tests/unit/test_metadata_agent.py @@ -48,11 +48,9 @@ class TestMetadataProxyHandler(base.BaseTestCase): super(TestMetadataProxyHandler, self).setUp() self.qclient_p = mock.patch('neutronclient.v2_0.client.Client') self.qclient = self.qclient_p.start() - self.addCleanup(self.qclient_p.stop) self.log_p = mock.patch.object(agent, 'LOG') self.log = self.log_p.start() - self.addCleanup(self.log_p.stop) self.handler = agent.MetadataProxyHandler(FakeConf) @@ -279,7 +277,6 @@ class TestUnixDomainWSGIServer(base.BaseTestCase): super(TestUnixDomainWSGIServer, self).setUp() self.eventlet_p = mock.patch.object(agent, 'eventlet') self.eventlet = self.eventlet_p.start() - self.addCleanup(self.eventlet_p.stop) self.server = agent.UnixDomainWSGIServer('test') def test_start(self): diff --git a/neutron/tests/unit/test_metadata_namespace_proxy.py b/neutron/tests/unit/test_metadata_namespace_proxy.py index 26d7ba9df..8aafc33a4 100644 --- a/neutron/tests/unit/test_metadata_namespace_proxy.py +++ b/neutron/tests/unit/test_metadata_namespace_proxy.py @@ -62,7 +62,6 @@ class TestNetworkMetadataProxyHandler(base.BaseTestCase): super(TestNetworkMetadataProxyHandler, self).setUp() self.log_p = mock.patch.object(ns_proxy, 'LOG') self.log = self.log_p.start() - self.addCleanup(self.log_p.stop) self.handler = ns_proxy.NetworkMetadataProxyHandler('router_id') diff --git a/neutron/tests/unit/test_neutron_context.py b/neutron/tests/unit/test_neutron_context.py index 937e29666..ebf30b72c 100644 --- a/neutron/tests/unit/test_neutron_context.py +++ b/neutron/tests/unit/test_neutron_context.py @@ -28,7 +28,6 @@ class TestNeutronContext(base.BaseTestCase): db_api = 'neutron.db.api.get_session' self._db_api_session_patcher = mock.patch(db_api) self.db_api_session = self._db_api_session_patcher.start() - self.addCleanup(self._db_api_session_patcher.stop) def test_neutron_context_create(self): ctx = context.Context('user_id', 'tenant_id') diff --git a/neutron/tests/unit/test_policy.py b/neutron/tests/unit/test_policy.py index 7c4997630..22193b5af 100644 --- a/neutron/tests/unit/test_policy.py +++ b/neutron/tests/unit/test_policy.py @@ -270,7 +270,6 @@ class NeutronPolicyTestCase(base.BaseTestCase): 'init', new=fakepolicyinit) self.patcher.start() - self.addCleanup(self.patcher.stop) self.addCleanup(remove_fake_resource) self.context = context.Context('fake', 'fake', roles=['user']) plugin_klass = importutils.import_class( @@ -279,7 +278,6 @@ class NeutronPolicyTestCase(base.BaseTestCase): fake_manager = self.manager_patcher.start() fake_manager_instance = fake_manager.return_value fake_manager_instance.plugin = plugin_klass() - self.addCleanup(self.manager_patcher.stop) def _test_action_on_attr(self, context, action, attr, value, exception=None): diff --git a/neutron/tests/unit/test_quota_ext.py b/neutron/tests/unit/test_quota_ext.py index 0d88d9371..cf11ecb65 100644 --- a/neutron/tests/unit/test_quota_ext.py +++ b/neutron/tests/unit/test_quota_ext.py @@ -78,7 +78,6 @@ class QuotaExtensionTestCase(testlib_api.WebTestCase): self.api = webtest.TestApp(ext_middleware) def tearDown(self): - self._plugin_patcher.stop() self.api = None self.plugin = None db.clear_db() diff --git a/neutron/tests/unit/vmware/extensions/test_networkgw.py b/neutron/tests/unit/vmware/extensions/test_networkgw.py index ae9ccfcf2..e437377f3 100644 --- a/neutron/tests/unit/vmware/extensions/test_networkgw.py +++ b/neutron/tests/unit/vmware/extensions/test_networkgw.py @@ -85,7 +85,6 @@ class NetworkGatewayExtensionTestCase(base.BaseTestCase): _plugin_patcher = mock.patch(plugin, autospec=True) self.plugin = _plugin_patcher.start() - self.addCleanup(_plugin_patcher.stop) # Instantiate mock plugin and enable extensions manager.NeutronManager.get_plugin().supported_extension_aliases = ( diff --git a/neutron/tests/unit/vmware/nsxlib/base.py b/neutron/tests/unit/vmware/nsxlib/base.py index 2d4fedcb5..16281b5ee 100644 --- a/neutron/tests/unit/vmware/nsxlib/base.py +++ b/neutron/tests/unit/vmware/nsxlib/base.py @@ -53,7 +53,6 @@ class NsxlibTestCase(base.BaseTestCase): super(NsxlibTestCase, self).setUp() self.addCleanup(self.fc.reset_all) - self.addCleanup(self.mock_nsxapi.stop) def _build_tag_dict(self, tags): # This syntax is needed for python 2.6 compatibility @@ -88,4 +87,3 @@ class NsxlibNegativeBaseTestCase(base.BaseTestCase): super(NsxlibNegativeBaseTestCase, self).setUp() self.addCleanup(self.fc.reset_all) - self.addCleanup(self.mock_nsxapi.stop) diff --git a/neutron/tests/unit/vmware/nsxlib/test_lsn.py b/neutron/tests/unit/vmware/nsxlib/test_lsn.py index 953754928..e29afdf10 100644 --- a/neutron/tests/unit/vmware/nsxlib/test_lsn.py +++ b/neutron/tests/unit/vmware/nsxlib/test_lsn.py @@ -32,7 +32,6 @@ class LSNTestCase(base.BaseTestCase): self.mock_request = self.mock_request_p.start() self.cluster = mock.Mock() self.cluster.default_service_cluster_uuid = 'foo' - self.addCleanup(self.mock_request_p.stop) def test_service_cluster_None(self): self.mock_request.return_value = None diff --git a/neutron/tests/unit/vmware/test_dhcpmeta.py b/neutron/tests/unit/vmware/test_dhcpmeta.py index 5b737bde9..40bf06fbc 100644 --- a/neutron/tests/unit/vmware/test_dhcpmeta.py +++ b/neutron/tests/unit/vmware/test_dhcpmeta.py @@ -116,7 +116,6 @@ class MigrationManagerTestCase(base.BaseTestCase): self.subnet_id = 'foo_subnet_id' self.mock_builder_p = mock.patch.object(self.manager, 'builder') self.mock_builder = self.mock_builder_p.start() - self.addCleanup(self.mock_builder_p.stop) def _test_validate(self, lsn_exists=False, ext_net=False, subnets=None): network = {'router:external': ext_net} @@ -268,7 +267,6 @@ class LsnManagerTestCase(base.BaseTestCase): self.mock_lsn_api = self.mock_lsn_api_p.start() nsx.register_dhcp_opts(cfg) nsx.register_metadata_opts(cfg) - self.addCleanup(self.mock_lsn_api_p.stop) def test_lsn_get(self): self.mock_lsn_api.lsn_for_network_get.return_value = self.lsn_id @@ -702,7 +700,6 @@ class PersistentLsnManagerTestCase(base.BaseTestCase): self.context = context.get_admin_context() self.mock_lsn_api_p = mock.patch.object(lsn_man, 'lsn_api') self.mock_lsn_api = self.mock_lsn_api_p.start() - self.addCleanup(self.mock_lsn_api_p.stop) self.addCleanup(db.clear_db) def test_lsn_get(self): diff --git a/neutron/tests/unit/vmware/test_nsx_opts.py b/neutron/tests/unit/vmware/test_nsx_opts.py index 99b6366a9..9a18fcb78 100644 --- a/neutron/tests/unit/vmware/test_nsx_opts.py +++ b/neutron/tests/unit/vmware/test_nsx_opts.py @@ -82,7 +82,6 @@ class ConfigurationTest(base.BaseTestCase): # Avoid runs of the synchronizer looping call patch_sync = mock.patch.object(sync, '_start_loopingcall') patch_sync.start() - self.addCleanup(patch_sync.stop) def _assert_required_options(self, cluster): self.assertEqual(cluster.nsx_controllers, ['fake_1:443', 'fake_2:443']) @@ -211,7 +210,6 @@ class OldNVPConfigurationTest(base.BaseTestCase): # Avoid runs of the synchronizer looping call patch_sync = mock.patch.object(sync, '_start_loopingcall') patch_sync.start() - self.addCleanup(patch_sync.stop) def _assert_required_options(self, cluster): self.assertEqual(cluster.nsx_controllers, ['fake_1:443', 'fake_2:443']) diff --git a/neutron/tests/unit/vmware/test_nsx_sync.py b/neutron/tests/unit/vmware/test_nsx_sync.py index 6fbb5d7da..579317053 100644 --- a/neutron/tests/unit/vmware/test_nsx_sync.py +++ b/neutron/tests/unit/vmware/test_nsx_sync.py @@ -298,10 +298,6 @@ class SyncTestCase(base.BaseTestCase): mock_nm_get_service_plugins.start() super(SyncTestCase, self).setUp() self.addCleanup(self.fc.reset_all) - self.addCleanup(patch_sync.stop) - self.addCleanup(mock_api.stop) - self.addCleanup(mock_nm_get_plugin.stop) - self.addCleanup(mock_nm_get_service_plugins.stop) @contextlib.contextmanager def _populate_data(self, ctx, net_size=2, port_size=2, router_size=2): diff --git a/neutron/tests/unit/vmware/vshield/test_vcns_driver.py b/neutron/tests/unit/vmware/vshield/test_vcns_driver.py index e49cd2d6c..65ece2b39 100644 --- a/neutron/tests/unit/vmware/vshield/test_vcns_driver.py +++ b/neutron/tests/unit/vmware/vshield/test_vcns_driver.py @@ -322,7 +322,6 @@ class VcnsDriverTestCase(base.BaseTestCase): self.vcns_patch() self.addCleanup(self.fc.reset_all) - self.addCleanup(self.mock_vcns.stop) self.vcns_driver = vcns_driver.VcnsDriver(self) -- 2.45.2