From 572c0dace98320a2ff925bf91e5ff07a4cfd9f4f Mon Sep 17 00:00:00 2001 From: Gregory Thiemonge Date: Thu, 17 Nov 2022 17:56:03 +0100 Subject: [PATCH] Add a newline when writing the server state file Before restarting haproxy, the amphora-agent dumps the state of the servers in a file, so when haproxy reloads, it can recover the operating state of its backends' members. But with haproxy 2.4 (in Centos 9 Stream), it fails with a "corrupted global server state file" error when reading this file. It seems that most recent haproxy releases have a more strict validation of the format of the file and ensure that it is terminated with a newline. This commit adds a newline to the file (all the responses to haproxy queries are stripped in the amphora-agent). It fixes the issue on Centos 9 Stream (and turns off a warning on Ubuntu). Story: 2010442 Task: 46873 Change-Id: I00e327e1d94e46aa13a38120df9865ec34eaa593 --- octavia/amphorae/backends/utils/haproxy_query.py | 2 +- .../unit/amphorae/backends/utils/test_haproxy_query.py | 2 +- ...orrupted-global-server-state-file-325ab7c62e21ff14.yaml | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/fix-corrupted-global-server-state-file-325ab7c62e21ff14.yaml diff --git a/octavia/amphorae/backends/utils/haproxy_query.py b/octavia/amphorae/backends/utils/haproxy_query.py index bd3041768b..582d6845ea 100644 --- a/octavia/amphorae/backends/utils/haproxy_query.py +++ b/octavia/amphorae/backends/utils/haproxy_query.py @@ -160,7 +160,7 @@ class HAProxyQuery(object): result = self._query('show servers state') # No need for binary mode, the _query converts bytes to ascii. with open(state_file_path, 'w', encoding='utf-8') as fh: - fh.write(result) + fh.write(result + "\n") return True except Exception as e: # Catch any exception - may be socket issue, or write permission diff --git a/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py b/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py index 08a8168ba9..851d384ce1 100644 --- a/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py +++ b/octavia/tests/unit/amphorae/backends/utils/test_haproxy_query.py @@ -158,7 +158,7 @@ class QueryTestCase(base.TestCase): self.q.save_state(filename) - mock_fh.write.assert_called_once_with('DATA') + mock_fh.write.assert_called_once_with('DATA\n') def test_save_state_error(self): """save_state() should swallow exceptions""" diff --git a/releasenotes/notes/fix-corrupted-global-server-state-file-325ab7c62e21ff14.yaml b/releasenotes/notes/fix-corrupted-global-server-state-file-325ab7c62e21ff14.yaml new file mode 100644 index 0000000000..e0cd761883 --- /dev/null +++ b/releasenotes/notes/fix-corrupted-global-server-state-file-325ab7c62e21ff14.yaml @@ -0,0 +1,7 @@ +--- +fixes: + - | + Fixed a "corrupted global server state file" error in Centos 9 Stream when + reloading the state of the servers after restarting haproxy. + It also fixed the recovering of the operational state of the servers in + haproxy after its restart.