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
This commit is contained in:
parent
21ec2752f9
commit
0a8d5e1d4d
|
@ -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`.
|
|
@ -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"""
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue