From df2c7baa23b814ccd118fb69d16427b2bf59cecc Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Tue, 13 Oct 2020 15:52:06 +0000 Subject: [PATCH] Make test_agent_show only look for its own agents Since plugin agents are a global resource, relying just on the 'type' field for test_agent_show may end up finding an agent that we don't know about, and that agent could be deleted by another test. This reworks test_agent_show to sepecifically look for its own OVN controller agent and test agent. This also adds the 'id' field to the returned agent_status from create_or_update_agent() to make it possible to look for the agent that was just created. Change-Id: Ib840e7c51f7b918b5e17ce9deff9ceafacf063cc Closes-Bug: #1899004 --- neutron/db/agents_db.py | 1 + .../drivers/ovn/mech_driver/test_mech_driver.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/neutron/db/agents_db.py b/neutron/db/agents_db.py index ff39f8d21e1..c4766d4536b 100644 --- a/neutron/db/agents_db.py +++ b/neutron/db/agents_db.py @@ -430,6 +430,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin): agent_state['agent_status'] = status agent_state['admin_state_up'] = agent.admin_state_up + agent_state['id'] = agent.id registry.publish(resources.AGENT, event_type, self, payload=events.DBEventPayload( context=context, metadata={ diff --git a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py index f7135bb0a05..e50b013b7c7 100644 --- a/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py +++ b/neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py @@ -749,19 +749,18 @@ class TestAgentApi(base.TestOVNFunctionalBase): def setUp(self): super().setUp() self.host = 'test-host' - self.add_fake_chassis(self.host) + self.controller_agent = self.add_fake_chassis(self.host) self.plugin = self.mech_driver._plugin agent = {'agent_type': 'test', 'binary': '/bin/test', 'host': self.host, 'topic': 'test_topic'} - self.plugin.create_or_update_agent(self.context, agent) + _, status = self.plugin.create_or_update_agent(self.context, agent) + self.test_agent = status['id'] mock.patch.object(self.mech_driver, 'ping_all_chassis', return_value=False).start() - def get_agent(self, agent_type): - return next(iter(self.plugin.get_agents( - self.context, filters={'agent_type': agent_type}))) + def test_agent_show_non_ovn(self): + self.assertTrue(self.plugin.get_agent(self.context, self.test_agent)) - def test_agent_show(self): - for agent_type in ('test', ovn_const.OVN_CONTROLLER_AGENT): - agent = self.get_agent(agent_type) - self.assertTrue(self.plugin.get_agent(self.context, agent['id'])) + def test_agent_show_ovn_controller(self): + self.assertTrue(self.plugin.get_agent(self.context, + self.controller_agent))