Revision 7e3c1da6
b/daemons/import-export | ||
---|---|---|
381 | 381 |
(utils.ShellQuoteArgs(GetSocatCommand(mode)), |
382 | 382 |
socat_stderr_fd)) |
383 | 383 |
|
384 |
# TODO: Make compression configurable |
|
384 |
compr = options.compress |
|
385 |
|
|
386 |
assert compr in constants.IEC_ALL |
|
385 | 387 |
|
386 | 388 |
if mode == constants.IEM_IMPORT: |
387 |
transport_cmd = "%s | gunzip -c" % socat_cmd |
|
389 |
if compr == constants.IEC_GZIP: |
|
390 |
transport_cmd = "%s | gunzip -c" % socat_cmd |
|
391 |
else: |
|
392 |
transport_cmd = socat_cmd |
|
388 | 393 |
elif mode == constants.IEM_EXPORT: |
389 |
transport_cmd = "gzip -c | %s" % socat_cmd |
|
394 |
if compr == constants.IEC_GZIP: |
|
395 |
transport_cmd = "gzip -c | %s" % socat_cmd |
|
396 |
else: |
|
397 |
transport_cmd = socat_cmd |
|
390 | 398 |
else: |
391 | 399 |
raise Error("Invalid mode") |
392 | 400 |
|
... | ... | |
554 | 562 |
parser.add_option("--connect-timeout", dest="connect_timeout", action="store", |
555 | 563 |
type="int", default=DEFAULT_CONNECT_TIMEOUT, |
556 | 564 |
help="Timeout for connection to be established (seconds)") |
565 |
parser.add_option("--compress", dest="compress", action="store", |
|
566 |
type="choice", help="Compression method", |
|
567 |
metavar="[%s]" % "|".join(constants.IEC_ALL), |
|
568 |
choices=list(constants.IEC_ALL), default=constants.IEC_GZIP) |
|
557 | 569 |
parser.add_option("--cmd-prefix", dest="cmd_prefix", action="store", |
558 | 570 |
type="string", help="Command prefix") |
559 | 571 |
parser.add_option("--cmd-suffix", dest="cmd_suffix", action="store", |
b/lib/constants.py | ||
---|---|---|
210 | 210 |
IEM_IMPORT = "import" |
211 | 211 |
IEM_EXPORT = "export" |
212 | 212 |
|
213 |
# Import/export transport compression |
|
214 |
IEC_NONE = "none" |
|
215 |
IEC_GZIP = "gzip" |
|
216 |
IEC_ALL = frozenset([ |
|
217 |
IEC_NONE, |
|
218 |
IEC_GZIP, |
|
219 |
]) |
|
220 |
|
|
213 | 221 |
# Import/export I/O |
214 | 222 |
# Direct file I/O, equivalent to a shell's I/O redirection using '<' or '>' |
215 | 223 |
IEIO_FILE = "file" |
b/test/import-export_unittest.bash | ||
---|---|---|
87 | 87 |
cmd_suffix= |
88 | 88 |
connect_timeout=10 |
89 | 89 |
connect_retries=1 |
90 |
compress=gzip |
|
90 | 91 |
|
91 | 92 |
$impexpd >/dev/null 2>&1 && |
92 | 93 |
err "daemon-util succeeded without parameters" |
... | ... | |
100 | 101 |
$impexpd $src_statusfile invalidmode >/dev/null 2>&1 && |
101 | 102 |
err "daemon-util succeeded with invalid mode" |
102 | 103 |
|
104 |
$impexpd $src_statusfile import --compression=rot13 >/dev/null 2>&1 && |
|
105 |
err "daemon-util succeeded with invalid compression" |
|
106 |
|
|
103 | 107 |
cat $(get_testfile proc_drbd8.txt) $(get_testfile cert1.pem) > $testdata |
104 | 108 |
|
105 | 109 |
impexpd_helper() { |
... | ... | |
140 | 144 |
--key=$src_x509 --cert=$src_x509 --ca=$dst_x509 \ |
141 | 145 |
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \ |
142 | 146 |
--connect-timeout=$connect_timeout \ |
143 |
--connect-retries=$connect_retries |
|
147 |
--connect-retries=$connect_retries \ |
|
148 |
--compress=$compress |
|
144 | 149 |
} |
145 | 150 |
|
146 | 151 |
do_import() { |
... | ... | |
149 | 154 |
--key=$dst_x509 --cert=$dst_x509 --ca=$src_x509 \ |
150 | 155 |
--cmd-prefix="$cmd_prefix" --cmd-suffix="$cmd_suffix" \ |
151 | 156 |
--connect-timeout=$connect_timeout \ |
152 |
--connect-retries=$connect_retries |
|
157 |
--connect-retries=$connect_retries \ |
|
158 |
--compress=$compress |
|
153 | 159 |
} |
154 | 160 |
|
155 | 161 |
upto 'Generate X509 certificates and keys' |
... | ... | |
233 | 239 |
checkpids $exppid $imppid || \ |
234 | 240 |
err 'Listening with timeout failed when it should not' |
235 | 241 |
|
242 |
upto 'No compression' |
|
243 |
reset_status |
|
244 |
compress=none do_import > $statusdir/recv-nocompr 2>$dst_output & imppid=$! |
|
245 |
{ write_data | compress=none do_export; } &>$src_output & exppid=$! |
|
246 |
checkpids $exppid $imppid || err 'An error occurred' |
|
247 |
cmp $testdata $statusdir/recv-nocompr || \ |
|
248 |
err 'Received data does not match input' |
|
249 |
|
|
250 |
upto 'Compression mismatch A' |
|
251 |
reset_status |
|
252 |
compress=none do_import > $statusdir/recv-miscompr 2>$dst_output & imppid=$! |
|
253 |
{ write_data | compress=gzip do_export; } &>$src_output & exppid=$! |
|
254 |
checkpids $exppid $imppid || err 'An error occurred' |
|
255 |
cmp -s $testdata $statusdir/recv-miscompr && \ |
|
256 |
err 'Received data matches input when it should not' |
|
257 |
|
|
258 |
upto 'Compression mismatch B' |
|
259 |
reset_status |
|
260 |
compress=gzip do_import > $statusdir/recv-miscompr2 2>$dst_output & imppid=$! |
|
261 |
{ write_data | compress=none do_export; } &>$src_output & exppid=$! |
|
262 |
checkpids $exppid $imppid && err 'Did not fail when it should' |
|
263 |
cmp -s $testdata $statusdir/recv-miscompr2 && \ |
|
264 |
err 'Received data matches input when it should not' |
|
265 |
|
|
236 | 266 |
exit 0 |
Also available in: Unified diff