From 3b3689901a96be2c2e8b04a0d5748a18cdf98efd Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Wed, 1 Apr 2020 16:51:06 +0530 Subject: [PATCH] qa/cephfs: add methods to read/write on CephFS mounts Signed-off-by: Rishabh Dave (cherry picked from commit 3f0284f272231c3b62b0f3f201cbaaecfa405bcd) Conflicts: qa/tasks/cephfs/mount.py: get_file and IP module is not present in nautilus --- qa/tasks/cephfs/mount.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/qa/tasks/cephfs/mount.py b/qa/tasks/cephfs/mount.py index 190ac1e07a7c1..d486f1b68cd0b 100644 --- a/qa/tasks/cephfs/mount.py +++ b/qa/tasks/cephfs/mount.py @@ -8,6 +8,7 @@ import time from six import StringIO from textwrap import dedent import os +from teuthology.misc import sudo_write_file from teuthology.orchestra import run from teuthology.orchestra.run import CommandFailedError, ConnectionLostError, Raw from tasks.cephfs.filesystem import Filesystem @@ -142,6 +143,29 @@ class CephFSMount(object): if r.exitstatus != 0: raise RuntimeError("Expected file {0} not found".format(suffix)) + def write_file(self, path, data, perms=None): + """ + Write the given data at the given path and set the given perms to the + file on the path. + """ + if path.find(self.mountpoint) == -1: + path = os.path.join(self.mountpoint, path) + + sudo_write_file(self.client_remote, path, data) + + if perms: + self.run_shell(args=f'chmod {perms} {path}') + + def read_file(self, path): + """ + Return the data from the file on given path. + """ + if path.find(self.mountpoint) == -1: + path = os.path.join(self.mountpoint, path) + + return self.run_shell(args=['sudo', 'cat', path], omit_sudo=False).\ + stdout.getvalue().strip() + def create_destroy(self): assert(self.is_mounted()) -- 2.39.5