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: async def delete_silence(self, silence_id: str) -> None:
silence = await self.get_silence(silence_id) silence = await self.get_silence(silence_id)
silence_state = silence["state"] silence_state = silence["status"]["state"]
if silence_state == "expired": if silence_state == "expired":
raise SilenceExpiredError( raise SilenceExpiredError(
f"Cannot delete already expired silence with ID {silence_id}" f"Cannot delete already expired silence with ID {silence_id}"

View file

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