Changeset View
Changeset View
Standalone View
Standalone View
swh/icinga_plugins/tests/test_vault.py
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | def test_vault_failure(requests_mock, mocker, mocked_time): | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | ||||
get_storage_mock.side_effect = FakeStorage | get_storage_mock.side_effect = FakeStorage | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--prometheus-exporter", | |||||
"--prometheus-exporter-directory", | |||||
"/tmp", | |||||
"check-vault", | "check-vault", | ||||
"--swh-web-url", | "--swh-web-url", | ||||
"mock://swh-web.example.org", | "mock://swh-web.example.org", | ||||
"--swh-storage-url", | "--swh-storage-url", | ||||
"foo://example.org", | "foo://example.org", | ||||
"directory", | "directory", | ||||
], | ], | ||||
catch_exceptions=True, | catch_exceptions=True, | ||||
Show All 18 Lines | def test_vault_unknown_status(requests_mock, mocker, mocked_time): | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | ||||
get_storage_mock.side_effect = FakeStorage | get_storage_mock.side_effect = FakeStorage | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--prometheus-exporter", | |||||
"--prometheus-exporter-directory", | |||||
"/tmp", | |||||
"check-vault", | "check-vault", | ||||
"--swh-web-url", | "--swh-web-url", | ||||
"mock://swh-web.example.org", | "mock://swh-web.example.org", | ||||
"--swh-storage-url", | "--swh-storage-url", | ||||
"foo://example.org", | "foo://example.org", | ||||
"directory", | "directory", | ||||
], | ], | ||||
catch_exceptions=True, | catch_exceptions=True, | ||||
Show All 19 Lines | def test_vault_timeout(requests_mock, mocker, mocked_time): | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | ||||
get_storage_mock.side_effect = FakeStorage | get_storage_mock.side_effect = FakeStorage | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--prometheus-exporter", | |||||
"--prometheus-exporter-directory", | |||||
"/tmp", | |||||
"check-vault", | "check-vault", | ||||
"--swh-web-url", | "--swh-web-url", | ||||
"mock://swh-web.example.org", | "mock://swh-web.example.org", | ||||
"--swh-storage-url", | "--swh-storage-url", | ||||
"foo://example.org", | "foo://example.org", | ||||
"directory", | "directory", | ||||
], | ], | ||||
catch_exceptions=True, | catch_exceptions=True, | ||||
Show All 21 Lines | def test_vault_cached_directory(requests_mock, mocker, mocked_time): | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | ||||
get_storage_mock.side_effect = FakeStorage | get_storage_mock.side_effect = FakeStorage | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--prometheus-exporter", | |||||
"--prometheus-exporter-directory", | |||||
"/tmp", | |||||
"check-vault", | "check-vault", | ||||
"--swh-web-url", | "--swh-web-url", | ||||
"mock://swh-web.example.org", | "mock://swh-web.example.org", | ||||
"--swh-storage-url", | "--swh-storage-url", | ||||
"foo://example.org", | "foo://example.org", | ||||
"directory", | "directory", | ||||
] | ] | ||||
) | ) | ||||
Show All 12 Lines | def test_vault_no_directory(requests_mock, mocker, mocked_time): | ||||
scenario.install_mock(requests_mock) | scenario.install_mock(requests_mock) | ||||
get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | get_storage_mock = mocker.patch("swh.icinga_plugins.vault.get_storage") | ||||
get_storage_mock.side_effect = FakeStorage | get_storage_mock.side_effect = FakeStorage | ||||
mocker.patch(f"{__name__}.FakeStorage.directory_get_random", return_value=None) | mocker.patch(f"{__name__}.FakeStorage.directory_get_random", return_value=None) | ||||
result = invoke( | result = invoke( | ||||
[ | [ | ||||
"--prometheus-exporter", | |||||
"--prometheus-exporter-directory", | |||||
"/tmp", | |||||
"check-vault", | "check-vault", | ||||
"--swh-web-url", | "--swh-web-url", | ||||
"mock://swh-web.example.org", | "mock://swh-web.example.org", | ||||
"--swh-storage-url", | "--swh-storage-url", | ||||
"foo://example.org", | "foo://example.org", | ||||
"directory", | "directory", | ||||
], | ], | ||||
catch_exceptions=True, | catch_exceptions=True, | ||||
) | ) | ||||
assert result.output == ("VAULT CRITICAL - No directory exists in the archive.\n") | assert result.output == ("VAULT CRITICAL - No directory exists in the archive.\n") | ||||
assert result.exit_code == 2, result.output | assert result.exit_code == 2, result.output |