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

Improve import-export unittest a bit


- Increase timeouts from 10 to 30 seconds (this still breaks when the
  machine is busy, e.g. using bonnie++)
- Depend on only one timeout per test instead of three
- Reset variables before each test

Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 4dd97aa1
No related branches found
No related tags found
No related merge requests found
...@@ -32,8 +32,8 @@ from ganeti import objects ...@@ -32,8 +32,8 @@ from ganeti import objects
from ganeti import serializer from ganeti import serializer
RETRY_INTERVAL = 0.1 RETRY_INTERVAL = (0.1, 1.1, 1)
TIMEOUT = int(os.getenv("TIMEOUT", 10)) TIMEOUT = int(os.getenv("TIMEOUT", 30))
VALIDITY = int(os.getenv("VALIDITY", 1)) VALIDITY = int(os.getenv("VALIDITY", 1))
......
...@@ -88,19 +88,12 @@ src_x509=$statusdir/src.pem ...@@ -88,19 +88,12 @@ src_x509=$statusdir/src.pem
dst_statusfile=$statusdir/dst.status dst_statusfile=$statusdir/dst.status
dst_output=$statusdir/dst.output dst_output=$statusdir/dst.output
dst_x509=$statusdir/dst.pem dst_x509=$statusdir/dst.pem
dst_portfile=$statusdir/dst.port
other_x509=$statusdir/other.pem other_x509=$statusdir/other.pem
testdata=$statusdir/data1 testdata=$statusdir/data1
largetestdata=$statusdir/data2 largetestdata=$statusdir/data2
cmd_prefix=
cmd_suffix=
connect_timeout=10
connect_retries=1
compress=gzip
upto 'Command line parameter tests' upto 'Command line parameter tests'
$impexpd >/dev/null 2>&1 && $impexpd >/dev/null 2>&1 &&
...@@ -136,36 +129,28 @@ impexpd_helper() { ...@@ -136,36 +129,28 @@ impexpd_helper() {
$PYTHON $(get_testpath)/import-export_unittest-helper "$@" $PYTHON $(get_testpath)/import-export_unittest-helper "$@"
} }
reset_status() { start_test() {
rm -f $src_statusfile $dst_output $dst_statusfile $dst_output $dst_portfile upto "$@"
rm -f $gencert_output
}
write_data() { rm -f $src_statusfile $dst_output $dst_statusfile $dst_output
local fname=${1:-$testdata} rm -f $gencert_output
# Wait for connection to be established
impexpd_helper $src_statusfile connected
# And just to be sure, also wait for destination to report as connected imppid=
impexpd_helper $dst_statusfile connected exppid=
cat $fname cmd_prefix=
cmd_suffix=
connect_timeout=30
connect_retries=1
compress=gzip
} }
do_export() { wait_import_ready() {
# Wait for listening port # Wait for listening port
impexpd_helper $dst_statusfile listen-port > $dst_portfile impexpd_helper $dst_statusfile listen-port
local port=$(< $dst_portfile)
test -n "$port" || err 'Empty port file'
test "$port" != None || err 'Missing port'
do_export_to_port $port
} }
do_export_to_port() { do_export() {
local port=$1 local port=$1
$impexpd $src_statusfile export --bind=127.0.0.1 \ $impexpd $src_statusfile export --bind=127.0.0.1 \
...@@ -194,116 +179,124 @@ impexpd_helper $other_x509 gencert 2>$gencert_output & othercertpid=$! ...@@ -194,116 +179,124 @@ impexpd_helper $other_x509 gencert 2>$gencert_output & othercertpid=$!
checkpids $srccertpid $dstcertpid $othercertpid || \ checkpids $srccertpid $dstcertpid $othercertpid || \
err 'Failed to generate certificates' err 'Failed to generate certificates'
upto 'Normal case' start_test 'Normal case'
reset_status
do_import > $statusdir/recv1 2>$dst_output & imppid=$! do_import > $statusdir/recv1 2>$dst_output & imppid=$!
{ write_data | do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid || err 'An error occurred' checkpids $exppid $imppid || err 'An error occurred'
cmp $testdata $statusdir/recv1 || err 'Received data does not match input' cmp $testdata $statusdir/recv1 || err 'Received data does not match input'
upto 'Export using wrong CA' start_test 'Export using wrong CA'
reset_status
# Setting lower timeout to not wait for too long # Setting lower timeout to not wait for too long
connect_timeout=1 do_import &>$dst_output & imppid=$! connect_timeout=1 do_import &>$dst_output & imppid=$!
: | dst_x509=$other_x509 do_export &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
: | dst_x509=$other_x509 do_export $port >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid && err 'Export did not fail when using wrong CA' checkpids $exppid $imppid && err 'Export did not fail when using wrong CA'
upto 'Import using wrong CA' start_test 'Import using wrong CA'
reset_status
# Setting lower timeout to not wait for too long # Setting lower timeout to not wait for too long
src_x509=$other_x509 connect_timeout=1 do_import &>$dst_output & imppid=$! src_x509=$other_x509 connect_timeout=1 do_import &>$dst_output & imppid=$!
: | do_export &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
: | do_export $port >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid && err 'Import did not fail when using wrong CA' checkpids $exppid $imppid && err 'Import did not fail when using wrong CA'
upto 'Suffix command on import' start_test 'Suffix command on import'
reset_status
cmd_suffix="| cksum > $statusdir/recv2" do_import &>$dst_output & imppid=$! cmd_suffix="| cksum > $statusdir/recv2" do_import &>$dst_output & imppid=$!
{ write_data | do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid || err 'Testing additional commands failed' checkpids $exppid $imppid || err 'Testing additional commands failed'
cmp $statusdir/recv2 <(cksum < $testdata) || \ cmp $statusdir/recv2 <(cksum < $testdata) || \
err 'Checksum of received data does not match' err 'Checksum of received data does not match'
upto 'Prefix command on export' start_test 'Prefix command on export'
reset_status
do_import > $statusdir/recv3 2>$dst_output & imppid=$! do_import > $statusdir/recv3 2>$dst_output & imppid=$!
{ write_data | cmd_prefix="cksum |" do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
cmd_prefix='cksum |' do_export $port <$testdata >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid || err 'Testing additional commands failed' checkpids $exppid $imppid || err 'Testing additional commands failed'
cmp $statusdir/recv3 <(cksum < $testdata) || \ cmp $statusdir/recv3 <(cksum < $testdata) || \
err 'Received checksum does not match' err 'Received checksum does not match'
upto 'Failing prefix command on export' start_test 'Failing prefix command on export'
reset_status : | cmd_prefix='exit 1;' do_export 0 &>$src_output & exppid=$!
: | cmd_prefix='exit 1;' do_export_to_port 0 &>$src_output & exppid=$!
checkpids $exppid && err 'Prefix command on export did not fail when it should' checkpids $exppid && err 'Prefix command on export did not fail when it should'
upto 'Failing suffix command on export' start_test 'Failing suffix command on export'
reset_status do_import >&$dst_output & imppid=$!
do_import >&$src_output & imppid=$! if port=$(wait_import_ready 2>$src_output); then
: | cmd_suffix='| exit 1' do_export &>$dst_output & exppid=$! : | cmd_suffix='| exit 1' do_export $port >>$src_output 2>&1 & exppid=$!
fi
checkpids $imppid $exppid && \ checkpids $imppid $exppid && \
err 'Suffix command on export did not fail when it should' err 'Suffix command on export did not fail when it should'
upto 'Failing prefix command on import' start_test 'Failing prefix command on import'
reset_status
cmd_prefix='exit 1;' do_import &>$dst_output & imppid=$! cmd_prefix='exit 1;' do_import &>$dst_output & imppid=$!
checkpids $imppid && err 'Prefix command on import did not fail when it should' checkpids $imppid && err 'Prefix command on import did not fail when it should'
upto 'Failing suffix command on import' start_test 'Failing suffix command on import'
reset_status
cmd_suffix='| exit 1' do_import &>$dst_output & imppid=$! cmd_suffix='| exit 1' do_import &>$dst_output & imppid=$!
: | do_export &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
: | do_export $port >>$src_output 2>&1 & exppid=$!
fi
checkpids $imppid $exppid && \ checkpids $imppid $exppid && \
err 'Suffix command on import did not fail when it should' err 'Suffix command on import did not fail when it should'
upto 'Listen timeout A' start_test 'Listen timeout A'
reset_status
# Setting lower timeout to not wait too long (there won't be anything trying to # Setting lower timeout to not wait too long (there won't be anything trying to
# connect) # connect)
connect_timeout=1 do_import &>$dst_output & imppid=$! connect_timeout=1 do_import &>$dst_output & imppid=$!
checkpids $imppid && \ checkpids $imppid && \
err 'Listening with timeout did not fail when it should' err 'Listening with timeout did not fail when it should'
upto 'Listen timeout B' start_test 'Listen timeout B'
reset_status
do_import &>$dst_output & imppid=$! do_import &>$dst_output & imppid=$!
{ sleep 1; : | do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
{ sleep 1; : | do_export $port; } >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid || \ checkpids $exppid $imppid || \
err 'Listening with timeout failed when it should not' err 'Listening with timeout failed when it should not'
upto 'Connect timeout' start_test 'Connect timeout'
reset_status
# Setting lower timeout as nothing will be listening on port 0 # Setting lower timeout as nothing will be listening on port 0
: | connect_timeout=1 do_export_to_port 0 &>$src_output & exppid=$! : | connect_timeout=1 do_export 0 &>$src_output & exppid=$!
checkpids $exppid && err 'Connection did not time out when it should' checkpids $exppid && err 'Connection did not time out when it should'
upto 'No compression' start_test 'No compression'
reset_status
compress=none do_import > $statusdir/recv-nocompr 2>$dst_output & imppid=$! compress=none do_import > $statusdir/recv-nocompr 2>$dst_output & imppid=$!
{ write_data | compress=none do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
compress=none do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid || err 'An error occurred' checkpids $exppid $imppid || err 'An error occurred'
cmp $testdata $statusdir/recv-nocompr || \ cmp $testdata $statusdir/recv-nocompr || \
err 'Received data does not match input' err 'Received data does not match input'
upto 'Compression mismatch A' start_test 'Compression mismatch A'
reset_status
compress=none do_import > $statusdir/recv-miscompr 2>$dst_output & imppid=$! compress=none do_import > $statusdir/recv-miscompr 2>$dst_output & imppid=$!
{ write_data | compress=gzip do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
compress=gzip do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid || err 'An error occurred' checkpids $exppid $imppid || err 'An error occurred'
cmp -s $testdata $statusdir/recv-miscompr && \ cmp -s $testdata $statusdir/recv-miscompr && \
err 'Received data matches input when it should not' err 'Received data matches input when it should not'
upto 'Compression mismatch B' start_test 'Compression mismatch B'
reset_status
compress=gzip do_import > $statusdir/recv-miscompr2 2>$dst_output & imppid=$! compress=gzip do_import > $statusdir/recv-miscompr2 2>$dst_output & imppid=$!
{ write_data | compress=none do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
compress=none do_export $port < $testdata >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid && err 'Did not fail when it should' checkpids $exppid $imppid && err 'Did not fail when it should'
cmp -s $testdata $statusdir/recv-miscompr2 && \ cmp -s $testdata $statusdir/recv-miscompr2 && \
err 'Received data matches input when it should not' err 'Received data matches input when it should not'
upto 'Large transfer' start_test 'Large transfer'
reset_status
do_import > $statusdir/recv-large 2>$dst_output & imppid=$! do_import > $statusdir/recv-large 2>$dst_output & imppid=$!
{ write_data $largetestdata | do_export; } &>$src_output & exppid=$! if port=$(wait_import_ready 2>$src_output); then
do_export $port < $largetestdata >>$src_output 2>&1 & exppid=$!
fi
checkpids $exppid $imppid || err 'An error occurred' checkpids $exppid $imppid || err 'An error occurred'
cmp $largetestdata $statusdir/recv-large || \ cmp $largetestdata $statusdir/recv-large || \
err 'Received data does not match input' err 'Received data does not match input'
......
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