From 95558d0bf5fe262a806077b35855c80556147e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Wed, 16 Sep 2020 21:27:07 -0300 Subject: [PATCH] Metering fix error that might happen when labels are removed during processing If a metering label is removed during a data collection and processing, and error might happen. This patch address such situations, and creates an execution flow that avoids such problems. Change-Id: Iba68173c304dccf97521dcec9a87fce67e21cec2 --- neutron/services/metering/agents/metering_agent.py | 11 +++++++++-- .../metering/drivers/iptables/iptables_driver.py | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/neutron/services/metering/agents/metering_agent.py b/neutron/services/metering/agents/metering_agent.py index eb3bd2e9712..bc3a0421c9c 100644 --- a/neutron/services/metering/agents/metering_agent.py +++ b/neutron/services/metering/agents/metering_agent.py @@ -134,10 +134,17 @@ class MeteringAgent(MeteringPluginRpc, manager.Manager): if driver.BASE_LABEL_TRAFFIC_COUNTER_KEY in key: other_ids, actual_label_id = key.split( driver.BASE_LABEL_TRAFFIC_COUNTER_KEY) - is_label_shared = self.metering_labels[actual_label_id]['shared'] + + is_label_shared = None + label_name = actual_label_id + + metering_label = self.metering_labels.get(actual_label_id) + if metering_label: + is_label_shared = metering_label['shared'] + label_name = metering_label['name'] data['label_id'] = actual_label_id - data['label_name'] = self.metering_labels[actual_label_id]['name'] + data['label_name'] = label_name data['label_shared'] = is_label_shared if is_label_shared: diff --git a/neutron/services/metering/drivers/iptables/iptables_driver.py b/neutron/services/metering/drivers/iptables/iptables_driver.py index 96e93f97f7d..faf4be0fcf8 100644 --- a/neutron/services/metering/drivers/iptables/iptables_driver.py +++ b/neutron/services/metering/drivers/iptables/iptables_driver.py @@ -309,7 +309,8 @@ class IptablesMeteringDriver(abstract_driver.MeteringAbstractDriver): labels = router.get(constants.METERING_LABEL_KEY, []) for label in labels: label_id = label['id'] - del rm.metering_labels[label_id] + if rm.metering_labels.get(label_id): + del rm.metering_labels[label_id] @log_helpers.log_method_call def add_metering_label(self, context, routers):