From 161799edaab21ea7b4f577766764768fa6c39e5d Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 17 Jan 2017 12:07:55 -0800 Subject: [PATCH] Handle oslo.serialization type error and binascii error A upcoming oslo.serialization release will unify these but for now just handle both so that the release of that library can proceed without breaking nova. Change-Id: I87d5497307fa1610b4c340fe562d65cd25a93feb --- nova/compute/api.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index f76af12285..ce772fe32a 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -833,14 +833,15 @@ class API(base.Base): length=l, maxsize=MAX_USERDATA_SIZE) try: - # TODO(gcb): Just use base64utils.decode_as_bytes(user_data) - # when https://review.openstack.org/#/c/410797/ is merged and - # ensure oslo.serialization >=2.15.0 in Nova requirements.txt. - if six.PY3: - base64utils.decode_as_bytes(user_data) - else: - base64.decodestring(user_data) - except base64.binascii.Error: + base64utils.decode_as_bytes(user_data) + except (base64.binascii.Error, TypeError): + # TODO(harlowja): reduce the above exceptions caught to + # only type error once we get a new oslo.serialization + # release that captures and makes only one be output. + # + # We can eliminate the capture of `binascii.Error` when: + # + # https://review.openstack.org/#/c/418066/ is released. raise exception.InstanceUserDataMalformed() # When using Neutron, _check_requested_secgroups will translate and