Commit 7e3c1da6 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

import-export daemon: Allow changing compression method



For example, exports on the same node shouldn't be compressed.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 39019f91
......@@ -381,12 +381,20 @@ def GetTransportCommand(mode, socat_stderr_fd):
(utils.ShellQuoteArgs(GetSocatCommand(mode)),
socat_stderr_fd))
# TODO: Make compression configurable
compr = options.compress
assert compr in constants.IEC_ALL
if mode == constants.IEM_IMPORT:
transport_cmd = "%s | gunzip -c" % socat_cmd
if compr == constants.IEC_GZIP:
transport_cmd = "%s | gunzip -c" % socat_cmd
else:
transport_cmd = socat_cmd
elif mode == constants.IEM_EXPORT:
transport_cmd = "gzip -c | %s" % socat_cmd
if compr == constants.IEC_GZIP:
transport_cmd = "gzip -c | %s" % socat_cmd
else:
transport_cmd = socat_cmd
else:
raise Error("Invalid mode")
......@@ -554,6 +562,10 @@ def ParseOptions():
parser.add_option("--connect-timeout", dest="connect_timeout", action="store",
type="int", default=DEFAULT_CONNECT_TIMEOUT,
help="Timeout for connection to be established (seconds)")
parser.add_option("--compress", dest="compress", action="store",
type="choice", help="Compression method",
metavar="[%s]" % "|".join(constants.IEC_ALL),
choices=list(constants.IEC_ALL), default=constants.IEC_GZIP)
parser.add_option("--cmd-prefix", dest="cmd_prefix", action="store",
type="string", help="Command prefix")
parser.add_option("--cmd-suffix", dest="cmd_suffix", action="store",
......
......@@ -210,6 +210,14 @@ IMPORT_EXPORT_DAEMON = _autoconf.PKGLIBDIR + "/import-export"
IEM_IMPORT = "import"
IEM_EXPORT = "export"
# Import/export transport compression
IEC_NONE = "none"
IEC_GZIP = "gzip"
IEC_ALL = frozenset([
IEC_NONE,
IEC_GZIP,
])
# Import/export I/O
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>'
IEIO_FILE = "file"
......
......@@ -87,6 +87,7 @@ cmd_prefix=
cmd_suffix=
connect_timeout=10
connect_retries=1
compress=gzip
$impexpd >/dev/null 2>&1 &&
err "daemon-util succeeded without parameters"
......@@ -100,6 +101,9 @@ $impexpd $src_statusfile >/dev/null 2>&1 &&
$impexpd $src_statusfile invalidmode >/dev/null 2>&1 &&
err "daemon-util succeeded with invalid mode"
$impexpd $src_statusfile import --compression=rot13 >/dev/null 2>&1 &&
err "daemon-util succeeded with invalid compression"
cat $(get_testfile proc_drbd8.txt) $(get_testfile cert1.pem) > $testdata
impexpd_helper() {
......@@ -140,7 +144,8 @@ do_export_to_port() {
--key=$src_x509 --cert=$src_x509 --ca=$dst_x509 \
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \
--connect-timeout=$connect_timeout \
--connect-retries=$connect_retries
--connect-retries=$connect_retries \
--compress=$compress
}
do_import() {
......@@ -149,7 +154,8 @@ do_import() {
--key=$dst_x509 --cert=$dst_x509 --ca=$src_x509 \
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \
--connect-timeout=$connect_timeout \
--connect-retries=$connect_retries
--connect-retries=$connect_retries \
--compress=$compress
}
upto 'Generate X509 certificates and keys'
......@@ -233,4 +239,28 @@ do_import &>$dst_output & imppid=$!
checkpids $exppid $imppid || \
err 'Listening with timeout failed when it should not'
upto 'No compression'
reset_status
compress=none do_import > $statusdir/recv-nocompr 2>$dst_output & imppid=$!
{ write_data | compress=none do_export; } &>$src_output & exppid=$!
checkpids $exppid $imppid || err 'An error occurred'
cmp $testdata $statusdir/recv-nocompr || \
err 'Received data does not match input'
upto 'Compression mismatch A'
reset_status
compress=none do_import > $statusdir/recv-miscompr 2>$dst_output & imppid=$!
{ write_data | compress=gzip do_export; } &>$src_output & exppid=$!
checkpids $exppid $imppid || err 'An error occurred'
cmp -s $testdata $statusdir/recv-miscompr && \
err 'Received data matches input when it should not'
upto 'Compression mismatch B'
reset_status
compress=gzip do_import > $statusdir/recv-miscompr2 2>$dst_output & imppid=$!
{ write_data | compress=none do_export; } &>$src_output & exppid=$!
checkpids $exppid $imppid && err 'Did not fail when it should'
cmp -s $testdata $statusdir/recv-miscompr2 && \
err 'Received data matches input when it should not'
exit 0
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