-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new service cluster_has_scheduled_action
- Loading branch information
Showing
8 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"members": [ | ||
{ | ||
"name": "p1", | ||
"role": "sync_standby", | ||
"state": "streaming", | ||
"api_url": "http://10.20.30.51:8008/patroni", | ||
"host": "10.20.30.51", | ||
"port": 5432, | ||
"timeline": 3, | ||
"scheduled_restart": { | ||
"schedule": "2023-10-08T11:30:00+00:00", | ||
"postmaster_start_time": "2023-08-21 08:08:33.415237+00:00" | ||
}, | ||
"lag": 0 | ||
}, | ||
{ | ||
"name": "p2", | ||
"role": "leader", | ||
"state": "running", | ||
"api_url": "http://10.20.30.52:8008/patroni", | ||
"host": "10.20.30.52", | ||
"port": 5432, | ||
"timeline": 3 | ||
} | ||
] | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/json/cluster_has_scheduled_action_ko_switchover.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"members": [ | ||
{ | ||
"name": "p1", | ||
"role": "sync_standby", | ||
"state": "streaming", | ||
"api_url": "http://10.20.30.51:8008/patroni", | ||
"host": "10.20.30.51", | ||
"port": 5432, | ||
"timeline": 3, | ||
"lag": 0 | ||
}, | ||
{ | ||
"name": "p2", | ||
"role": "leader", | ||
"state": "running", | ||
"api_url": "http://10.20.30.52:8008/patroni", | ||
"host": "10.20.30.52", | ||
"port": 5432, | ||
"timeline": 3 | ||
} | ||
], | ||
"scheduled_switchover": { | ||
"at": "2023-10-08T11:30:00+00:00", | ||
"from": "p1", | ||
"to": "p2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"members": [ | ||
{ | ||
"name": "srv1", | ||
"role": "leader", | ||
"state": "running", | ||
"api_url": "https://10.20.199.3:8008/patroni", | ||
"host": "10.20.199.3", | ||
"port": 5432, | ||
"timeline": 51 | ||
}, | ||
{ | ||
"name": "srv2", | ||
"role": "replica", | ||
"state": "streaming", | ||
"api_url": "https://10.20.199.4:8008/patroni", | ||
"host": "10.20.199.4", | ||
"port": 5432, | ||
"timeline": 51, | ||
"lag": 0 | ||
}, | ||
{ | ||
"name": "srv3", | ||
"role": "sync_standby", | ||
"state": "streaming", | ||
"api_url": "https://10.20.199.5:8008/patroni", | ||
"host": "10.20.199.5", | ||
"port": 5432, | ||
"timeline": 51, | ||
"lag": 0 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from click.testing import CliRunner | ||
from pytest_mock import MockerFixture | ||
|
||
from check_patroni.cli import main | ||
|
||
from .tools import my_mock | ||
|
||
|
||
def test_cluster_has_scheduled_action_ok( | ||
mocker: MockerFixture, use_old_replica_state: bool | ||
) -> None: | ||
runner = CliRunner() | ||
|
||
my_mock(mocker, "cluster_has_scheduled_action_ok", 200) | ||
result = runner.invoke( | ||
main, ["-e", "https://10.20.199.3:8008", "cluster_has_scheduled_action"] | ||
) | ||
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" | ||
) | ||
|
||
|
||
def test_cluster_has_scheduled_action_ko_switchover( | ||
mocker: MockerFixture, use_old_replica_state: bool | ||
) -> None: | ||
runner = CliRunner() | ||
|
||
my_mock(mocker, "cluster_has_scheduled_action_ko_switchover", 200) | ||
result = runner.invoke( | ||
main, ["-e", "https://10.20.199.3:8008", "cluster_has_scheduled_action"] | ||
) | ||
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" | ||
) | ||
|
||
|
||
def test_cluster_has_scheduled_action_ko_restart( | ||
mocker: MockerFixture, use_old_replica_state: bool | ||
) -> None: | ||
runner = CliRunner() | ||
|
||
my_mock(mocker, "cluster_has_scheduled_action_ko_restart", 200) | ||
result = runner.invoke( | ||
main, ["-e", "https://10.20.199.3:8008", "cluster_has_scheduled_action"] | ||
) | ||
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters