Merge "Support HttpHeaders in create_subscription"
This commit is contained in:
commit
d591ed76ad
@ -114,6 +114,7 @@ class RedfishVendorPassthru(base.VendorInterface):
|
|||||||
# are not present in the args.
|
# are not present in the args.
|
||||||
context = kwargs.get('Context', "")
|
context = kwargs.get('Context', "")
|
||||||
protocol = kwargs.get('Protocol', "Redfish")
|
protocol = kwargs.get('Protocol', "Redfish")
|
||||||
|
http_headers = kwargs.get('HttpHeaders')
|
||||||
|
|
||||||
if event_types is not None:
|
if event_types is not None:
|
||||||
event_service = redfish_utils.get_event_service(task.node)
|
event_service = redfish_utils.get_event_service(task.node)
|
||||||
@ -135,6 +136,12 @@ class RedfishVendorPassthru(base.VendorInterface):
|
|||||||
raise exception.InvalidParameterValue(
|
raise exception.InvalidParameterValue(
|
||||||
_("Protocol %s is not a string") % protocol)
|
_("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:
|
try:
|
||||||
parsed = rfc3986.uri_reference(destination)
|
parsed = rfc3986.uri_reference(destination)
|
||||||
validator = rfc3986.validators.Validator().require_presence_of(
|
validator = rfc3986.validators.Validator().require_presence_of(
|
||||||
@ -177,6 +184,10 @@ class RedfishVendorPassthru(base.VendorInterface):
|
|||||||
'EventTypes': kwargs.get('EventTypes', ["Alert"])
|
'EventTypes': kwargs.get('EventTypes', ["Alert"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
http_headers = kwargs.get('HttpHeaders', [])
|
||||||
|
if http_headers:
|
||||||
|
payload['HttpHeaders'] = http_headers
|
||||||
|
|
||||||
try:
|
try:
|
||||||
event_service = redfish_utils.get_event_service(task.node)
|
event_service = redfish_utils.get_event_service(task.node)
|
||||||
subscription = event_service.subscriptions.create(payload)
|
subscription = event_service.subscriptions.create(payload)
|
||||||
|
@ -96,13 +96,13 @@ class RedfishVendorPassthruTestCase(db_base.DbTestCase):
|
|||||||
task.driver.vendor.validate, task, 'create_subscription',
|
task.driver.vendor.validate, task, 'create_subscription',
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
kwargs = {'Context': 10}
|
kwargs = {'Destination': 'https://someulr', 'Context': 10}
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exception.InvalidParameterValue,
|
exception.InvalidParameterValue,
|
||||||
task.driver.vendor.validate, task, 'create_subscription',
|
task.driver.vendor.validate, task, 'create_subscription',
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
kwargs = {'Protocol': 10}
|
kwargs = {'Destination': 'https://someulr', 'Protocol': 10}
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exception.InvalidParameterValue,
|
exception.InvalidParameterValue,
|
||||||
task.driver.vendor.validate, task, 'create_subscription',
|
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 = mock_get_event_service.return_value
|
||||||
mock_evt_serv.get_event_types_for_subscription.return_value = \
|
mock_evt_serv.get_event_types_for_subscription.return_value = \
|
||||||
['Alert']
|
['Alert']
|
||||||
kwargs = {'EventTypes': ['Other']}
|
kwargs = {'Destination': 'https://someulr',
|
||||||
|
'EventTypes': ['Other']}
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
exception.InvalidParameterValue,
|
exception.InvalidParameterValue,
|
||||||
task.driver.vendor.validate, task, 'create_subscription',
|
task.driver.vendor.validate, task, 'create_subscription',
|
||||||
**kwargs)
|
**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):
|
def test_validate_invalid_delete_subscription(self):
|
||||||
with task_manager.acquire(self.context, self.node.uuid,
|
with task_manager.acquire(self.context, self.node.uuid,
|
||||||
shared=True) as task:
|
shared=True) as task:
|
||||||
@ -254,7 +263,10 @@ class RedfishVendorPassthruTestCase(db_base.DbTestCase):
|
|||||||
subscription = mock.MagicMock()
|
subscription = mock.MagicMock()
|
||||||
subscription.json.return_value = subscription_json
|
subscription.json.return_value = subscription_json
|
||||||
mock_event_service.subscriptions.create = subscription
|
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,
|
with task_manager.acquire(self.context, self.node.uuid,
|
||||||
shared=True) as task:
|
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