qa_utils: Virtual cluster support for SSH commands
authorMichael Hanselmann <hansmi@google.com>
Thu, 21 Feb 2013 14:10:59 +0000 (15:10 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 27 Feb 2013 13:58:40 +0000 (14:58 +0100)
In virtual clusters, all “gnt-*” and “ganeti-*” commands require
environment variables to be set for the virtual cluster root directory
and node name. The “cmd” script generated by “vcluster-setup” is a
wrapper setting those variables.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Bernardo Dal Seno <bdalseno@google.com>

qa/qa_utils.py

index 9533c28..d9389ed 100644 (file)
@@ -41,6 +41,7 @@ from ganeti import compat
 from ganeti import constants
 from ganeti import ht
 from ganeti import pathutils
+from ganeti import vcluster
 
 import qa_config
 import qa_error
@@ -250,9 +251,25 @@ def GetSSHCommand(node, cmd, strict=True, opts=None, tty=None):
     spath = _MULTIPLEXERS[node][0]
     args.append("-oControlPath=%s" % spath)
     args.append("-oControlMaster=no")
-  args.append(node)
-  if cmd:
-    args.append(cmd)
+
+  (vcluster_master, vcluster_basedir) = \
+    qa_config.GetVclusterSettings()
+
+  if vcluster_master:
+    args.append(vcluster_master)
+    args.append("%s/%s/cmd" % (vcluster_basedir, node))
+
+    if cmd:
+      # For virtual clusters the whole command must be wrapped using the "cmd"
+      # script, as that script sets a number of environment variables. If the
+      # command contains shell meta characters the whole command needs to be
+      # quoted.
+      args.append(utils.ShellQuote(cmd))
+  else:
+    args.append(node)
+
+    if cmd:
+      args.append(cmd)
 
   return args