From 14e665a1fdee47f2a4b5e173ea60eb89f5cedca7 Mon Sep 17 00:00:00 2001 From: liujinxin Date: Tue, 9 Apr 2024 15:32:44 +0800 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: Iba433485d2e5deebd7f256bba191382071696b96 --- neutron/Chart.yaml | 2 +- neutron/templates/bin/_health-probe.py.tpl | 24 +++++++++++++--------- releasenotes/notes/neutron.yaml | 1 + 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/neutron/Chart.yaml b/neutron/Chart.yaml index a58bb8d85b..1f2cc0f086 100644 --- a/neutron/Chart.yaml +++ b/neutron/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Neutron name: neutron -version: 0.3.38 +version: 0.3.39 home: https://docs.openstack.org/neutron/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Neutron/OpenStack_Project_Neutron_vertical.png sources: diff --git a/neutron/templates/bin/_health-probe.py.tpl b/neutron/templates/bin/_health-probe.py.tpl index 897b735267..b5e170bcfd 100644 --- a/neutron/templates/bin/_health-probe.py.tpl +++ b/neutron/templates/bin/_health-probe.py.tpl @@ -315,16 +315,20 @@ 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/neutron.yaml b/releasenotes/notes/neutron.yaml index a3b1791398..3ce76ee5e3 100644 --- a/releasenotes/notes/neutron.yaml +++ b/releasenotes/notes/neutron.yaml @@ -80,4 +80,5 @@ neutron: - 0.3.36 Enable custom annotations for Openstack pods - 0.3.37 Proper chown /run/openvswitch/db.sock under OVN - 0.3.38 Add 2024.1 overrides + - 0.3.39 Ensure that the script handles cases where the PID file exists but is empty or does not contain the expected data structure. ...