Replace tearDown with addCleanup.

All setUp and tearDown methods must upcall using the super()
method.tearDown methods should be avoided and addCleanup calls
should be preferred[1].

[1] https://github.com/openstack/neutron/blob/master/HACKING.rst

Change-Id: Idef345a44cc9f926c61af342729736d1f9245036
This commit is contained in:
maliangyi 2022-03-18 16:28:44 +08:00 committed by Liangyi Ma
parent 3a5dde69e7
commit de8a4d4cfb
5 changed files with 7 additions and 22 deletions

View File

@ -263,6 +263,7 @@ class TestOVSFirewallDriver(base.BaseTestCase):
self._mock_ovs_br = mock.patch.object(
ovs_lib, 'OVSBridge', autospec=True)
mock_bridge = self._mock_ovs_br.start()
self.addCleanup(self._mock_ovs_br.stop)
mock_agent_api = mock.patch.object(
ovs_ext_api.OVSAgentExtensionAPI, 'request_int_br',
return_value=mock_bridge).start()
@ -273,10 +274,6 @@ class TestOVSFirewallDriver(base.BaseTestCase):
self.mock_bridge.br.get_vif_port_by_id.return_value = \
self.fake_ovs_port
def tearDown(self):
self._mock_ovs_br.stop()
super(TestOVSFirewallDriver, self).tearDown()
def _prepare_firewall_group(self):
ingress_rules = [
{'position': '1',

View File

@ -61,10 +61,7 @@ class TestCreateFlowsFromRuleAndPort(base.BaseTestCase):
self._mock_create_flows = mock.patch.object(
rules, 'create_protocol_flows')
self.create_flows_mock = self._mock_create_flows.start()
def tearDown(self):
self._mock_create_flows.stop()
super(TestCreateFlowsFromRuleAndPort, self).tearDown()
self.addCleanup(self._mock_create_flows.stop)
@property
def passed_flow_template(self):

View File

@ -47,6 +47,7 @@ class TestFWaasV2AgentExtensionBase(base.BaseTestCase):
self._driver_mock = mock.patch(
'neutron.manager.NeutronManager.load_class_for_provider')
self.driver = self._driver_mock.start()
self.addCleanup(self._driver_mock.stop)
self.l2.initialize(None, 'ovs')
self.l2.vlan_manager = mock.Mock()
self.conf = cfg.ConfigOpts()
@ -54,10 +55,6 @@ class TestFWaasV2AgentExtensionBase(base.BaseTestCase):
self.l2.conf.host = self.host
self.rpc = self.l2.plugin_rpc
def tearDown(self):
self._driver_mock.stop()
super(TestFWaasV2AgentExtensionBase, self).tearDown()
class TestFWaasV2AgentExtension(TestFWaasV2AgentExtensionBase):

View File

@ -97,8 +97,10 @@ class TestAgentDriver(test_fwaas_plugin_v2.FirewallPluginV2TestCase,
new=FakeAgentApi().delete_firewall_group,
)
self.agentapi_del_fw_p = self._mock_agentapi_del_fw_p.start()
self.addCleanup(self._mock_agentapi_del_fw_p.stop)
self._mock_get_client = mock.patch.object(agents.n_rpc, 'get_client')
self._mock_get_client.start()
self.addCleanup(self._mock_get_client.stop)
mock.patch.object(agents.n_rpc, 'Connection').start()
l3_plugin_str = ('neutron.tests.unit.extensions.test_l3.'
@ -121,11 +123,6 @@ class TestAgentDriver(test_fwaas_plugin_v2.FirewallPluginV2TestCase,
]
cfg.CONF.register_opts(router_distributed_opts)
def tearDown(self):
self._mock_get_client.stop()
self._mock_agentapi_del_fw_p.stop()
super(TestAgentDriver, self).tearDown()
@property
def _self_context(self):
return context.Context('', self._tenant_id)

View File

@ -34,6 +34,7 @@ class FireWallDriverDBMixinTestCase(test_fwaas_plugin_v2.
self._mp_registry_publish = mock.patch(
'neutron_lib.callbacks.registry.publish')
self.mock_registry_publish = self._mp_registry_publish.start()
self.addCleanup(self._mp_registry_publish.stop)
self.driver_api = self.plugin.driver
self.ctx = context.get_admin_context()
self.firewall_db = self.plugin.driver.firewall_db
@ -41,6 +42,7 @@ class FireWallDriverDBMixinTestCase(test_fwaas_plugin_v2.
self._mock_payload = mock.patch(
'neutron_lib.callbacks.events.DBEventPayload')
m_db_event_payload = self._mock_payload.start()
self.addCleanup(self._mock_payload.stop)
m_db_event_payload.return_value = self.m_payload
self.fake_fwg = {
'id': 'fake_fwg_id',
@ -64,11 +66,6 @@ class FireWallDriverDBMixinTestCase(test_fwaas_plugin_v2.
'project_id': 'fake_project_id'
}
def tearDown(self):
self._mock_payload.stop()
self._mp_registry_publish.stop()
super(FireWallDriverDBMixinTestCase, self).tearDown()
# Test Firewall Group
def test_create_firewall_group(self):