From f06268a8ffb5a0cb3d234c7c13a6808b9cce8263 Mon Sep 17 00:00:00 2001 From: Terry Wilson Date: Mon, 8 Feb 2021 18:40:36 +0000 Subject: [PATCH] Don't update AgentCache when Chassis_Private.chassis == [] When we delete a Chassis object when deleting an agent, the corresponding value in Chassis_Private.chassis is automatically set to []. Even though we use frozen rows, since we listen for updates to Chassis_Private, we will replace the row in the AgentCache with this new "chassis-less" entry, which will break things since Chassis_Private.chassis is used to display information which is only stored there like 'hostname'. This patch avoids updating the AgentCache when Chassis_Private has an empty Chassis field. Related-Bug: #1914757 Change-Id: Iad01db7f33d6c61b29c552d2dc8893e2946a369a --- .../drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py index ac6925243b2..158f5c84299 100644 --- a/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py +++ b/neutron/plugins/ml2/drivers/ovn/mech_driver/ovsdb/ovsdb_monitor.py @@ -265,7 +265,12 @@ class ChassisAgentWriteEvent(ChassisAgentEvent): events = (BaseEvent.ROW_CREATE, BaseEvent.ROW_UPDATE) def match_fn(self, event, row, old=None): - return event == self.ROW_CREATE or getattr(old, 'nb_cfg', False) + # On updates to Chassis_Private because the Chassis has been deleted, + # don't update the AgentCache. We use chassis_private.chassis to return + # data about the agent. + return event == self.ROW_CREATE or ( + getattr(old, 'nb_cfg', False) and not + (self.table == 'Chassis_Private' and not row.chassis)) def run(self, event, row, old): n_agent.AgentCache().update(ovn_const.OVN_CONTROLLER_AGENT, row, @@ -291,6 +296,11 @@ class ChassisMetadataAgentWriteEvent(ChassisAgentEvent): if event == self.ROW_CREATE: return True try: + # On updates to Chassis_Private because the Chassis has been + # deleted, don't update the AgentCache. We use + # chassis_private.chassis to return data about the agent. + if self.table == 'Chassis_Private' and not row.chassis: + return False return self._metadata_nb_cfg(row) != self._metadata_nb_cfg(old) except (AttributeError, KeyError): return False