]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/barbican.py: convert to str before json.loads()
authorKefu Chai <kchai@redhat.com>
Mon, 6 Apr 2020 09:36:18 +0000 (17:36 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 7 Apr 2020 13:51:23 +0000 (21:51 +0800)
in Python3, json.loads() expects a string, while
HTTPConnection.getresponse() returns a byte-like object, so we need to
coerce it to str first.

Signed-off-by: Kefu Chai <kchai@redhat.com>
qa/tasks/barbican.py

index 51a9af1f9ebb3f31e38ce23fbf638aabc6761902..6c7f97376ec40c3433773c4a3f69198e4c5a0364 100644 (file)
@@ -4,6 +4,7 @@ Deploy and configure Barbican for Teuthology
 import argparse
 import contextlib
 import logging
+import six
 from six.moves import http_client
 from six.moves.urllib.parse import urlparse
 import json
@@ -271,7 +272,7 @@ def create_secrets(ctx, config):
             rgw_access_user_resp.status < 300):
         raise Exception("Cannot authenticate user "+rgw_user["username"]+" for secret creation")
     #    baru_resp = json.loads(baru_req.data)
-    rgw_access_user_data = json.loads(rgw_access_user_resp.read())
+    rgw_access_user_data = json.loads(six.ensure_str(rgw_access_user_resp.read()))
     rgw_user_id = rgw_access_user_data['access']['user']['id']
 
     if 'secrets' in cconfig:
@@ -309,7 +310,7 @@ def create_secrets(ctx, config):
                     token_resp.status < 300):
                 raise Exception("Cannot authenticate user "+secret["username"]+" for secret creation")
 
-            token_data = json.loads(token_resp.read())
+            token_data = json.loads(six.ensure_str(token_resp.read()))
             token_id = token_data['access']['token']['id']
 
             key1_json = json.dumps(
@@ -342,7 +343,7 @@ def create_secrets(ctx, config):
             if not (barbican_sec_resp.status >= 200 and
                     barbican_sec_resp.status < 300):
                 raise Exception("Cannot create secret")
-            barbican_data = json.loads(barbican_sec_resp.read())
+            barbican_data = json.loads(six.ensure_str(barbican_sec_resp.read()))
             if 'secret_ref' not in barbican_data:
                 raise ValueError("Malformed secret creation response")
             secret_ref = barbican_data["secret_ref"]