Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix liveness check #34

Merged
merged 2 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions check_patroni/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ 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:
blogh marked this conversation as resolved.
Show resolved Hide resolved
raise APIError(
f"Failed to connect to {endpoint}/{service} status code {r.status_code}"
)

return r.json()
try:
return r.json()
except requests.exceptions.JSONDecodeError:
return 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)
Loading