]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/cephfs: add methods to read/write on CephFS mounts
authorRishabh Dave <ridave@redhat.com>
Wed, 1 Apr 2020 11:21:06 +0000 (16:51 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 10 Sep 2020 18:27:15 +0000 (23:57 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
qa/tasks/cephfs/mount.py

index 13dd1412241e6d0a1796f4ef5e0da9c05d5434da..fc70edd77fb87ef8512fe31bcfc172f3d5ca9636 100644 (file)
@@ -10,7 +10,7 @@ from contextlib import contextmanager
 from textwrap import dedent
 from IPy import IP
 
-from teuthology.misc import get_file
+from teuthology.misc import get_file, sudo_write_file
 from teuthology.orchestra import run
 from teuthology.orchestra.run import CommandFailedError, ConnectionLostError, Raw
 
@@ -614,6 +614,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.hostfs_mntpt) == -1:
+            path = os.path.join(self.hostfs_mntpt, 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.hostfs_mntpt) == -1:
+            path = os.path.join(self.hostfs_mntpt, path)
+
+        return self.run_shell(args=['sudo', 'cat', path], omit_sudo=False).\
+            stdout.getvalue().strip()
+
     def create_destroy(self):
         assert(self.is_mounted())