diff options
author | Ryan Chu <ryan.chu@qt.io> | 2018-09-20 15:16:57 +0200 |
---|---|---|
committer | Ryan Chu <ryan.chu@qt.io> | 2018-10-18 19:22:46 +0000 |
commit | c99b8a3f41e6641c2a254d6e4ba80151734fc58e (patch) | |
tree | 55c6d14388c20fdf8d8dfd0febeb0a1bf476d9de /tests | |
parent | 0d4d06647a9c15dfbe637926557b163ee736c642 (diff) |
Docker-based test servers for network-related Qt autotests on macOS
There is no docker bridge on macOS. Docker document recommends using
port mapping to connect to a container; but it causes a port conflict
if the user is running a service that binds the same port on the host.
An alternative solution is to deploy the docker environment into
VirtualBox and use the host network option.
Task-number: QTQAINFRA-2293
Change-Id: I05dc65c5f8b4be7a1b1874a4ec7c034cc68679ca
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/network-settings.h | 10 | ||||
-rw-r--r-- | tests/auto/testserver.pri | 39 | ||||
-rw-r--r-- | tests/testserver/docker-compose-for-macOS.yml | 80 | ||||
-rwxr-xr-x | tests/testserver/vsftpd/vsftpd.sh | 2 |
4 files changed, 112 insertions, 19 deletions
diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index a3c318420f..4225ff11c7 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -176,7 +176,7 @@ public: static QString ftpServerName() { -#ifdef QT_TEST_SERVER +#ifdef QT_TEST_SERVER_NAME return QString("vsftpd.") % serverDomainName(); #else return serverName(); @@ -184,7 +184,7 @@ public: } static QString ftpProxyServerName() { -#ifdef QT_TEST_SERVER +#ifdef QT_TEST_SERVER_NAME return QString("ftp-proxy.") % serverDomainName(); #else return serverName(); @@ -192,7 +192,7 @@ public: } static QString httpServerName() { -#ifdef QT_TEST_SERVER +#ifdef QT_TEST_SERVER_NAME return QString("apache2.") % serverDomainName(); #else return serverName(); @@ -200,7 +200,7 @@ public: } static QString httpProxyServerName() { -#ifdef QT_TEST_SERVER +#ifdef QT_TEST_SERVER_NAME return QString("squid.") % serverDomainName(); #else return serverName(); @@ -208,7 +208,7 @@ public: } static QString socksProxyServerName() { -#ifdef QT_TEST_SERVER +#ifdef QT_TEST_SERVER_NAME return QString("danted.") % serverDomainName(); #else return serverName(); diff --git a/tests/auto/testserver.pri b/tests/auto/testserver.pri index b2f593235f..a50ffd9bd6 100644 --- a/tests/auto/testserver.pri +++ b/tests/auto/testserver.pri @@ -51,7 +51,6 @@ # 2. testserver_clean - Clean up server containers/images and tidy away related # files. -TESTSERVER_COMPOSE_FILE = $$dirname(_QMAKE_CONF_)/tests/testserver/docker-compose.yml TESTSERVER_VERSION = $$system(docker-compose --version) equals(QMAKE_HOST.os, Windows)|isEmpty(TESTSERVER_VERSION) { @@ -59,30 +58,43 @@ equals(QMAKE_HOST.os, Windows)|isEmpty(TESTSERVER_VERSION) { message("testserver: qt-test-server.qt-test-net") } else { # Make check with test servers - message("testserver:" $$TESTSERVER_VERSION) + equals(QMAKE_HOST.os, Darwin) { + # There is no docker bridge on macOS. It is impossible to ping a container. + # Docker docs recommends using port mapping to connect to a container; + # but it causes a port conflict if the user is running a service that + # binds the same port on the host. An alternative solution is to deploy + # the docker environment into VirtualBox using docker-machine. + TESTSERVER_COMPOSE_FILE = \ + $$dirname(_QMAKE_CONF_)/tests/testserver/docker-compose-for-macOS.yml + + # The connection configuration for the target machine + MACHINE_CONFIG = $(shell docker-machine config qt-test-server) + + # The environment variables passed to the docker-compose file + TEST_ENV = 'MACHINE_IP=$(shell docker-machine ip qt-test-server)' + } else { + TESTSERVER_COMPOSE_FILE = $$dirname(_QMAKE_CONF_)/tests/testserver/docker-compose.yml + DEFINES += QT_TEST_SERVER_NAME + } # Ensure that the docker-compose file is provided. It is a configuration # file which is mandatory for all docker-compose commands. You can get more # detail from the description of TESTSERVER_COMPOSE_FILE above. There is # also an example showing how to configure it manually. FILE_PRETEST_MSG = "Project variable 'TESTSERVER_COMPOSE_FILE' is not set" - testserver_pretest.commands = $(if $$TESTSERVER_COMPOSE_FILE,,$(error $$FILE_PRETEST_MSG)) + testserver_pretest.commands = $(info "testserver:" $$TESTSERVER_VERSION) + testserver_pretest.commands += $(if $$TESTSERVER_COMPOSE_FILE,,$(error $$FILE_PRETEST_MSG)) # Before starting the test servers, it requires the user to run the setup # script (coin/provisioning/.../testserver/docker_testserver.sh) in advance. - IMAGE_PRETEST_CMD = docker images -aq "qt-test-server-*" + IMAGE_PRETEST_CMD = docker $$MACHINE_CONFIG images -aq "qt-test-server-*" IMAGE_PRETEST_MSG = "Docker image qt-test-server-* not found" testserver_pretest.commands += $(if $(shell $$IMAGE_PRETEST_CMD),,$(error $$IMAGE_PRETEST_MSG)) # The domain name is relevant to https keycert (qnetworkreply/crts/qt-test-net-cacert.pem). DNSDOMAIN = test-net.qt.local - TEST_ENV += TESTSERVER_DOMAIN=$$DNSDOMAIN DEFINES += QT_TEST_SERVER QT_TEST_SERVER_DOMAIN=$$shell_quote(\"$${DNSDOMAIN}\") - # There is no docker bridge on macOS. It is impossible to ping a container. - # Docker docs recommends using port mapping to connect to a container. - equals(QMAKE_HOST.os, Darwin): TEST_ENV += TESTSERVER_BIND_LOCAL=1 - # Rename the check target of testcase feature check.target = check_network testserver_test.target = check @@ -91,18 +103,19 @@ equals(QMAKE_HOST.os, Windows)|isEmpty(TESTSERVER_VERSION) { testserver_test.depends = testserver_pretest # Bring up test servers and make sure the services are ready. - testserver_test.commands = $$TEST_ENV docker-compose -f $$TESTSERVER_COMPOSE_FILE up -d \ - --force-recreate --timeout 1 $${QT_TEST_SERVER_LIST} && + !isEmpty(TEST_ENV): testserver_test.commands = env $$TEST_ENV + testserver_test.commands += docker-compose $$MACHINE_CONFIG -f $$TESTSERVER_COMPOSE_FILE up \ + --detach --force-recreate --timeout 1 $${QT_TEST_SERVER_LIST} && # Check test cases with docker-based test servers. testserver_test.commands += $(MAKE) check_network; # Stop and remove test servers after testing. - testserver_test.commands += $$TEST_ENV docker-compose -f $$TESTSERVER_COMPOSE_FILE down \ + testserver_test.commands += docker-compose $$MACHINE_CONFIG -f $$TESTSERVER_COMPOSE_FILE down \ --timeout 1 # Destroy test servers and tidy away related files. - testserver_clean.commands = $$TEST_ENV docker-compose -f $$TESTSERVER_COMPOSE_FILE down \ + testserver_clean.commands = docker-compose $$MACHINE_CONFIG -f $$TESTSERVER_COMPOSE_FILE down \ --rmi all QMAKE_EXTRA_TARGETS += testserver_pretest testserver_test testserver_clean diff --git a/tests/testserver/docker-compose-for-macOS.yml b/tests/testserver/docker-compose-for-macOS.yml new file mode 100644 index 0000000000..f5d812511d --- /dev/null +++ b/tests/testserver/docker-compose-for-macOS.yml @@ -0,0 +1,80 @@ +version: '3.4' + +# The tag of images is used by docker compose file to launch the corresponding +# docker containers. The value of tag comes from the provisioning script +# (coin/provisioning/.../testserver/docker_testserver.sh). The script gets SHA-1 +# of each server context as the tag of docker images. If one of the server +# contexts gets changes, please make sure to update this compose file as well. +# You can run command 'docker images' to list all the tags of test server images. +# For example: +# REPOSITORY TAG IMAGE ID +# qt-test-server-apache2 cc9ea678b92bdda33acb9fa0159bb4ad0f3cd947 2ad5c8720317 + +services: + apache2: + image: qt-test-server-apache2:cc9ea678b92bdda33acb9fa0159bb4ad0f3cd947 + container_name: qt-test-server-apache2 + domainname: test-net.qt.local + volumes: + - ./common:/common:ro + - ./apache2:/service:ro + entrypoint: common/startup.sh + command: [common/ssl.sh, service/apache2.sh] + network_mode: "host" + + squid: + image: qt-test-server-squid:577d99307eea9a8cccfec944d25be2bce2fe99cc + container_name: qt-test-server-squid + domainname: test-net.qt.local + depends_on: + - apache2 + volumes: + - ./common:/common:ro + - ./squid:/service:ro + entrypoint: common/startup.sh + command: service/squid.sh + network_mode: "host" + + vsftpd: + image: qt-test-server-vsftpd:18896604c7e90b543e56d80c8a8aabdb65a590d0 + container_name: qt-test-server-vsftpd + domainname: test-net.qt.local + volumes: + - ./common:/common:ro + - ./vsftpd:/service:ro + entrypoint: common/startup.sh + command: service/vsftpd.sh + network_mode: "host" + + ftp-proxy: + image: qt-test-server-ftp-proxy:2c6c8f1ab6a364b540c43d705fb6f15a585cb2af + container_name: qt-test-server-ftp-proxy + domainname: test-net.qt.local + depends_on: + - vsftpd + volumes: + - ./common:/common:ro + - ./ftp-proxy:/service:ro + entrypoint: common/startup.sh + command: service/ftp-proxy.sh + network_mode: "host" + + danted: + image: qt-test-server-danted:2d5eea7356dd0ba25f3c12d1cba00d70770da1b0 + container_name: qt-test-server-danted + domainname: test-net.qt.local + depends_on: + - apache2 + - vsftpd + - ftp-proxy + volumes: + - ./common:/common:ro + - ./danted:/service:ro + entrypoint: common/startup.sh + command: service/danted.sh + network_mode: "host" + environment: + - danted_internal=${MACHINE_IP:-eth0} + - danted_external=${MACHINE_IP:-eth0} + - danted_auth_internal=${MACHINE_IP:-eth0} + - danted_auth_external=${MACHINE_IP:-eth0} diff --git a/tests/testserver/vsftpd/vsftpd.sh b/tests/testserver/vsftpd/vsftpd.sh index 1ba1a8c347..845c576534 100755 --- a/tests/testserver/vsftpd/vsftpd.sh +++ b/tests/testserver/vsftpd/vsftpd.sh @@ -43,7 +43,7 @@ cp $TESTDATA/vsftpd.{conf,user_list} /etc/ # Resolve error message "vsftpd failed - probably invalid config" during boot command='start-stop-daemon --start --background -m --oknodo --pidfile /var/run/vsftpd/vsftpd.pid' command+=' --exec ${DAEMON}' -sed -i "s,$command.*$,$command; sleep 1," /etc/init.d/vsftpd +sed -i "s,$command.*$,$command; sleep 10," /etc/init.d/vsftpd # Populate the FTP sites: su $USER -c "cp -r $TESTDATA/ftp ~/ftp" |