fix silence status

This commit is contained in:
HgO 2022-07-27 21:28:57 +02:00
parent a1f701d2ba
commit 978f0adc61
2 changed files with 15 additions and 15 deletions

View file

@ -105,7 +105,7 @@ class AlertmanagerClient:
async def delete_silence(self, silence_id: str) -> None:
silence = await self.get_silence(silence_id)
silence_state = silence["state"]
silence_state = silence["status"]["state"]
if silence_state == "expired":
raise SilenceExpiredError(
f"Cannot delete already expired silence with ID {silence_id}"

View file

@ -43,8 +43,8 @@ class AbstractFakeAlertmanagerServer:
]
)
self.app["silences"] = [
{"id": "silence1", "state": "active"},
{"id": "silence2", "state": "expired"},
{"id": "silence1", "status": {"state": "active"}},
{"id": "silence2", "status": {"state": "expired"}},
]
self.runner = web.AppRunner(self.app)
@ -114,7 +114,7 @@ class FakeAlertmanagerServer(AbstractFakeAlertmanagerServer):
silence = await request.json()
if silence["id"] is None:
silence["id"] = "silence1"
silence["state"] = "active"
silence["status"] = {"state": "active"}
silences.append(silence)
return web.Response(
@ -229,8 +229,8 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
[
{"id": "silence1", "state": "active"},
{"id": "silence2", "state": "expired"},
{"id": "silence1", "status": {"state": "active"}},
{"id": "silence2", "status": {"state": "expired"}},
],
silences,
)
@ -305,11 +305,11 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
silence2 = await alertmanager.get_silence("silence2")
self.assertEqual(
{"id": "silence1", "state": "active"},
{"id": "silence1", "status": {"state": "active"}},
silence1,
)
self.assertEqual(
{"id": "silence2", "state": "expired"},
{"id": "silence2", "status": {"state": "expired"}},
silence2,
)
@ -350,7 +350,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
{
"id": "silence1",
"state": "active",
"status": {"state": "active"},
"matchers": [
{
"name": "alertname",
@ -384,7 +384,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
{
"id": "silence2",
"state": "active",
"status": {"state": "active"},
"matchers": [
{
"name": "alertname",
@ -416,7 +416,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
{
"id": "silence1",
"state": "active",
"status": {"state": "active"},
"matchers": [
{
"name": "alertname",
@ -450,7 +450,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
{
"id": "silence1",
"state": "active",
"status": {"state": "active"},
"matchers": [
{
"name": "alertname",
@ -510,7 +510,7 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
await alertmanager.delete_silence("silence1")
silences = await alertmanager.get_silences()
self.assertEqual([{"id": "silence2", "state": "expired"}], silences)
self.assertEqual([{"id": "silence2", "status": {"state": "expired"}}], silences)
async def test_delete_silence_raise_silence_expired(self) -> None:
async with FakeAlertmanagerServer() as fake_alertmanager_server:
@ -525,8 +525,8 @@ class AlertmanagerClientTestCase(unittest.IsolatedAsyncioTestCase):
self.assertEqual(
[
{"id": "silence1", "state": "active"},
{"id": "silence2", "state": "expired"},
{"id": "silence1", "status": {"state": "active"}},
{"id": "silence2", "status": {"state": "expired"}},
],
silences,
)