From 125b09062738b4a3b18a166fc573c7a0795dab8f Mon Sep 17 00:00:00 2001 From: Robin McCorkell Date: Tue, 24 Nov 2015 15:42:01 +0000 Subject: [PATCH] Replace shitty netcat use with dedicated PHP script --- .../tests/env/start-amazons3-ceph.sh | 17 ++----- .../tests/env/start-ftp-morrisjobke.sh | 17 ++----- .../tests/env/start-sftp-atmoz.sh | 17 ++----- .../tests/env/start-smb-silvershell.sh | 17 ++----- .../tests/env/start-smb-windows.sh | 3 +- .../tests/env/start-swift-ceph.sh | 17 ++----- .../tests/env/start-webdav-ownCloud.sh | 19 +++----- .../tests/env/wait-for-connection | 45 +++++++++++++++++++ 8 files changed, 71 insertions(+), 81 deletions(-) create mode 100755 apps/files_external/tests/env/wait-for-connection diff --git a/apps/files_external/tests/env/start-amazons3-ceph.sh b/apps/files_external/tests/env/start-amazons3-ceph.sh index b40d28f1ec..20fa7e7bb2 100755 --- a/apps/files_external/tests/env/start-amazons3-ceph.sh +++ b/apps/files_external/tests/env/start-amazons3-ceph.sh @@ -50,19 +50,10 @@ echo "${docker_image} container: $container" echo $container >> $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.amazons3 echo -n "Waiting for ceph initialization" -starttime=$(date +%s) -# support for GNU netcat and BSD netcat -while ! (nc -c -w 1 ${host} ${port} &/dev/null \ - || nc -w 1 ${host} ${port} &/dev/null); do - sleep 1 - echo -n '.' - if (( $(date +%s) > starttime + 60 )); then - echo - echo "[ERROR] Waited 60 seconds, no response" >&2 - exit 1 - fi -done -echo +if ! "$thisFolder"/env/wait-for-connection ${host} ${port} 60; then + echo "[ERROR] Waited 60 seconds, no response" >&2 + exit 1 +fi sleep 1 echo "Create ceph user" diff --git a/apps/files_external/tests/env/start-ftp-morrisjobke.sh b/apps/files_external/tests/env/start-ftp-morrisjobke.sh index 3c6cc62bce..3a5f6ffcb6 100755 --- a/apps/files_external/tests/env/start-ftp-morrisjobke.sh +++ b/apps/files_external/tests/env/start-ftp-morrisjobke.sh @@ -55,19 +55,10 @@ echo "ftp container: $container" echo $container >> $thisFolder/dockerContainerMorrisJobke.$EXECUTOR_NUMBER.ftp echo -n "Waiting for ftp initialization" -starttime=$(date +%s) -# support for GNU netcat and BSD netcat -while ! (nc -c -w 1 ${host} 21 &/dev/null \ - || nc -w 1 ${host} 21 &/dev/null); do - sleep 1 - echo -n '.' - if (( $(date +%s) > starttime + 60 )); then - echo - echo "[ERROR] Waited 60 seconds, no response" >&2 - exit 1 - fi -done -echo +if ! "$thisFolder"/env/wait-for-connection ${host} 21 60; then + echo "[ERROR] Waited 60 seconds, no response" >&2 + exit 1 +fi sleep 1 if [ -n "$DEBUG" ]; then diff --git a/apps/files_external/tests/env/start-sftp-atmoz.sh b/apps/files_external/tests/env/start-sftp-atmoz.sh index 3e0616f03d..0fc0c5c427 100755 --- a/apps/files_external/tests/env/start-sftp-atmoz.sh +++ b/apps/files_external/tests/env/start-sftp-atmoz.sh @@ -55,19 +55,10 @@ echo "sftp container: $container" echo $container >> $thisFolder/dockerContainerAtmoz.$EXECUTOR_NUMBER.sftp echo -n "Waiting for sftp initialization" -starttime=$(date +%s) -# support for GNU netcat and BSD netcat -while ! (nc -c -w 1 ${host} 22 &/dev/null \ - || nc -w 1 ${host} 22 &/dev/null); do - sleep 1 - echo -n '.' - if (( $(date +%s) > starttime + 60 )); then - echo - echo "[ERROR] Waited 60 seconds, no response" >&2 - exit 1 - fi -done -echo +if ! "$thisFolder"/env/wait-for-connection ${host} 22 60; then + echo "[ERROR] Waited 60 seconds, no response" >&2 + exit 1 +fi sleep 1 if [ -n "$DEBUG" ]; then diff --git a/apps/files_external/tests/env/start-smb-silvershell.sh b/apps/files_external/tests/env/start-smb-silvershell.sh index 31e3da4464..a7ff3f71eb 100755 --- a/apps/files_external/tests/env/start-smb-silvershell.sh +++ b/apps/files_external/tests/env/start-smb-silvershell.sh @@ -53,19 +53,10 @@ echo "samba container: $container" echo $container >> $thisFolder/dockerContainerSilvershell.$EXECUTOR_NUMBER.smb echo -n "Waiting for samba initialization" -starttime=$(date +%s) -# support for GNU netcat and BSD netcat -while ! (nc -c -w 1 ${host} 445 &/dev/null \ - || nc -w 1 ${host} 445 &/dev/null); do - sleep 1 - echo -n '.' - if (( $(date +%s) > starttime + 60 )); then - echo - echo "[ERROR] Waited 60 seconds, no response" >&2 - exit 1 - fi -done -echo +if ! "$thisFolder"/env/wait-for-connection ${host} 445 60; then + echo "[ERROR] Waited 60 seconds, no response" >&2 + exit 1 +fi sleep 1 if [ -n "$DEBUG" ]; then diff --git a/apps/files_external/tests/env/start-smb-windows.sh b/apps/files_external/tests/env/start-smb-windows.sh index 6779cdb2d5..9453b4eb3e 100755 --- a/apps/files_external/tests/env/start-smb-windows.sh +++ b/apps/files_external/tests/env/start-smb-windows.sh @@ -19,8 +19,7 @@ user=smb-test password=!owncloud123 host=WIN-9GTFAS08C15 -if ! (nc -c -w 1 ${host} 445 &/dev/null \ - || nc -w 1 ${host} 445 &/dev/null); then +if ! "$thisFolder"/env/wait-for-connection ${host} 445 0; then echo "[ERROR] Server not reachable" >&2 exit 1 fi diff --git a/apps/files_external/tests/env/start-swift-ceph.sh b/apps/files_external/tests/env/start-swift-ceph.sh index ea16e167af..936bb667e9 100755 --- a/apps/files_external/tests/env/start-swift-ceph.sh +++ b/apps/files_external/tests/env/start-swift-ceph.sh @@ -57,19 +57,10 @@ echo "${docker_image} container: $container" echo $container >> $thisFolder/dockerContainerCeph.$EXECUTOR_NUMBER.swift echo -n "Waiting for ceph initialization" -starttime=$(date +%s) -# support for GNU netcat and BSD netcat -while ! (nc -c -w 1 ${host} 80 &/dev/null \ - || nc -w 1 ${host} 80 &/dev/null); do - sleep 1 - echo -n '.' - if (( $(date +%s) > starttime + 60 )); then - echo - echo "[ERROR] Waited 60 seconds, no response" >&2 - exit 1 - fi -done -echo +if ! "$thisFolder"/env/wait-for-connection ${host} 80 60; then + echo "[ERROR] Waited 60 seconds, no response" >&2 + exit 1 +fi sleep 1 cat > $thisFolder/config.swift.php <&/dev/null \ - || nc -w 1 ${host} 80 &/dev/null); do - sleep 1 - echo -n '.' - if (( $(date +%s) > starttime + 60 )); then - echo - echo "[ERROR] Waited 60 seconds, no response" >&2 - exit 1 - fi -done -echo +if ! "$thisFolder"/env/wait-for-connection ${host} 80 60; then + echo "[ERROR] Waited 60 seconds, no response" >&2 + exit 1 +fi # wait at least 5 more seconds - sometimes the webserver still needs some additional time sleep 5 diff --git a/apps/files_external/tests/env/wait-for-connection b/apps/files_external/tests/env/wait-for-connection new file mode 100755 index 0000000000..2c480fb733 --- /dev/null +++ b/apps/files_external/tests/env/wait-for-connection @@ -0,0 +1,45 @@ +#!/usr/bin/php + $timeout) { + $socketTimeout = $timeout; +} + +$stopTime = time() + $timeout; +do { + $sock = @fsockopen($host, $port, $errno, $errstr, $socketTimeout); + if ($sock !== false) { + fclose($sock); + fwrite(STDOUT, "\n"); + exit(0); + } + sleep(1); + fwrite(STDOUT, '.'); +} while (time() < $stopTime); + +fwrite(STDOUT, "\n"); +exit(1);