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
(cherry picked from commit df2c7baa23
)
This commit is contained in:
parent
3ca5b3a5de
commit
baf54722e4
|
@ -430,6 +430,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
|
||||||
|
|
||||||
agent_state['agent_status'] = status
|
agent_state['agent_status'] = status
|
||||||
agent_state['admin_state_up'] = agent.admin_state_up
|
agent_state['admin_state_up'] = agent.admin_state_up
|
||||||
|
agent_state['id'] = agent.id
|
||||||
registry.publish(resources.AGENT, event_type, self,
|
registry.publish(resources.AGENT, event_type, self,
|
||||||
payload=events.DBEventPayload(
|
payload=events.DBEventPayload(
|
||||||
context=context, metadata={
|
context=context, metadata={
|
||||||
|
|
|
@ -749,19 +749,18 @@ class TestAgentApi(base.TestOVNFunctionalBase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
self.host = 'test-host'
|
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
|
self.plugin = self.mech_driver._plugin
|
||||||
agent = {'agent_type': 'test', 'binary': '/bin/test',
|
agent = {'agent_type': 'test', 'binary': '/bin/test',
|
||||||
'host': self.host, 'topic': 'test_topic'}
|
'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',
|
mock.patch.object(self.mech_driver, 'ping_all_chassis',
|
||||||
return_value=False).start()
|
return_value=False).start()
|
||||||
|
|
||||||
def get_agent(self, agent_type):
|
def test_agent_show_non_ovn(self):
|
||||||
return next(iter(self.plugin.get_agents(
|
self.assertTrue(self.plugin.get_agent(self.context, self.test_agent))
|
||||||
self.context, filters={'agent_type': agent_type})))
|
|
||||||
|
|
||||||
def test_agent_show(self):
|
def test_agent_show_ovn_controller(self):
|
||||||
for agent_type in ('test', ovn_const.OVN_CONTROLLER_AGENT):
|
self.assertTrue(self.plugin.get_agent(self.context,
|
||||||
agent = self.get_agent(agent_type)
|
self.controller_agent))
|
||||||
self.assertTrue(self.plugin.get_agent(self.context, agent['id']))
|
|
||||||
|
|
Loading…
Reference in New Issue