Merge "Avoid writing segments to the DB repeatedly" into stable/victoria

This commit is contained in:
Zuul 2021-12-20 19:54:04 +00:00 committed by Gerrit Code Review
commit 6b62c26432
3 changed files with 10 additions and 3 deletions

View File

@ -397,6 +397,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
agent = self._get_agent_by_type_and_host(
context, agent_state['agent_type'], agent_state['host'])
agent_state_orig = copy.deepcopy(agent_state)
agent_state_previous = copy.deepcopy(agent)
if not agent.is_active:
status = agent_consts.AGENT_REVIVED
if 'resource_versions' not in agent_state:
@ -417,6 +418,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
event_type = events.AFTER_UPDATE
except agent_exc.AgentNotFoundByTypeHost:
agent_state_orig = None
agent_state_previous = None
greenthread.sleep(0)
res['created_at'] = current_time
res['started_at'] = current_time
@ -441,7 +443,7 @@ class AgentDbMixin(ext_agent.AgentPluginBase, AgentAvailabilityZoneMixin):
'plugin': self,
'status': status
},
states=(agent_state_orig, ),
states=(agent_state_orig, agent_state_previous),
desired_state=agent_state,
resource_id=agent.id
))

View File

@ -298,6 +298,11 @@ def _update_segment_host_mapping_for_agent(resource, event, trigger,
if host in reported_hosts and not start_flag:
return
reported_hosts.add(host)
if (len(payload.states) > 1 and
payload.states[1] is not None and
agent.get('configurations') == payload.states[1].get(
'configurations')):
return
segments = get_segments_with_phys_nets(context, phys_nets)
current_segment_ids = {
segment['id'] for segment in segments

View File

@ -947,9 +947,9 @@ class TestMl2HostSegmentMappingAgentServerSynch(HostSegmentMappingTestCase):
self._register_agent(host, mappings={physical_network: 'br-eth-1'},
plugin=self.plugin, start_flag=True)
self.assertIn(host, db.reported_hosts)
self.assertEqual(2, mock_function.call_count)
self.assertEqual(1, mock_function.call_count)
expected_call = mock.call(mock.ANY, host, set())
mock_function.assert_has_calls([expected_call, expected_call])
mock_function.assert_has_calls([expected_call])
@mock.patch(mock_path)
def test_no_starting_agent_is_not_processed(self, mock_function):