2023-08-22 17:29:13 +02:00
|
|
|
from click.testing import CliRunner
|
|
|
|
|
|
|
|
from check_patroni.cli import main
|
|
|
|
|
2023-09-28 09:41:33 +02:00
|
|
|
from . import PatroniAPI
|
2023-08-22 17:29:13 +02:00
|
|
|
|
2023-09-28 09:41:33 +02:00
|
|
|
|
|
|
|
def test_cluster_has_scheduled_action_ok(
|
|
|
|
runner: CliRunner, patroni_api: PatroniAPI
|
|
|
|
) -> None:
|
|
|
|
with patroni_api.routes({"cluster": "cluster_has_scheduled_action_ok.json"}):
|
|
|
|
result = runner.invoke(
|
|
|
|
main, ["-e", patroni_api.endpoint, "cluster_has_scheduled_action"]
|
|
|
|
)
|
2023-08-22 17:29:13 +02:00
|
|
|
assert result.exit_code == 0
|
|
|
|
assert (
|
|
|
|
result.stdout
|
|
|
|
== "CLUSTERHASSCHEDULEDACTION OK - has_scheduled_actions is 0 | has_scheduled_actions=0;;0 scheduled_restart=0 scheduled_switchover=0\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-09-28 09:41:33 +02:00
|
|
|
def test_cluster_has_scheduled_action_ko_switchover(
|
2023-09-28 09:41:33 +02:00
|
|
|
runner: CliRunner, patroni_api: PatroniAPI
|
2023-09-28 09:41:33 +02:00
|
|
|
) -> None:
|
2023-09-28 09:41:33 +02:00
|
|
|
with patroni_api.routes(
|
|
|
|
{"cluster": "cluster_has_scheduled_action_ko_switchover.json"}
|
|
|
|
):
|
|
|
|
result = runner.invoke(
|
|
|
|
main, ["-e", patroni_api.endpoint, "cluster_has_scheduled_action"]
|
|
|
|
)
|
2023-08-22 17:29:13 +02:00
|
|
|
assert result.exit_code == 2
|
|
|
|
assert (
|
|
|
|
result.stdout
|
|
|
|
== "CLUSTERHASSCHEDULEDACTION CRITICAL - has_scheduled_actions is 1 (outside range 0:0) | has_scheduled_actions=1;;0 scheduled_restart=0 scheduled_switchover=1\n"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-09-28 09:41:33 +02:00
|
|
|
def test_cluster_has_scheduled_action_ko_restart(
|
2023-09-28 09:41:33 +02:00
|
|
|
runner: CliRunner, patroni_api: PatroniAPI
|
2023-09-28 09:41:33 +02:00
|
|
|
) -> None:
|
2023-09-28 09:41:33 +02:00
|
|
|
with patroni_api.routes(
|
|
|
|
{"cluster": "cluster_has_scheduled_action_ko_restart.json"}
|
|
|
|
):
|
|
|
|
result = runner.invoke(
|
|
|
|
main, ["-e", patroni_api.endpoint, "cluster_has_scheduled_action"]
|
|
|
|
)
|
2023-08-22 17:29:13 +02:00
|
|
|
assert result.exit_code == 2
|
|
|
|
assert (
|
|
|
|
result.stdout
|
|
|
|
== "CLUSTERHASSCHEDULEDACTION CRITICAL - has_scheduled_actions is 1 (outside range 0:0) | has_scheduled_actions=1;;0 scheduled_restart=1 scheduled_switchover=0\n"
|
|
|
|
)
|