From 9ad03dcf96b9b2fbe43dede8b59c99542bda237a Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Thu, 31 Oct 2019 15:32:09 +0000 Subject: [PATCH] Catch FileNotFoundError when listing namespace PIDs During the namespace PID listing, if a process is stopped, it will disappear from "/proc/". When "os.stat(path)" is executed on an unexistent path, returns "FileNotFoundError". This exception should be catched and ignored. Change-Id: Icde5e15bd97578f5ec8273f22ef8384502be1850 Related-Bug: #1841753 --- neutron/privileged/agent/linux/ip_lib.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/neutron/privileged/agent/linux/ip_lib.py b/neutron/privileged/agent/linux/ip_lib.py index 800cf35bf40..0ec3173561a 100644 --- a/neutron/privileged/agent/linux/ip_lib.py +++ b/neutron/privileged/agent/linux/ip_lib.py @@ -216,7 +216,7 @@ def list_ns_pids(namespace): try: ns_path = os.path.join(NETNS_RUN_DIR, namespace) ns_inode = os.stat(ns_path).st_ino - except OSError: + except (OSError, FileNotFoundError): return ns_pids for pid in os.listdir('/proc'): @@ -226,7 +226,7 @@ def list_ns_pids(namespace): pid_path = os.path.join('/proc', pid, 'ns', 'net') if os.stat(pid_path).st_ino == ns_inode: ns_pids.append(int(pid)) - except OSError: + except (OSError, FileNotFoundError): continue return ns_pids