From 5ef1d54607809c6eaab0c64ce6e179823213abf1 Mon Sep 17 00:00:00 2001 From: az7961 Date: Thu, 6 Jul 2023 09:49:51 -0500 Subject: [PATCH] Ensure that the script handles cases where the PID file exists but is empty or does not contain the expected data structure. Change-Id: I4301a6cbea0688369c735d4751c741106b3fe7ab --- nova/Chart.yaml | 2 +- nova/templates/bin/_health-probe.py.tpl | 23 +++++++++++++---------- releasenotes/notes/nova.yaml | 1 + 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/nova/Chart.yaml b/nova/Chart.yaml index 1c511e8d27..b51859fbc6 100644 --- a/nova/Chart.yaml +++ b/nova/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Nova name: nova -version: 0.3.14 +version: 0.3.15 home: https://docs.openstack.org/nova/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Nova/OpenStack_Project_Nova_vertical.png sources: diff --git a/nova/templates/bin/_health-probe.py.tpl b/nova/templates/bin/_health-probe.py.tpl index a72376961f..660d62b627 100644 --- a/nova/templates/bin/_health-probe.py.tpl +++ b/nova/templates/bin/_health-probe.py.tpl @@ -243,16 +243,19 @@ if __name__ == "__main__": data = {} if os.path.isfile(pidfile): with open(pidfile,'r') as f: - data = json.load(f) - if check_pid_running(data['pid']): - if data['exit_count'] > 1: - # Third time in, kill the previous process - os.kill(int(data['pid']), signal.SIGTERM) - else: - data['exit_count'] = data['exit_count'] + 1 - with open(pidfile, 'w') as f: - json.dump(data, f) - sys.exit(0) + file_content = f.read().strip() + if file_content: + data = json.loads(file_content) + + if 'pid' in data and check_pid_running(data['pid']): + if 'exit_count' in data and data['exit_count'] > 1: + # Third time in, kill the previous process + os.kill(int(data['pid']), signal.SIGTERM) + else: + data['exit_count'] = data.get('exit_count', 0) + 1 + with open(pidfile, 'w') as f: + json.dump(data, f) + sys.exit(0) data['pid'] = os.getpid() data['exit_count'] = 0 with open(pidfile, 'w') as f: diff --git a/releasenotes/notes/nova.yaml b/releasenotes/notes/nova.yaml index 6f78db74d7..4e5308c938 100644 --- a/releasenotes/notes/nova.yaml +++ b/releasenotes/notes/nova.yaml @@ -83,4 +83,5 @@ nova: - 0.3.12 Update oslo_messaging_RPCClient - 0.3.13 Add Zed overrides - 0.3.14 Add 2023.1 overrides + - 0.3.15 Ensure that the health check script handles cases where the PID file exists but is empty or does not contain the expected data structure. ...