Commit 72f0f7fd authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix the ssh change which breaks remote ssh commands

Explanation: since we use lists and not a string, every argument we give
is passed unchanged to the remote shell. So, for example, passing
'/etc/init.d/ganeti restart' to the remote shell, it will try to run the
path /etc/init.d/ganeti\ restart. With the s space included. This
breaks, for example, gnt-node add and gnt-cluster command.

The original problem with the backup routines that led to the "'" change
is that they use a plain " ".join(list), but we don't need to quote the
whole ssh remote command for this. We can simply use the existing
utils.ShellQuoteCmd(list) which does the proper quoting of the ';' or
'&&' metacharacters.

With this change, both gnt-node add, gnt-cluster command and
export/import work.

This also improves the error-handling behaviour of one cat command by
making it conditional on the preceding mkdir.

Reviewed-by: ultrotter
parent 4e5e8bfc
......@@ -1022,14 +1022,14 @@ def ExportSnapshot(disk, dest_node, instance):
comprcmd = "gzip"
destcmd = utils.BuildShellCmd("mkdir -p %s; cat > %s/%s",
destcmd = utils.BuildShellCmd("mkdir -p %s && cat > %s/%s",
destdir, destdir, destfile)
remotecmd = ssh.BuildSSHCmd(dest_node, 'root', destcmd)
# all commands have been checked, so we're safe to combine them
command = '|'.join([expcmd, comprcmd, ' '.join(remotecmd)])
command = '|'.join([expcmd, comprcmd, utils.ShellQuoteArgs(remotecmd)])
result = utils.RunCmd(command)
......@@ -1178,7 +1178,7 @@ def ImportOSIntoInstance(instance, os_disk, swap_disk, src_node, src_image):
real_os_dev.dev_path, real_swap_dev.dev_path,
command = '|'.join([' '.join(remotecmd), comprcmd, impcmd])
command = '|'.join([utils.ShellQuoteArgs(remotecmd), comprcmd, impcmd])
result = utils.RunCmd(command)
......@@ -54,6 +54,7 @@ ASK_KEY_OPTS = [
def BuildSSHCmd(hostname, user, command, batch=True, ask_key=False):
"""Build an ssh string to execute a command on a remote node.
......@@ -78,7 +79,7 @@ def BuildSSHCmd(hostname, user, command, batch=True, ask_key=False):
elif ask_key:
argv.extend(["%s@%s" % (user, hostname), "'%s'" % command])
argv.extend(["%s@%s" % (user, hostname), command])
return argv
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment