]> git-server-git.apps.pok.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)
committerKotresh HR <khiremat@redhat.com>
Fri, 5 Mar 2021 06:50:32 +0000 (12:20 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
(cherry picked from commit 3f0284f272231c3b62b0f3f201cbaaecfa405bcd)

Conflicts:
    qa/tasks/cephfs/mount.py: get_file and IP module is not present in
      octopus

qa/tasks/cephfs/mount.py

index 7d9edda2769b6fc23d4e6e392d6c4d1e21ae82a3..e4d6d659e2c4d3509e1191d7bb16c6fdfe29382e 100644 (file)
@@ -7,6 +7,8 @@ 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
@@ -173,6 +175,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())