Skip to content

Commit

Permalink
Fix liveness check
Browse files Browse the repository at this point in the history
The liveness probe used to return something. It looks like it doesn't do
it anymore and it breaks the `node_is_alive` check.

Issue: #31
  • Loading branch information
blogh committed Aug 21, 2023
1 parent a01a535 commit 28bbfe9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
6 changes: 4 additions & 2 deletions check_patroni/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def rest_api(self: "PatroniResource", service: str) -> Any:
_log.debug(e)
continue
# The status code is already displayed by urllib3
_log.debug("api call data: %(data)s", {"data": r.text})
_log.debug(
"api call data: %(data)s", {"data": r.text if r.text else "<Empty>"}
)

if r.status_code != 200:
raise APIError(
f"Failed to connect to {endpoint}/{service} status code {r.status_code}"
)

return r.json()
return r.json() if r.text else None
raise nagiosplugin.CheckError("Connection failed for all provided endpoints")


Expand Down
19 changes: 0 additions & 19 deletions tests/json/node_is_alive.json

This file was deleted.

4 changes: 2 additions & 2 deletions tests/test_node_is_alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
def test_node_is_alive_ok(mocker: MockerFixture) -> None:
runner = CliRunner()

my_mock(mocker, "node_is_alive", 200)
my_mock(mocker, None, 200)
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"])
assert result.exit_code == 0


def test_node_is_alive_ko(mocker: MockerFixture) -> None:
runner = CliRunner()

my_mock(mocker, "node_is_alive", 404)
my_mock(mocker, None, 404)
result = runner.invoke(main, ["-e", "https://10.20.199.3:8008", "node_is_alive"])
assert result.exit_code == 2
2 changes: 1 addition & 1 deletion tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def my_mock(mocker: MockerFixture, json_file: str, status: int) -> None:
def mock_rest_api(self: PatroniResource, service: str) -> Any:
if status != 200:
raise APIError("Test en erreur pour status code 200")
return getjson(json_file)
return getjson(json_file) if json_file else None

mocker.resetall()
mocker.patch("check_patroni.types.PatroniResource.rest_api", mock_rest_api)

0 comments on commit 28bbfe9

Please sign in to comment.