From 197e07d3de36895f506abb43b19001e9c63b8329 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sat, 21 Aug 2021 01:35:45 +0900 Subject: [PATCH] rfc3986: Replace deprecated URIReference.is_valid The URIReference.is_valid method has been deprecated since rfc3986 1.1.0[1] and triggers the following deprecation warning. DeprecationWarning: Please use rfc3986.validators.Validator instead. This method will be eventually removed. [1] https://github.com/python-hyper/rfc3986/commit/fd19bd90 Change-Id: I256e42b8aa736b278bab6b4aa145a859aca10e17 --- ironic/drivers/modules/redfish/utils.py | 10 ++++++++-- ironic/drivers/modules/redfish/vendor.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py index 9915dba116..607de4366d 100644 --- a/ironic/drivers/modules/redfish/utils.py +++ b/ironic/drivers/modules/redfish/utils.py @@ -108,8 +108,14 @@ def parse_driver_info(node): if not parsed.scheme or not parsed.authority: address = 'https://%s' % address parsed = rfc3986.uri_reference(address) - # TODO(vdrok): Workaround this check, in py3 we need to use validator class - if not parsed.is_valid(require_scheme=True, require_authority=True): + validator = rfc3986.validators.Validator().require_presence_of( + 'scheme', 'host', + ).check_validity_of( + 'scheme', 'userinfo', 'host', 'path', 'query', 'fragment', + ) + try: + validator.validate(parsed) + except rfc3986.exceptions.RFC3986Exception: raise exception.InvalidParameterValue( _('Invalid Redfish address %(address)s set in ' 'driver_info/redfish_address on node %(node)s') % diff --git a/ironic/drivers/modules/redfish/vendor.py b/ironic/drivers/modules/redfish/vendor.py index c802176cec..056dbe90ad 100644 --- a/ironic/drivers/modules/redfish/vendor.py +++ b/ironic/drivers/modules/redfish/vendor.py @@ -137,8 +137,14 @@ class RedfishVendorPassthru(base.VendorInterface): try: parsed = rfc3986.uri_reference(destination) - if not parsed.is_valid(require_scheme=True, - require_authority=True): + validator = rfc3986.validators.Validator().require_presence_of( + 'scheme', 'host', + ).check_validity_of( + 'scheme', 'userinfo', 'host', 'path', 'query', 'fragment', + ) + try: + validator.validate(parsed) + except rfc3986.exceptions.RFC3986Exception: # NOTE(iurygregory): raise error because the parsed # destination does not contain scheme or authority. raise TypeError