]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa/vstart_runner: Add get_file and write_file equivalents to the LocalRemoteProcess...
authorConnor Fawcett <connorfa@uk.ibm.com>
Tue, 26 Nov 2024 04:01:05 +0000 (04:01 +0000)
committerConnor Fawcett <connorfa@uk.ibm.com>
Mon, 26 May 2025 23:37:25 +0000 (00:37 +0100)
Signed-off-by: Connor Fawcett <connorfa@uk.ibm.com>
qa/tasks/vstart_runner.py

index 2ed2143133064159f9b2f0f6e1980ed78419a3e7..755ea642d95da27845c191f8d30f63c37a685aea 100644 (file)
@@ -354,10 +354,20 @@ class LocalRemote(RemoteShell):
             self._hostname = 'localhost'
         return self._hostname
 
-    def get_file(self, path, sudo, dest_dir):
-        tmpfile = tempfile.NamedTemporaryFile(delete=False).name
-        shutil.copy(path, tmpfile)
-        return tmpfile
+    def get_file(self, path, sudo=False, dest_dir='/tmp'):
+        if dest_dir == '/tmp':
+            # If we're storing in /tmp, generate a unique filename
+            (_fd, local_path) = tempfile.mkstemp(dir=dest_dir)
+        else:
+            # If we are storing somewhere other than /tmp, use the original
+            # filename
+            local_path = os.path.join(dest_dir, path.split(os.path.sep)[-1])
+        try:
+            shutil.copy(path, local_path)
+        except shutil.SameFileError:
+            log.info("path and local_path refer to the same file")
+            pass
+        return local_path
 
     # XXX: This method ignores the error raised when src and dst are
     # holding same path. For teuthology, same path still represents
@@ -368,6 +378,26 @@ class LocalRemote(RemoteShell):
         except shutil.SameFileError:
             pass
 
+    def write_file(self, path, data, owner=None,
+                   mode='0644', mkdir=False, append=False, sudo=False):
+        dd = 'sudo dd' if sudo else 'dd'
+        args = dd + ' of=' + path
+        if append:
+            args += ' conv=notrunc oflag=append'
+        if mkdir:
+            mkdirp = 'sudo mkdir -p' if sudo else 'mkdir -p'
+            dirpath = os.path.dirname(path)
+            if dirpath:
+                args = mkdirp + ' ' + dirpath + '\n' + args
+        if mode:
+            chmod = 'sudo chmod' if sudo else 'chmod'
+            args += '\n' + chmod + ' ' + mode + ' ' + path
+        if owner:
+            chown = 'sudo chown' if sudo else 'chown'
+            args += '\n' + chown + ' ' + owner + ' ' + path
+        args = 'set -ex' + '\n' + args
+        self.run(args=args, stdin=data, quiet=True)
+
     def _expand_teuthology_tools(self, args):
         assert isinstance(args, list)
         for tool in self.rewrite_helper_tools: