]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
openstack: upload absolute paths to remote teuthology machine
authorNathan Cutler <ncutler@suse.com>
Wed, 15 Mar 2017 14:12:37 +0000 (15:12 +0100)
committerKyr Shatskyy <kyrylo.shatskyy@gmail.com>
Thu, 18 Oct 2018 22:52:44 +0000 (00:52 +0200)
If any absolute paths are given on the teuthology-openstack command line,
assume they are local YAML files and upload them to the remote teuthology
machine before running teuthology-suite.

If the local YAML file (absolute path) is PATH, the remote
path will be /home/ubuntu/yaml/$PATH. The remote file is clobbered if
it already exists.

Fixes: https://github.com/SUSE/teuthology/issues/46
Fixes: https://github.com/SUSE/teuthology/issues/56
Signed-off-by: Nathan Cutler <ncutler@suse.com>
teuthology/openstack/__init__.py

index 0b754627eb813f90f7791aa3a1ba6e6305441c29..df2e1235097fe9e14b8ec6120e258f9df002a515 100644 (file)
@@ -551,6 +551,59 @@ class TeuthologyOpenStack(OpenStack):
                 self.teardown()
         return exit_code
 
+    def _upload_yaml_file(self, fp):
+        """
+        Given an absolute path fp, assume it is a YAML file existing
+        on the local machine and upload it to the remote teuthology machine
+        (see https://github.com/SUSE/teuthology/issues/56 for details)
+        """
+        f = open(fp, 'r') # will throw exception on failure
+        f.close()
+        log.info("Detected local YAML file {}".format(fp))
+        machine = self.username + "@" + self.instance.get_floating_ip_or_ip()
+
+        def ssh_command(s):
+            return "ssh -i {k} {m} sh -c \\\"{s}\\\"".format(
+                k=self.key_filename,
+                m=machine,
+                s=s,
+            )
+
+        log.info("Uploading local file {} to teuthology machine".format(fp))
+        remote_fp=os.path.normpath(
+            '/home/{un}/yaml/{fp}'.format(
+                un=self.username,
+                fp=fp,
+            )
+        )
+        command = ssh_command("stat {aug_fp}".format(
+            aug_fp=remote_fp,
+        ))
+        try:
+            misc.sh(command)
+        except:
+            pass
+        else:
+            log.warning(
+                ('{fp} probably already exists remotely as {aug_fp}; '
+                 'the remote one will be clobbered').format(
+                fp=fp,
+                aug_fp=remote_fp,
+            ))
+        remote_dn=os.path.dirname(remote_fp)
+        command = ssh_command("mkdir -p {aug_dn}".format(
+            aug_dn=remote_dn,
+        ))
+        misc.sh(command) # will throw exception on failure
+        command = "scp -i {k} {yamlfile} {m}:{dn}".format(
+            k=self.key_filename,
+            yamlfile=fp,
+            m=machine,
+            dn=remote_dn,
+        )
+        misc.sh(command) # will throw exception on failure
+        return remote_fp
+
     def run_suite(self):
         """
         Delegate running teuthology-suite to the OpenStack instance
@@ -573,6 +626,10 @@ class TeuthologyOpenStack(OpenStack):
             elif original_argv[0] in ('--teardown',
                                       '--upload'):
                 del original_argv[0]
+            elif os.path.isabs(original_argv[0]):
+                remote_path = self._upload_yaml_file(original_argv[0])
+                argv.append(remote_path)
+                original_argv.pop(0)
             else:
                 argv.append(original_argv.pop(0))
         #