From bf73cd98aae1b702b00f6dca4c3e6e1ceeb5ae48 Mon Sep 17 00:00:00 2001 From: Slawek Kaplonski Date: Tue, 25 Aug 2020 15:06:04 +0200 Subject: [PATCH] Don't raise FileNotFoundError during disabling keepalived In case when keepalived's config is not existing already, there is no need to raise any exception while L3 agent is trying to clean this config. In stable/rocky branch, where we are using Python 2.7 it requires to catch EnvironmentError and check errno instead of catching FileNotFoundError which isn't available in Python 2.7. Change-Id: I9ec81ad0c10379294d3145c5902e8b81b65c0221 Closes-Bug: #1892866 (cherry picked from commit a08893368a9f323d41f490ee043ef7bd50c4f1fa) --- neutron/agent/l3/ha_router.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/neutron/agent/l3/ha_router.py b/neutron/agent/l3/ha_router.py index b6cb0bfe672..aaa2b1ef63e 100644 --- a/neutron/agent/l3/ha_router.py +++ b/neutron/agent/l3/ha_router.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import errno import os import shutil import signal @@ -193,7 +194,11 @@ class HaRouter(router.RouterInfo): return self.keepalived_manager.disable() conf_dir = self.keepalived_manager.get_conf_dir() - shutil.rmtree(conf_dir) + try: + shutil.rmtree(conf_dir) + except EnvironmentError as e: + if e.errno != errno.ENOENT: + raise def _get_keepalived_instance(self): return self.keepalived_manager.config.get_instance(self.ha_vr_id)