Skip to content
Snippets Groups Projects
Commit fbb6b864 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

import/export daemon: Simplify command building


Instead of appending strings, stage parts in a list. Building the "dd"
command is moved to a separate function.

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 0559f745
No related branches found
No related tags found
No related merge requests found
......@@ -197,14 +197,10 @@ class CommandBuilder(object):
",".join(addr1), ",".join(addr2)
]
def _GetTransportCommand(self):
"""Returns the command for the transport part of the daemon.
def _GetDdCommand(self):
"""Returns the command for measuring throughput.
"""
socat_cmd = ("%s 2>&%d" %
(utils.ShellQuoteArgs(self._GetSocatCommand()),
self._socat_stderr_fd))
dd_cmd = StringIO()
# Setting LC_ALL since we want to parse the output and explicitely
# redirecting stdin, as the background process (dd) would have /dev/null as
......@@ -216,32 +212,46 @@ class CommandBuilder(object):
# And wait for dd
dd_cmd.write(" wait $pid;")
dd_cmd.write(" }")
return dd_cmd.getvalue()
def _GetTransportCommand(self):
"""Returns the command for the transport part of the daemon.
"""
socat_cmd = ("%s 2>&%d" %
(utils.ShellQuoteArgs(self._GetSocatCommand()),
self._socat_stderr_fd))
dd_cmd = self._GetDdCommand()
compr = self._opts.compress
assert compr in constants.IEC_ALL
parts = []
if self._mode == constants.IEM_IMPORT:
parts.append(socat_cmd)
if compr == constants.IEC_GZIP:
transport_cmd = "%s | gunzip -c" % socat_cmd
else:
transport_cmd = socat_cmd
parts.append("gunzip -c")
parts.append(dd_cmd)
transport_cmd += " | %s" % dd_cmd.getvalue()
elif self._mode == constants.IEM_EXPORT:
parts.append(dd_cmd)
if compr == constants.IEC_GZIP:
transport_cmd = "gzip -c | %s" % socat_cmd
else:
transport_cmd = socat_cmd
parts.append("gzip -c")
parts.append(socat_cmd)
transport_cmd = "%s | %s" % (dd_cmd.getvalue(), transport_cmd)
else:
raise errors.GenericError("Invalid mode '%s'" % self._mode)
# TODO: Run transport as separate user
# The transport uses its own shell to simplify running it as a separate user
# in the future.
return self.GetBashCommand(transport_cmd)
return self.GetBashCommand(" | ".join(parts))
def GetCommand(self):
"""Returns the complete child process command.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment