From: Kefu Chai Date: Sun, 5 Apr 2020 13:45:51 +0000 (+0800) Subject: qa/tasks/cephfs: allow caller to use BytesIO when calling rados() X-Git-Tag: v16.1.0~2648^2~30 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=20dafc6d52acc4af235dc061fa67ecd617a90159;p=ceph.git qa/tasks/cephfs: allow caller to use BytesIO when calling rados() when the caller expects binary data, it should pass BytesIO as stdout. this change shold address the failure of ``` 2020-04-05T12:47:25.335 INFO:tasks.cephfs_test_runner:====================================================================== 2020-04-05T12:47:25.336 INFO:tasks.cephfs_test_runner:ERROR: test_apply_tag (tasks.cephfs.test_forward_scrub.TestForwardScrub) 2020-04-05T12:47:25.336 INFO:tasks.cephfs_test_runner:---------------------------------------------------------------------- 2020-04-05T12:47:25.336 INFO:tasks.cephfs_test_runner:Traceback (most recent call last): 2020-04-05T12:47:25.337 INFO:tasks.cephfs_test_runner: File "/home/teuthworker/src/github.com_tchaikov_ceph_wip-qa-py3/qa/tasks/cephfs/test_forward_scrub.py", line 75, in test_apply_tag 2020-04-05T12:47:25.337 INFO:tasks.cephfs_test_runner: self.assertTagged(inos[dirpath], tag, self.fs.get_metadata_pool_name()) 2020-04-05T12:47:25.337 INFO:tasks.cephfs_test_runner: File "/home/teuthworker/src/github.com_tchaikov_ceph_wip-qa-py3/qa/tasks/cephfs/test_forward_scrub.py", line 98, in assertTagged 2020-04-05T12:47:25.338 INFO:tasks.cephfs_test_runner: "scrub_tag" 2020-04-05T12:47:25.338 INFO:tasks.cephfs_test_runner: File "/home/teuthworker/src/github.com_tchaikov_ceph_wip-qa-py3/qa/tasks/cephfs/test_forward_scrub.py", line 35, in _read_str_xattr 2020-04-05T12:47:25.339 INFO:tasks.cephfs_test_runner: strlen = struct.unpack('i', output[0:4])[0] 2020-04-05T12:47:25.339 INFO:tasks.cephfs_test_runner:TypeError: a bytes-like object is required, not 'str' ``` Signed-off-by: Kefu Chai --- diff --git a/qa/tasks/cephfs/filesystem.py b/qa/tasks/cephfs/filesystem.py index dc811fe8d47e..d7aa80093f0e 100644 --- a/qa/tasks/cephfs/filesystem.py +++ b/qa/tasks/cephfs/filesystem.py @@ -11,6 +11,7 @@ import random import traceback from io import BytesIO +from six import StringIO from teuthology.exceptions import CommandFailedError from teuthology import misc @@ -1230,7 +1231,8 @@ class Filesystem(MDSCluster): return True def rados(self, args, pool=None, namespace=None, stdin_data=None, - stdin_file=None): + stdin_file=None, + stdout_data=None): """ Call into the `rados` CLI from an MDS """ @@ -1251,9 +1253,13 @@ class Filesystem(MDSCluster): if stdin_file is not None: args = ["bash", "-c", "cat " + stdin_file + " | " + " ".join(args)] + if stdout_data is None: + stdout_data = StringIO() - output = remote.sh(args, stdin=stdin_data) - return output.strip() + p = remote.run(args=args, + stdin=stdin_data, + stdout=stdout_data) + return p.stdout.getvalue().strip() def list_dirfrag(self, dir_ino): """ diff --git a/qa/tasks/cephfs/test_data_scan.py b/qa/tasks/cephfs/test_data_scan.py index 481ef0e36b46..dcc48a2a2ff6 100644 --- a/qa/tasks/cephfs/test_data_scan.py +++ b/qa/tasks/cephfs/test_data_scan.py @@ -7,9 +7,11 @@ import json import logging import os import time -from textwrap import dedent import traceback + +from io import BytesIO from collections import namedtuple, defaultdict +from textwrap import dedent from teuthology.orchestra.run import CommandFailedError from tasks.cephfs.cephfs_test_case import CephFSTestCase, for_teuthology @@ -565,7 +567,8 @@ class TestDataScan(CephFSTestCase): # introduce duplicated primary link file1_key = "file1_head" self.assertIn(file1_key, dirfrag1_keys) - file1_omap_data = self.fs.rados(["getomapval", dirfrag1_oid, file1_key, '-']) + file1_omap_data = self.fs.rados(["getomapval", dirfrag1_oid, file1_key, '-'], + stdout_data=BytesIO()) self.fs.rados(["setomapval", dirfrag2_oid, file1_key], stdin_data=file1_omap_data) self.assertIn(file1_key, self._dirfrag_keys(dirfrag2_oid)) diff --git a/qa/tasks/cephfs/test_forward_scrub.py b/qa/tasks/cephfs/test_forward_scrub.py index 6eb31b244df4..94e99d3101d0 100644 --- a/qa/tasks/cephfs/test_forward_scrub.py +++ b/qa/tasks/cephfs/test_forward_scrub.py @@ -11,6 +11,7 @@ import json import logging from collections import namedtuple +from io import BytesIO from textwrap import dedent from teuthology.orchestra.run import CommandFailedError @@ -31,7 +32,8 @@ class TestForwardScrub(CephFSTestCase): """ Read a ceph-encoded string from a rados xattr """ - output = self.fs.rados(["getxattr", obj, attr], pool=pool) + output = self.fs.rados(["getxattr", obj, attr], pool=pool, + stdout_data=BytesIO()) strlen = struct.unpack('i', output[0:4])[0] return output[4:(4 + strlen)]