From ce39dc5ed7cd6d2f7220237a7688ca9d758b51b6 Mon Sep 17 00:00:00 2001 From: Mohammed Naser Date: Thu, 5 Nov 2020 17:32:28 -0500 Subject: [PATCH] Fix NetNS creation when PID is re-used Change-Id: I464d769d58998fcb85d1de6ddc6e11cb6525fdf9 --- openstack_tools/cmd/prometheus/routers_l3_ha.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/openstack_tools/cmd/prometheus/routers_l3_ha.py b/openstack_tools/cmd/prometheus/routers_l3_ha.py index 0d1efd1..7887ca1 100644 --- a/openstack_tools/cmd/prometheus/routers_l3_ha.py +++ b/openstack_tools/cmd/prometheus/routers_l3_ha.py @@ -83,6 +83,11 @@ def main(): while True: output = "" for pid_file in get_pid_files(args.state): + state_path = pid_file.replace('.pid.keepalived-vrrp', '') + state_file = os.path.join(state_path, 'state') + + router_id = os.path.basename(state_path) + with open(pid_file) as pid_fd: pid = int(pid_fd.read()) @@ -90,10 +95,12 @@ def main(): if psutil.pid_exists(pid) is False: continue - state_path = pid_file.replace('.pid.keepalived-vrrp', '') - state_file = os.path.join(state_path, 'state') + # Check if the PID is indeed for the correct router + proc = psutil.Process(pid) + cmdline = " ".join(proc.cmdline()) + if router_id not in cmdline: + continue - router_id = os.path.basename(state_path) with open(state_file) as state_fd: master = 1 if 'master' in state_fd.read() else 0