From 50eaa5da7d61e5b5f3078cde89cd77a0c202a1bb Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Thu, 21 Feb 2013 15:10:59 +0100
Subject: [PATCH] qa_utils: Virtual cluster support for SSH commands
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/qa/qa_utils.py b/qa/qa_utils.py
index 9533c280b..d9389edbc 100644
--- a/qa/qa_utils.py
+++ b/qa/qa_utils.py
@@ -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
 
-- 
GitLab