From 70a79d7b456e993e8be13a891871bf3b72b79929 Mon Sep 17 00:00:00 2001 From: Vu Cong Tuan Date: Fri, 2 Nov 2018 14:37:39 +0700 Subject: [PATCH] Remove DeprecationWarning of "decodestring()" When running "tox -e py35", it shows: DeprecationWarning: decodestring() is a deprecated alias, use decodebytes() This patch helps to remove this deprecation warning by replacing "base64.decodestring" with "oslo_serialization.base64.decode_as_bytes". The same has been done for nova: https://review.openstack.org/#/c/610401/ Change-Id: Ib3f7fc4392ca53e92ee2e421b95874dc97f04e5f --- cinder/api/validation/validators.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cinder/api/validation/validators.py b/cinder/api/validation/validators.py index 510ea3baa6f..0f8c46f1427 100644 --- a/cinder/api/validation/validators.py +++ b/cinder/api/validation/validators.py @@ -18,11 +18,11 @@ Internal implementation of request Body validating middleware. """ -import base64 import re import jsonschema from jsonschema import exceptions as jsonschema_exc +from oslo_serialization import base64 from oslo_utils import strutils from oslo_utils import timeutils from oslo_utils import uuidutils @@ -199,9 +199,7 @@ def _validate_base64_format(instance): try: if isinstance(instance, six.text_type): instance = instance.encode('utf-8') - base64.decodestring(instance) - except base64.binascii.Error: - return False + base64.decode_as_bytes(instance) except TypeError: # The name must be string type. If instance isn't string type, the # TypeError will be raised at here.