From 0a8d5e1d4df1a4b4bf75d77a19c4b0c81a628411 Mon Sep 17 00:00:00 2001 From: Iury Gregory Melo Ferreira Date: Fri, 16 Jul 2021 11:08:18 +0200 Subject: [PATCH] Fix Context for EventDestination Context can be an empty string according to the redfish schema, when creating a subscription with context using empty string we can't retrieve the subscription via sushy because the BMC does not report the field in the json and will cause MissingAttributeError since we have `required=True` in the field. Change-Id: I6329a12fedf0805e7e02659755b3d9d93f07923b --- ...ext_eventdestination-9a96c34dd7edbeca.yaml | 6 +++++ .../eventservice/eventdestination.py | 2 +- .../unit/json_samples/eventdestination3.json | 15 +++++++++++ .../eventservice/test_evendestination.py | 25 +++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/allow_empty_context_eventdestination-9a96c34dd7edbeca.yaml create mode 100644 sushy/tests/unit/json_samples/eventdestination3.json diff --git a/releasenotes/notes/allow_empty_context_eventdestination-9a96c34dd7edbeca.yaml b/releasenotes/notes/allow_empty_context_eventdestination-9a96c34dd7edbeca.yaml new file mode 100644 index 00000000..050c5112 --- /dev/null +++ b/releasenotes/notes/allow_empty_context_eventdestination-9a96c34dd7edbeca.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Removes the requirement from `Context` to be present when requesting a + subscription, some BMCs do not report `Context` when the subscription is + created with empty string and would cause `MissingAttributeError`. diff --git a/sushy/resources/eventservice/eventdestination.py b/sushy/resources/eventservice/eventdestination.py index 1921d17c..28ca4a17 100644 --- a/sushy/resources/eventservice/eventdestination.py +++ b/sushy/resources/eventservice/eventdestination.py @@ -30,7 +30,7 @@ class EventDestination(base.ResourceBase): name = base.Field('Name', required=True) """The EventDestination resource name""" - context = base.Field('Context', required=True) + context = base.Field('Context') """A client-supplied string that is stored with the event destination subscription""" diff --git a/sushy/tests/unit/json_samples/eventdestination3.json b/sushy/tests/unit/json_samples/eventdestination3.json new file mode 100644 index 00000000..a220a340 --- /dev/null +++ b/sushy/tests/unit/json_samples/eventdestination3.json @@ -0,0 +1,15 @@ +{ + "@odata.context": "/redfish/v1/$metadata#EventDestination.EventDestination", + "@odata.etag": "W/\"E92736C3\"", + "@odata.id": "/redfish/v1/EventService/Subscriptions/3", + "@odata.type": "#EventDestination.v1_0_0.EventDestination", + "Id": "3", + "Description": "iLO Event Subscription", + "Destination": "https://localhost/RedfishEvents/EventReceiver.php", + "EventTypes": [ + "Alert" + ], + "HttpHeaders": [], + "Name": "Event Subscription", + "Protocol": "Redfish" +} diff --git a/sushy/tests/unit/resources/eventservice/test_evendestination.py b/sushy/tests/unit/resources/eventservice/test_evendestination.py index e29ee64a..c0c757b3 100644 --- a/sushy/tests/unit/resources/eventservice/test_evendestination.py +++ b/sushy/tests/unit/resources/eventservice/test_evendestination.py @@ -123,3 +123,28 @@ class EventDestinationCollectionTestCase(base.TestCase): data=payload, ) self.assertIsNone(new_subscription) + + def test__create_subscription_with_empty_context(self): + payload = { + 'Protocol': 'Redfish', + 'Destination': 'https://localhost/RedfishEvents/EventReceiver.php', + 'Context': '', + 'EventTypes': ["Alert"] + } + with open('sushy/tests/unit/json_samples/eventdestination3.json') as f: + self.conn.get.return_value.json.return_value = json.load(f) + self.conn.post.return_value.status_code = 201 + self.conn.post.return_value.headers.return_value = { + 'Location': '/redfish/v1/EventService/Subscriptions/3' + } + new_subscription = self.eventdestination.create(payload) + self.eventdestination._conn.post.assert_called_once_with( + '/redfish/v1/EventService/Subscriptions', + data=payload, + ) + self.assertIsNotNone(new_subscription) + self.assertEqual(new_subscription.identity, '3') + self.assertIsNone(new_subscription.context) + self.assertEqual(new_subscription.destination, + 'https://localhost/RedfishEvents/EventReceiver.php') + self.assertIn("Alert", new_subscription.event_types)