summaryrefslogtreecommitdiffstats
path: root/apps/files_external/tests/env
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-11-24 15:42:01 +0000
committerRobin McCorkell <rmccorkell@owncloud.com>2015-11-24 16:05:08 +0000
commit125b09062738b4a3b18a166fc573c7a0795dab8f (patch)
treed3387840c0bf42bc1e8dc8a1b50abdd51431c8b5 /apps/files_external/tests/env
parent4978a785fa906b4dc9d79aa9251a3f9187c31206 (diff)
downloadnextcloud-server-125b09062738b4a3b18a166fc573c7a0795dab8f.tar.gz
nextcloud-server-125b09062738b4a3b18a166fc573c7a0795dab8f.zip
Replace shitty netcat use with dedicated PHP script
Diffstat (limited to 'apps/files_external/tests/env')
-rwxr-xr-xapps/files_external/tests/env/start-amazons3-ceph.sh17
-rwxr-xr-xapps/files_external/tests/env/start-ftp-morrisjobke.sh17
-rwxr-xr-xapps/files_external/tests/env/start-sftp-atmoz.sh17
-rwxr-xr-xapps/files_external/tests/env/start-smb-silvershell.sh17
-rwxr-xr-xapps/files_external/tests/env/start-smb-windows.sh3
-rwxr-xr-xapps/files_external/tests/env/start-swift-ceph.sh17
-rwxr-xr-xapps/files_external/tests/env/start-webdav-ownCloud.sh19
-rwxr-xr-xapps/files_external/tests/env/wait-for-connection45
8 files changed, 71 insertions, 81 deletions
diff --git a/apps/files_external/tests/env/start-amazons3-ceph.sh b/apps/files_external/tests/env/start-amazons3-ceph.sh
index b40d28f1ec6..20fa7e7bb2b 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 >&/dev/null \
- || nc -w 1 ${host} ${port} </dev/null >&/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 3c6cc62bce8..3a5f6ffcb67 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 >&/dev/null \
- || nc -w 1 ${host} 21 </dev/null >&/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 3e0616f03d2..0fc0c5c427f 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 >&/dev/null \
- || nc -w 1 ${host} 22 </dev/null >&/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 31e3da44646..a7ff3f71eb1 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 >&/dev/null \
- || nc -w 1 ${host} 445 </dev/null >&/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 6779cdb2d56..9453b4eb3e7 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 >&/dev/null \
- || nc -w 1 ${host} 445 </dev/null >&/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 ea16e167af9..936bb667e94 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 >&/dev/null \
- || nc -w 1 ${host} 80 </dev/null >&/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 <<DELIM
diff --git a/apps/files_external/tests/env/start-webdav-ownCloud.sh b/apps/files_external/tests/env/start-webdav-ownCloud.sh
index f04616d4991..d992516d7b1 100755
--- a/apps/files_external/tests/env/start-webdav-ownCloud.sh
+++ b/apps/files_external/tests/env/start-webdav-ownCloud.sh
@@ -46,22 +46,13 @@ fi
container=`docker run -P $parameter -d -e ADMINLOGIN=test -e ADMINPWD=test morrisjobke/owncloud`
-host=`docker inspect $container | grep IPAddress | cut -d '"' -f 4`
+host=`docker inspect --format="{{.NetworkSettings.IPAddress}}" $container`
echo -n "Waiting for ownCloud initialization"
-starttime=$(date +%s)
-# support for GNU netcat and BSD netcat
-while ! (nc -c -w 1 ${host} 80 </dev/null >&/dev/null \
- || nc -w 1 ${host} 80 </dev/null >&/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 00000000000..2c480fb733e
--- /dev/null
+++ b/apps/files_external/tests/env/wait-for-connection
@@ -0,0 +1,45 @@
+#!/usr/bin/php
+<?php
+
+$timeout = 60;
+
+switch ($argc) {
+case 4:
+ $timeout = (float)$argv[3];
+case 3:
+ $host = $argv[1];
+ $port = (int)$argv[2];
+ break;
+default:
+ fwrite(STDERR, 'Usage: '.$argv[0].' host port [timeout]'."\n");
+ exit(2);
+}
+
+if ($timeout < 0) {
+ fwrite(STDERR, 'Timeout must be greater than zero'."\n");
+ exit(2);
+}
+if ($port < 1) {
+ fwrite(STDERR, 'Port must be an integer greater than zero'."\n");
+ exit(2);
+}
+
+$socketTimeout = (float)ini_get('default_socket_timeout');
+if ($socketTimeout > $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);