From a447b5d66cee1a941a7712c1c62a9fbdeea1a264 Mon Sep 17 00:00:00 2001 From: Nikhil B Date: Tue, 3 May 2016 21:52:49 +0530 Subject: [PATCH] Checking for error in file open There was a gap between checking for file existence and reading it. The file could get deleted during that time. Added check for such cases so that file deletion can be handled Closes-Bug: 1566123 Change-Id: If9825744a8b89d74e96315c1d6982cee9efe256c (cherry picked from commit f641b1166ce847baa56748045399a386b9f965c4) --- src/nodemgr/vrouter_nodemgr/vrouter_process_stat.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/nodemgr/vrouter_nodemgr/vrouter_process_stat.py b/src/nodemgr/vrouter_nodemgr/vrouter_process_stat.py index 8dd11ce13a7..645662f0dcb 100644 --- a/src/nodemgr/vrouter_nodemgr/vrouter_process_stat.py +++ b/src/nodemgr/vrouter_nodemgr/vrouter_process_stat.py @@ -23,8 +23,13 @@ def get_vrouter_process_info(self, proc_name): if file.endswith(".ini"): filename = \ '/etc/contrail/supervisord_vrouter_files/' + file - data = StringIO('\n'.join(line.strip() + try: + data = StringIO('\n'.join(line.strip() for line in open(filename))) + except IOError: + msg = "This file does not exist anymore so continuing: " + sys.stderr.write(msg + filename + "\n") + continue Config = ConfigParser.SafeConfigParser() Config.readfp(data) sections = Config.sections()