From: Kefu Chai Date: Mon, 27 Apr 2020 03:04:21 +0000 (+0800) Subject: qa/tasks: decode bytes returned by base64.b64encode() X-Git-Tag: v14.2.10~17^2~36 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7d5053e800a39b00d666cee421beed1f801a454a;p=ceph.git qa/tasks: decode bytes returned by base64.b64encode() we use the return value from `base64.b64encode()` as a string, this works in python2, but in python3, instead of a string, `base64.b64encode()` returns bytes. so for instance, if we try to compose command line arguments using `pipes.quote()` by passing a byte instance, we will have ``` TypeError: cannot use a string pattern on a bytes-like object ``` in this change, the retval is always decoded using ASCII, because base64 only returns ASCII strings when encoding. this change is not cherry-picked from master, as the changed files do not exist in master anymore. Signed-off-by: Kefu Chai --- diff --git a/qa/tasks/s3readwrite.py b/qa/tasks/s3readwrite.py index b70eb83b7a3f..89e6ff835da5 100644 --- a/qa/tasks/s3readwrite.py +++ b/qa/tasks/s3readwrite.py @@ -78,7 +78,7 @@ def _config_user(s3tests_conf, section, user): s3tests_conf[section].setdefault('email', '{user}+test@test.test'.format(user=user)) s3tests_conf[section].setdefault('display_name', 'Mr. {user}'.format(user=user)) s3tests_conf[section].setdefault('access_key', ''.join(random.choice(string.uppercase) for i in range(20))) - s3tests_conf[section].setdefault('secret_key', base64.b64encode(os.urandom(40))) + s3tests_conf[section].setdefault('secret_key', base64.b64encode(os.urandom(40)).decode('ascii')) @contextlib.contextmanager def create_users(ctx, config): diff --git a/qa/tasks/s3roundtrip.py b/qa/tasks/s3roundtrip.py index 9b27b4ae86d6..97c0f71151cd 100644 --- a/qa/tasks/s3roundtrip.py +++ b/qa/tasks/s3roundtrip.py @@ -78,7 +78,7 @@ def _config_user(s3tests_conf, section, user): s3tests_conf[section].setdefault('email', '{user}+test@test.test'.format(user=user)) s3tests_conf[section].setdefault('display_name', 'Mr. {user}'.format(user=user)) s3tests_conf[section].setdefault('access_key', ''.join(random.choice(string.uppercase) for i in range(20))) - s3tests_conf[section].setdefault('secret_key', base64.b64encode(os.urandom(40))) + s3tests_conf[section].setdefault('secret_key', base64.b64encode(os.urandom(40)).decode('ascii')) @contextlib.contextmanager def create_users(ctx, config): diff --git a/qa/tasks/swift.py b/qa/tasks/swift.py index 83a9d4c509b9..be19937bf274 100644 --- a/qa/tasks/swift.py +++ b/qa/tasks/swift.py @@ -60,7 +60,7 @@ def _config_user(testswift_conf, account, user, suffix): testswift_conf['func_test'].setdefault('username{s}'.format(s=suffix), user) testswift_conf['func_test'].setdefault('email{s}'.format(s=suffix), '{account}+test@test.test'.format(account=account)) testswift_conf['func_test'].setdefault('display_name{s}'.format(s=suffix), 'Mr. {account} {user}'.format(account=account, user=user)) - testswift_conf['func_test'].setdefault('password{s}'.format(s=suffix), base64.b64encode(os.urandom(40))) + testswift_conf['func_test'].setdefault('password{s}'.format(s=suffix), base64.b64encode(os.urandom(40)).decode('ascii')) @contextlib.contextmanager def create_users(ctx, config):