diff --git a/ironic/drivers/modules/redfish/vendor.py b/ironic/drivers/modules/redfish/vendor.py index fa94b0797d..97f1ce4d16 100644 --- a/ironic/drivers/modules/redfish/vendor.py +++ b/ironic/drivers/modules/redfish/vendor.py @@ -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) diff --git a/ironic/tests/unit/drivers/modules/redfish/test_vendor.py b/ironic/tests/unit/drivers/modules/redfish/test_vendor.py index c32bd2a602..d7c11bbb8d 100644 --- a/ironic/tests/unit/drivers/modules/redfish/test_vendor.py +++ b/ironic/tests/unit/drivers/modules/redfish/test_vendor.py @@ -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: diff --git a/releasenotes/notes/support-httpheaders-in-create-subscription-e383137f0db1ae21.yaml b/releasenotes/notes/support-httpheaders-in-create-subscription-e383137f0db1ae21.yaml new file mode 100644 index 0000000000..ba9edac73e --- /dev/null +++ b/releasenotes/notes/support-httpheaders-in-create-subscription-e383137f0db1ae21.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Adds support to specify `HttpHeaders` when creating a subscription + via redfish vendor passthru. \ No newline at end of file