Support HttpHeaders in create_subscription
This commit adds support to check if request to create a subscription contains HttpHeaders so we can send in the payload. [1] [1] https://redfish.dmtf.org/schemas/v1/EventDestination.v1_0_0.json Change-Id: I548ae06e22f217bf10ce6a7af57addfa7f9be555
This commit is contained in:
parent
fa1c60cbce
commit
72eac4e748
@ -114,6 +114,7 @@ class RedfishVendorPassthru(base.VendorInterface):
|
||||
# are not present in the args.
|
||||
context = kwargs.get('Context', "")
|
||||
protocol = kwargs.get('Protocol', "Redfish")
|
||||
http_headers = kwargs.get('HttpHeaders')
|
||||
|
||||
if event_types is not None:
|
||||
event_service = redfish_utils.get_event_service(task.node)
|
||||
@ -135,6 +136,12 @@ class RedfishVendorPassthru(base.VendorInterface):
|
||||
raise exception.InvalidParameterValue(
|
||||
_("Protocol %s is not a string") % protocol)
|
||||
|
||||
# NOTE(iurygregory): if http_headers are None there is no problem,
|
||||
# the validation will fail if the value is not None and not a list.
|
||||
if http_headers is not None and not isinstance(http_headers, list):
|
||||
raise exception.InvalidParameterValue(
|
||||
_("HttpHeaders %s is not a list of headers") % http_headers)
|
||||
|
||||
try:
|
||||
parsed = rfc3986.uri_reference(destination)
|
||||
validator = rfc3986.validators.Validator().require_presence_of(
|
||||
@ -177,6 +184,10 @@ class RedfishVendorPassthru(base.VendorInterface):
|
||||
'EventTypes': kwargs.get('EventTypes', ["Alert"])
|
||||
}
|
||||
|
||||
http_headers = kwargs.get('HttpHeaders', [])
|
||||
if http_headers:
|
||||
payload['HttpHeaders'] = http_headers
|
||||
|
||||
try:
|
||||
event_service = redfish_utils.get_event_service(task.node)
|
||||
subscription = event_service.subscriptions.create(payload)
|
||||
|
@ -96,13 +96,13 @@ class RedfishVendorPassthruTestCase(db_base.DbTestCase):
|
||||
task.driver.vendor.validate, task, 'create_subscription',
|
||||
**kwargs)
|
||||
|
||||
kwargs = {'Context': 10}
|
||||
kwargs = {'Destination': 'https://someulr', 'Context': 10}
|
||||
self.assertRaises(
|
||||
exception.InvalidParameterValue,
|
||||
task.driver.vendor.validate, task, 'create_subscription',
|
||||
**kwargs)
|
||||
|
||||
kwargs = {'Protocol': 10}
|
||||
kwargs = {'Destination': 'https://someulr', 'Protocol': 10}
|
||||
self.assertRaises(
|
||||
exception.InvalidParameterValue,
|
||||
task.driver.vendor.validate, task, 'create_subscription',
|
||||
@ -111,12 +111,21 @@ class RedfishVendorPassthruTestCase(db_base.DbTestCase):
|
||||
mock_evt_serv = mock_get_event_service.return_value
|
||||
mock_evt_serv.get_event_types_for_subscription.return_value = \
|
||||
['Alert']
|
||||
kwargs = {'EventTypes': ['Other']}
|
||||
kwargs = {'Destination': 'https://someulr',
|
||||
'EventTypes': ['Other']}
|
||||
self.assertRaises(
|
||||
exception.InvalidParameterValue,
|
||||
task.driver.vendor.validate, task, 'create_subscription',
|
||||
**kwargs)
|
||||
|
||||
kwargs = {'Destination': 'https://someulr',
|
||||
'HttpHeaders': {'Content-Type': 'application/json'}}
|
||||
self.assertRaises(
|
||||
exception.InvalidParameterValue,
|
||||
task.driver.vendor.validate, task, 'create_subscription',
|
||||
**kwargs
|
||||
)
|
||||
|
||||
def test_validate_invalid_delete_subscription(self):
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=True) as task:
|
||||
@ -254,7 +263,10 @@ class RedfishVendorPassthruTestCase(db_base.DbTestCase):
|
||||
subscription = mock.MagicMock()
|
||||
subscription.json.return_value = subscription_json
|
||||
mock_event_service.subscriptions.create = subscription
|
||||
kwargs = {'Destination': 'https://someurl'}
|
||||
kwargs = {
|
||||
'Destination': 'https://someurl',
|
||||
'HttpHeaders': [{"Content-Type": "application/json"}]
|
||||
}
|
||||
|
||||
with task_manager.acquire(self.context, self.node.uuid,
|
||||
shared=True) as task:
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Adds support to specify `HttpHeaders` when creating a subscription
|
||||
via redfish vendor passthru.
|
Loading…
Reference in New Issue
Block a user