Fix subscription vendor passthru

* Instead of specifying the fields we want to oomit from create/get
subscription, now we are specifying the fields we want to be returned
(This will avoid problems when vendors are using different versions)

* When validating create_subscription are requiring that Context and
Protocol are present, use the default value from Redfish in case
they are not present in the Body request.

* When trying to delete a subscription that doesn't exist Ironic
returns 500 (default code from IronicException), this commit updates
the code to 404 to show that the subscription doesn't exist.

Change-Id: I81907be1ebc293118f5ffde4fd4d0485ade390df
This commit is contained in:
Iury Gregory Melo Ferreira 2021-08-05 13:05:07 +02:00
parent 512364df9d
commit a8bbfae5aa
2 changed files with 18 additions and 8 deletions

View File

@ -30,9 +30,8 @@ sushy = importutils.try_import('sushy')
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
METRICS = metrics_utils.get_metrics_logger(__name__) METRICS = metrics_utils.get_metrics_logger(__name__)
SUBSCRIPTION_FIELDS_REMOVE = { SUBSCRIPTION_COMMON_FIELDS = {
'@odata.context', '@odate.etag', '@odata.id', '@odata.type', 'Id', 'Context', 'Protocol', 'Destination', 'EventTypes'
'HttpHeaders', 'Oem', 'Name', 'Description'
} }
@ -111,8 +110,10 @@ class RedfishVendorPassthru(base.VendorInterface):
"""Verify that the args input are valid.""" """Verify that the args input are valid."""
destination = kwargs.get('Destination') destination = kwargs.get('Destination')
event_types = kwargs.get('EventTypes') event_types = kwargs.get('EventTypes')
context = kwargs.get('Context') # NOTE(iurygregory): Use defaults values from Redfish in case they
protocol = kwargs.get('Protocol') # are not present in the args.
context = kwargs.get('Context', "")
protocol = kwargs.get('Protocol', "Redfish")
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)
@ -147,7 +148,7 @@ class RedfishVendorPassthru(base.VendorInterface):
def _filter_subscription_fields(self, subscription_json): def _filter_subscription_fields(self, subscription_json):
filter_subscription = {k: v for k, v in subscription_json.items() filter_subscription = {k: v for k, v in subscription_json.items()
if k not in SUBSCRIPTION_FIELDS_REMOVE} if k in SUBSCRIPTION_COMMON_FIELDS}
return filter_subscription return filter_subscription
@METRICS.timer('RedfishVendorPassthru.create_subscription') @METRICS.timer('RedfishVendorPassthru.create_subscription')
@ -196,7 +197,7 @@ class RedfishVendorPassthru(base.VendorInterface):
"Required argument: a dictionary of " "Required argument: a dictionary of "
"{'id': 'subscription_bmc_id'}")) "{'id': 'subscription_bmc_id'}"))
def delete_subscription(self, task, **kwargs): def delete_subscription(self, task, **kwargs):
"""Creates a subscription. """Delete a subscription.
:param task: A TaskManager object. :param task: A TaskManager object.
:param kwargs: The arguments sent with vendor passthru. :param kwargs: The arguments sent with vendor passthru.
@ -225,7 +226,7 @@ class RedfishVendorPassthru(base.VendorInterface):
'node': task.node.uuid, 'node': task.node.uuid,
'error': e}) 'error': e})
LOG.error(error_msg) LOG.error(error_msg)
raise exception.RedfishError(error=error_msg) raise exception.RedfishError(error=error_msg, code=404)
@METRICS.timer('RedfishVendorPassthru.get_subscriptions') @METRICS.timer('RedfishVendorPassthru.get_subscriptions')
@base.passthru(['GET'], async_call=False, @base.passthru(['GET'], async_call=False,

View File

@ -0,0 +1,9 @@
---
fixes:
- |
The validation for ``create_subscription`` now uses the default values
from Redfish for `Context` and `Protocol` to avoid `None`.
The fields returned by ``create_subscription`` and ``get_subscription``
are now filtered by the common fields between vendors.
Deleting a subscription that doesn't exist will return 404 instead of 500.