From 0c7fb4f1f98da1f06d92b92070fa0b7c5c9f59fb Mon Sep 17 00:00:00 2001 From: Josh Curl Date: Wed, 20 Jul 2016 10:42:16 -0700 Subject: [PATCH] Refactor integration tests --- Dockerfile.dapper | 2 + scripts/integration-test | 10 +- scripts/test | 2 +- .../assets/test_01/cloud-config.yml | 2 +- .../assets/test_02/cloud-config.yml | 2 +- tests/assets/test_03/cloud-config.yml | 5 + tests/assets/test_05/cloud-config.yml | 5 + .../assets/test_09/cloud-config.yml | 0 .../assets/test_10/cloud-config.yml | 0 tests/assets/test_11/cloud-config.yml | 18 +++ .../assets/test_11/cloud-config_arm.yml | 0 .../assets/test_11/cloud-config_arm64.yml | 0 tests/assets/test_12/cloud-config.yml | 3 + tests/assets/test_13/cloud-config.yml | 4 + .../assets/test_14/cloud-config.yml | 0 .../assets/test_16/cloud-config.yml | 0 .../assets/test_17/cloud-config.yml | 0 .../assets/test_18/cloud-config.yml | 0 .../assets/test_19/cloud-config.yml | 0 .../assets/test_20/cloud-config.yml | 0 .../assets/test_21/cloud-config.yml | 0 tests/cloud_config_hostname_test.go | 11 ++ tests/cloud_config_mounts_test.go | 10 ++ tests/common_test.go | 137 ++++++++++++++++++ ...ustom_docker_in_persistent_console_test.go | 14 ++ tests/dhcp_hostname_test.go | 11 ++ tests/docker_in_persistent_console_test.go | 20 +++ tests/environment_test.go | 12 ++ tests/http_proxy_test.go | 32 ++++ tests/install_test.go | 18 +++ tests/integration/README.txt | 1 - tests/integration/assets/test.key | 27 ---- .../assets/test_03/cloud-config.yml | 5 - .../assets/test_05/cloud-config.yml | 5 - .../assets/test_11/cloud-config.yml | 18 --- .../assets/test_12/cloud-config.yml | 3 - .../assets/test_13/cloud-config.yml | 4 - tests/integration/requirements.txt | 2 - tests/integration/rostest/__init__.py | 0 tests/integration/rostest/conftest.py | 13 -- tests/integration/rostest/test_00_system.py | 49 ------- .../rostest/test_01_cloud_config.py | 103 ------------- tests/integration/rostest/test_02_tls.py | 22 --- .../test_03_docker_in_persistent_console.py | 38 ----- .../rostest/test_04_ros_install.py | 34 ----- ..._05_custom_docker_in_persistent_console.py | 39 ----- tests/integration/rostest/test_06_subdir.py | 19 --- tests/integration/rostest/test_09_network.py | 50 ------- .../rostest/test_10_network_from_url.py | 62 -------- .../rostest/test_11_environment.py | 24 --- .../rostest/test_12_dhcp_hostname.py | 21 --- .../rostest/test_13_cloud_config_hostname.py | 21 --- .../rostest/test_15_shared_mount.py | 21 --- .../rostest/test_16_cloud_config_mounts.py | 17 --- .../integration/rostest/test_17_http_proxy.py | 45 ------ .../rostest/test_18_network_on_boot.py | 26 ---- .../test_19_lenient_service_parsing.py | 18 --- tests/integration/rostest/test_20_sysctl.py | 17 --- tests/integration/rostest/test_21_swap.py | 19 --- tests/integration/rostest/util.py | 116 --------------- tests/integration/setup.py | 11 -- tests/integration/tox.ini | 15 -- tests/lenient_service_parsing_test.go | 12 ++ tests/misc_test.go | 35 +++++ tests/network_from_url_test.go | 35 +++++ tests/network_on_boot_test.go | 11 ++ tests/network_test.go | 38 +++++ .../rostest/test_07_oem.py => oem_test.go} | 33 ++--- ...st_14_ros_config.py => ros_config_test.go} | 44 ++---- tests/shared_mount_test.go | 20 +++ ...ssh_key_merge.py => ssh_key_merge_test.go} | 22 ++- tests/subdir_test.go | 14 ++ tests/swap_test.go | 12 ++ tests/sysctl_test.go | 11 ++ tests/tls_test.go | 13 ++ 75 files changed, 545 insertions(+), 938 deletions(-) rename tests/{integration => }/assets/test_01/cloud-config.yml (58%) rename tests/{integration => }/assets/test_02/cloud-config.yml (94%) create mode 100644 tests/assets/test_03/cloud-config.yml create mode 100644 tests/assets/test_05/cloud-config.yml rename tests/{integration => }/assets/test_09/cloud-config.yml (100%) rename tests/{integration => }/assets/test_10/cloud-config.yml (100%) create mode 100644 tests/assets/test_11/cloud-config.yml rename tests/{integration => }/assets/test_11/cloud-config_arm.yml (100%) rename tests/{integration => }/assets/test_11/cloud-config_arm64.yml (100%) create mode 100644 tests/assets/test_12/cloud-config.yml create mode 100644 tests/assets/test_13/cloud-config.yml rename tests/{integration => }/assets/test_14/cloud-config.yml (100%) rename tests/{integration => }/assets/test_16/cloud-config.yml (100%) rename tests/{integration => }/assets/test_17/cloud-config.yml (100%) rename tests/{integration => }/assets/test_18/cloud-config.yml (100%) rename tests/{integration => }/assets/test_19/cloud-config.yml (100%) rename tests/{integration => }/assets/test_20/cloud-config.yml (100%) rename tests/{integration => }/assets/test_21/cloud-config.yml (100%) create mode 100644 tests/cloud_config_hostname_test.go create mode 100644 tests/cloud_config_mounts_test.go create mode 100644 tests/common_test.go create mode 100644 tests/custom_docker_in_persistent_console_test.go create mode 100644 tests/dhcp_hostname_test.go create mode 100644 tests/docker_in_persistent_console_test.go create mode 100644 tests/environment_test.go create mode 100644 tests/http_proxy_test.go create mode 100644 tests/install_test.go delete mode 100644 tests/integration/README.txt delete mode 100644 tests/integration/assets/test.key delete mode 100644 tests/integration/assets/test_03/cloud-config.yml delete mode 100644 tests/integration/assets/test_05/cloud-config.yml delete mode 100644 tests/integration/assets/test_11/cloud-config.yml delete mode 100644 tests/integration/assets/test_12/cloud-config.yml delete mode 100644 tests/integration/assets/test_13/cloud-config.yml delete mode 100644 tests/integration/requirements.txt delete mode 100644 tests/integration/rostest/__init__.py delete mode 100644 tests/integration/rostest/conftest.py delete mode 100644 tests/integration/rostest/test_00_system.py delete mode 100644 tests/integration/rostest/test_01_cloud_config.py delete mode 100644 tests/integration/rostest/test_02_tls.py delete mode 100644 tests/integration/rostest/test_03_docker_in_persistent_console.py delete mode 100644 tests/integration/rostest/test_04_ros_install.py delete mode 100644 tests/integration/rostest/test_05_custom_docker_in_persistent_console.py delete mode 100644 tests/integration/rostest/test_06_subdir.py delete mode 100644 tests/integration/rostest/test_09_network.py delete mode 100644 tests/integration/rostest/test_10_network_from_url.py delete mode 100644 tests/integration/rostest/test_11_environment.py delete mode 100644 tests/integration/rostest/test_12_dhcp_hostname.py delete mode 100644 tests/integration/rostest/test_13_cloud_config_hostname.py delete mode 100644 tests/integration/rostest/test_15_shared_mount.py delete mode 100644 tests/integration/rostest/test_16_cloud_config_mounts.py delete mode 100644 tests/integration/rostest/test_17_http_proxy.py delete mode 100644 tests/integration/rostest/test_18_network_on_boot.py delete mode 100644 tests/integration/rostest/test_19_lenient_service_parsing.py delete mode 100644 tests/integration/rostest/test_20_sysctl.py delete mode 100644 tests/integration/rostest/test_21_swap.py delete mode 100644 tests/integration/rostest/util.py delete mode 100644 tests/integration/setup.py delete mode 100644 tests/integration/tox.ini create mode 100644 tests/lenient_service_parsing_test.go create mode 100644 tests/misc_test.go create mode 100644 tests/network_from_url_test.go create mode 100644 tests/network_on_boot_test.go create mode 100644 tests/network_test.go rename tests/{integration/rostest/test_07_oem.py => oem_test.go} (50%) rename tests/{integration/rostest/test_14_ros_config.py => ros_config_test.go} (68%) create mode 100644 tests/shared_mount_test.go rename tests/{integration/rostest/test_08_ssh_key_merge.py => ssh_key_merge_test.go} (57%) create mode 100644 tests/subdir_test.go create mode 100644 tests/swap_test.go create mode 100644 tests/sysctl_test.go create mode 100644 tests/tls_test.go diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 7a81bcbc..25e5236a 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -158,6 +158,8 @@ RUN curl -fL ${!DOCKER_URL} > ${DOWNLOADS}/docker.tgz # Install Trash RUN go get github.com/rancher/trash +RUN go get gopkg.in/check.v1 + # Install dapper RUN curl -sL https://releases.rancher.com/dapper/latest/dapper-`uname -s`-`uname -m | sed 's/arm.*/arm/'` > /usr/bin/dapper && \ chmod +x /usr/bin/dapper diff --git a/scripts/integration-test b/scripts/integration-test index d96b1961..0165c433 100755 --- a/scripts/integration-test +++ b/scripts/integration-test @@ -1,13 +1,13 @@ #!/bin/bash -# help: Run Python based integration tests +# help: Run integration tests set -e source $(dirname $0)/version -cd $(dirname $0)/../tests/integration +cd $(dirname $0)/../tests -if [ ! -e ../../dist/artifacts/initrd ]; then - ../../scripts/dev +if [ ! -e ../dist/artifacts/initrd ]; then + ../scripts/dev fi -tox "$@" +go test -timeout 20m diff --git a/scripts/test b/scripts/test index e188270f..a620a05b 100755 --- a/scripts/test +++ b/scripts/test @@ -6,7 +6,7 @@ cd $(dirname $0)/.. echo Running tests -PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin)' | sed -e 's!^!./!' -e 's!$!/...!')" +PACKAGES=". $(find -name '*.go' | xargs -I{} dirname {} | cut -f2 -d/ | sort -u | grep -Ev '(^\.$|.git|.trash-cache|vendor|bin|tests)' | sed -e 's!^!./!' -e 's!$!/...!')" if [ "$ARCH" = "amd64" ]; then RACE="-race" diff --git a/tests/integration/assets/test_01/cloud-config.yml b/tests/assets/test_01/cloud-config.yml similarity index 58% rename from tests/integration/assets/test_01/cloud-config.yml rename to tests/assets/test_01/cloud-config.yml index 63d0d0d0..1b5de81d 100644 --- a/tests/integration/assets/test_01/cloud-config.yml +++ b/tests/assets/test_01/cloud-config.yml @@ -16,4 +16,4 @@ rancher: docker: args: [daemon, --log-opt, max-file=2, --log-opt, max-size=25m, -s, overlay, -G, docker, -H, 'unix:///var/run/docker.sock', --userland-proxy=false] ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF diff --git a/tests/integration/assets/test_02/cloud-config.yml b/tests/assets/test_02/cloud-config.yml similarity index 94% rename from tests/integration/assets/test_02/cloud-config.yml rename to tests/assets/test_02/cloud-config.yml index af7e26d2..3ddc9add 100644 --- a/tests/integration/assets/test_02/cloud-config.yml +++ b/tests/assets/test_02/cloud-config.yml @@ -99,4 +99,4 @@ rancher: -----END RSA PRIVATE KEY----- ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF diff --git a/tests/assets/test_03/cloud-config.yml b/tests/assets/test_03/cloud-config.yml new file mode 100644 index 00000000..29b8d11e --- /dev/null +++ b/tests/assets/test_03/cloud-config.yml @@ -0,0 +1,5 @@ +#cloud-config +rancher: + console: debian +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF diff --git a/tests/assets/test_05/cloud-config.yml b/tests/assets/test_05/cloud-config.yml new file mode 100644 index 00000000..29b8d11e --- /dev/null +++ b/tests/assets/test_05/cloud-config.yml @@ -0,0 +1,5 @@ +#cloud-config +rancher: + console: debian +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF diff --git a/tests/integration/assets/test_09/cloud-config.yml b/tests/assets/test_09/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_09/cloud-config.yml rename to tests/assets/test_09/cloud-config.yml diff --git a/tests/integration/assets/test_10/cloud-config.yml b/tests/assets/test_10/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_10/cloud-config.yml rename to tests/assets/test_10/cloud-config.yml diff --git a/tests/assets/test_11/cloud-config.yml b/tests/assets/test_11/cloud-config.yml new file mode 100644 index 00000000..23083b62 --- /dev/null +++ b/tests/assets/test_11/cloud-config.yml @@ -0,0 +1,18 @@ +#cloud-config +rancher: + environment: + A: A + BB: BB + BC: BC + services: + env: + image: busybox + command: env + labels: + io.rancher.os.scope: system + io.rancher.os.before: console + environment: + - A + - B* +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF diff --git a/tests/integration/assets/test_11/cloud-config_arm.yml b/tests/assets/test_11/cloud-config_arm.yml similarity index 100% rename from tests/integration/assets/test_11/cloud-config_arm.yml rename to tests/assets/test_11/cloud-config_arm.yml diff --git a/tests/integration/assets/test_11/cloud-config_arm64.yml b/tests/assets/test_11/cloud-config_arm64.yml similarity index 100% rename from tests/integration/assets/test_11/cloud-config_arm64.yml rename to tests/assets/test_11/cloud-config_arm64.yml diff --git a/tests/assets/test_12/cloud-config.yml b/tests/assets/test_12/cloud-config.yml new file mode 100644 index 00000000..6fc5495c --- /dev/null +++ b/tests/assets/test_12/cloud-config.yml @@ -0,0 +1,3 @@ +#cloud-config +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF diff --git a/tests/assets/test_13/cloud-config.yml b/tests/assets/test_13/cloud-config.yml new file mode 100644 index 00000000..af2d61bd --- /dev/null +++ b/tests/assets/test_13/cloud-config.yml @@ -0,0 +1,4 @@ +#cloud-config +hostname: rancher-test +ssh_authorized_keys: + - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC85w9stZyiLQp/DkVO6fqwiShYcj1ClKdtCqgHtf+PLpJkFReSFu8y21y+ev09gsSMRRrjF7yt0pUHV6zncQhVeqsZtgc5WbELY2DOYUGmRn/CCvPbXovoBrQjSorqlBmpuPwsStYLr92Xn+VVsMNSUIegHY22DphGbDKG85vrKB8HxUxGIDxFBds/uE8FhSy+xsoyT/jUZDK6pgq2HnGl6D81ViIlKecpOpWlW3B+fea99ADNyZNVvDzbHE5pcI3VRw8u59WmpWOUgT6qacNVACl8GqpBvQk8sw7O/X9DSZHCKafeD9G5k+GYbAUz92fKWrx/lOXfUXPS3+c8dRIF diff --git a/tests/integration/assets/test_14/cloud-config.yml b/tests/assets/test_14/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_14/cloud-config.yml rename to tests/assets/test_14/cloud-config.yml diff --git a/tests/integration/assets/test_16/cloud-config.yml b/tests/assets/test_16/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_16/cloud-config.yml rename to tests/assets/test_16/cloud-config.yml diff --git a/tests/integration/assets/test_17/cloud-config.yml b/tests/assets/test_17/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_17/cloud-config.yml rename to tests/assets/test_17/cloud-config.yml diff --git a/tests/integration/assets/test_18/cloud-config.yml b/tests/assets/test_18/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_18/cloud-config.yml rename to tests/assets/test_18/cloud-config.yml diff --git a/tests/integration/assets/test_19/cloud-config.yml b/tests/assets/test_19/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_19/cloud-config.yml rename to tests/assets/test_19/cloud-config.yml diff --git a/tests/integration/assets/test_20/cloud-config.yml b/tests/assets/test_20/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_20/cloud-config.yml rename to tests/assets/test_20/cloud-config.yml diff --git a/tests/integration/assets/test_21/cloud-config.yml b/tests/assets/test_21/cloud-config.yml similarity index 100% rename from tests/integration/assets/test_21/cloud-config.yml rename to tests/assets/test_21/cloud-config.yml diff --git a/tests/cloud_config_hostname_test.go b/tests/cloud_config_hostname_test.go new file mode 100644 index 00000000..5dee29c5 --- /dev/null +++ b/tests/cloud_config_hostname_test.go @@ -0,0 +1,11 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestCloudConfigHostname(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_13/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, "hostname | grep rancher-test") + s.CheckCall(c, "cat /etc/hosts | grep rancher-test") +} diff --git a/tests/cloud_config_mounts_test.go b/tests/cloud_config_mounts_test.go new file mode 100644 index 00000000..cef89563 --- /dev/null +++ b/tests/cloud_config_mounts_test.go @@ -0,0 +1,10 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestCloudConfigMounts(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_16/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, "cat /home/rancher/test | grep test") +} diff --git a/tests/common_test.go b/tests/common_test.go new file mode 100644 index 00000000..03549e93 --- /dev/null +++ b/tests/common_test.go @@ -0,0 +1,137 @@ +package integration + +import ( + "fmt" + "os" + "os/exec" + "runtime" + "testing" + "time" + + . "gopkg.in/check.v1" +) + +func Test(t *testing.T) { TestingT(t) } + +func init() { + Suite(&QemuSuite{ + runCommand: "../scripts/run", + sshCommand: "../scripts/ssh", + }) +} + +var ( + BusyboxImage = map[string]string{ + "amd64": "busybox", + "arm": "armhf/busybox", + "arm64": "aarch64/busybox", + }[runtime.GOARCH] + NginxImage = map[string]string{ + "amd64": "nginx", + "arm": "armhfbuild/nginx", + "arm64": "armhfbuild/nginx", + }[runtime.GOARCH] + DockerUrl = "https://experimental.docker.com/builds/Linux/x86_64/docker-1.10.0-dev" + Version = os.Getenv("VERSION") + Suffix = os.Getenv("SUFFIX") +) + +type QemuSuite struct { + runCommand string + sshCommand string + qemuCmd *exec.Cmd +} + +func (s *QemuSuite) TearDownTest(c *C) { + c.Assert(s.qemuCmd.Process.Kill(), IsNil) + time.Sleep(time.Millisecond * 1000) +} + +func (s *QemuSuite) RunQemu(additionalArgs ...string) error { + runArgs := []string{ + "--qemu", + "--no-rebuild", + "--no-rm-usr", + "--fresh", + } + runArgs = append(runArgs, additionalArgs...) + + s.qemuCmd = exec.Command(s.runCommand, runArgs...) + s.qemuCmd.Stdout = os.Stdout + s.qemuCmd.Stderr = os.Stderr + if err := s.qemuCmd.Start(); err != nil { + return err + } + + return s.WaitForSSH() +} + +func (s *QemuSuite) RestartQemu(additionalArgs ...string) error { + s.qemuCmd.Process.Kill() + time.Sleep(time.Millisecond * 1000) + + runArgs := []string{ + "--qemu", + "--no-rebuild", + "--no-rm-usr", + } + runArgs = append(runArgs, additionalArgs...) + + s.qemuCmd = exec.Command(s.runCommand, runArgs...) + s.qemuCmd.Stdout = os.Stdout + s.qemuCmd.Stderr = os.Stderr + if err := s.qemuCmd.Start(); err != nil { + return err + } + + return s.WaitForSSH() +} + +func (s *QemuSuite) WaitForSSH() error { + sshArgs := []string{ + "--qemu", + "docker", + "version", + ">/dev/null", + "2>&1", + } + + var err error + for i := 0; i < 300; i++ { + cmd := exec.Command(s.sshCommand, sshArgs...) + if err = cmd.Run(); err == nil { + return nil + } + time.Sleep(500 * time.Millisecond) + } + + return fmt.Errorf("Failed to connect to SSH: %v", err) +} + +func (s *QemuSuite) MakeCall(additionalArgs ...string) error { + sshArgs := []string{ + "--qemu", + } + sshArgs = append(sshArgs, additionalArgs...) + + cmd := exec.Command(s.sshCommand, sshArgs...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + +func (s *QemuSuite) CheckCall(c *C, additionalArgs ...string) { + c.Assert(s.MakeCall(additionalArgs...), IsNil) +} + +func (s *QemuSuite) Reboot() { + s.MakeCall("sudo reboot") + time.Sleep(3000 * time.Millisecond) +} + +func (s *QemuSuite) LoadInstallerImage(c *C) { + cmd := exec.Command("sh", "-c", fmt.Sprintf("docker save rancher/os:%s%s | ../scripts/ssh --qemu sudo system-docker load", Version, Suffix)) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + c.Assert(cmd.Run(), IsNil) +} diff --git a/tests/custom_docker_in_persistent_console_test.go b/tests/custom_docker_in_persistent_console_test.go new file mode 100644 index 00000000..28cb4ecd --- /dev/null +++ b/tests/custom_docker_in_persistent_console_test.go @@ -0,0 +1,14 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestCustomDockerInPersistentConsole(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_05/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, "curl", "-Lfo", "./docker", DockerUrl) + s.CheckCall(c, "chmod", "+x", "/home/rancher/docker") + s.CheckCall(c, "sudo", "ln", "-sf", "/home/rancher/docker", "/usr/bin/docker") + s.CheckCall(c, "sudo", "system-docker", "restart", "docker") + s.CheckCall(c, "sudo", "system-docker", "version") +} diff --git a/tests/dhcp_hostname_test.go b/tests/dhcp_hostname_test.go new file mode 100644 index 00000000..bf1dcc4c --- /dev/null +++ b/tests/dhcp_hostname_test.go @@ -0,0 +1,11 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestDhcpHostname(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_12/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, "hostname | grep rancher-dev") + s.CheckCall(c, "cat /etc/hosts | grep rancher-dev") +} diff --git a/tests/docker_in_persistent_console_test.go b/tests/docker_in_persistent_console_test.go new file mode 100644 index 00000000..15920043 --- /dev/null +++ b/tests/docker_in_persistent_console_test.go @@ -0,0 +1,20 @@ +package integration + +import ( + "fmt" + + . "gopkg.in/check.v1" +) + +func (s *QemuSuite) TestRebootWithContainerRunning(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_03/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, fmt.Sprintf(` +set -e -x +docker run -d --restart=always %s`, NginxImage)) + + s.Reboot() + + s.CheckCall(c, "docker ps -f status=running | grep nginx") +} diff --git a/tests/environment_test.go b/tests/environment_test.go new file mode 100644 index 00000000..79d3d842 --- /dev/null +++ b/tests/environment_test.go @@ -0,0 +1,12 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestEnvironment(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_11/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, "sudo system-docker inspect env | grep A=A") + s.CheckCall(c, "sudo system-docker inspect env | grep BB=BB") + s.CheckCall(c, "sudo system-docker inspect env | grep BC=BC") +} diff --git a/tests/http_proxy_test.go b/tests/http_proxy_test.go new file mode 100644 index 00000000..761b46fd --- /dev/null +++ b/tests/http_proxy_test.go @@ -0,0 +1,32 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestHttpProxy(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_17/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, ` +set -x -e + +sudo system-docker exec docker env | grep HTTP_PROXY=invalid +sudo system-docker exec docker env | grep HTTPS_PROXY=invalid +sudo system-docker exec docker env | grep NO_PROXY=invalid + +if docker pull busybox; then + exit 1 +else + exit 0 +fi`) + + s.RestartQemu("--cloud-config", "./tests/assets/test_17/cloud-config.yml") + + s.CheckCall(c, ` +set -x -e + +if sudo system-docker pull busybox; then + exit 1 +else + exit 0 +fi`) +} diff --git a/tests/install_test.go b/tests/install_test.go new file mode 100644 index 00000000..a911a2d3 --- /dev/null +++ b/tests/install_test.go @@ -0,0 +1,18 @@ +package integration + +import ( + "fmt" + + . "gopkg.in/check.v1" +) + +func (s *QemuSuite) TestInstall(c *C) { + err := s.RunQemu("--no-format") + c.Assert(err, IsNil) + + s.LoadInstallerImage(c) + + s.CheckCall(c, fmt.Sprintf(` +sudo mkfs.ext4 /dev/vda +sudo ros install -f --no-reboot -d /dev/vda -i rancher/os:%s%s`, Version, Suffix)) +} diff --git a/tests/integration/README.txt b/tests/integration/README.txt deleted file mode 100644 index b141b71e..00000000 --- a/tests/integration/README.txt +++ /dev/null @@ -1 +0,0 @@ -RancherOS Integration Tests diff --git a/tests/integration/assets/test.key b/tests/integration/assets/test.key deleted file mode 100644 index 059f2aca..00000000 --- a/tests/integration/assets/test.key +++ /dev/null @@ -1,27 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIEpAIBAAKCAQEA1JbFgC+UX9ForPwO5O05asdH2UutFcwmaz2WGz/8JC/eY79F -8wsfG3da2R3sm25RzwzaTQ9wS7+Kj2OQ8UcnsReLHhrs3CSP6TrxlBo0KJ3XjD4A -0xRKOcPd/YEnXk2XH180NMAFYc8A24B+Mz3zM23aKPAIrvY5CpY18PCBY7tIIfre -oipBmQiIyk/aO882tbxn5KHYb4tld1cz3TTtvIGsWWkTbZgWFKFZxskep1zdUNwi -WlboeaOhjwjqq4RzW2DhWSgaQ4h28T4VacR0A9vvMlEhkxu1lu+RX2Xj42ucvHdH -PzuS9+2WMeAGQHdyoEGAwU9lwhCRkDWsDW36bQIDAQABAoIBAE9NGslxdji0BgcZ -U3kEIPn68otVVnCeIeq5I4hwut7I2H1++VnrWSRGxqXdKsjkQzIoSjqauroW7loE -uym18FF4RdXqF1cbcG+BJGKpz7EjCCfxbR9QH0wjC2koR4Y/DVOPkQroYlmU/W3k -Ja95uYICxXGl8KdLhAW1+NMy9CE+KmEc0j+7hkpTrmK1yfv4zT/jc2VjcF7jEV7s -sBN2OT6LwFixfJd4SWU8V50DWrzU64qhwKGCQtmCZX3Ym9vRd6KUoWd8jnwuN+KV -RttuqFCSrLw86TaUfgqnlF8lt2Dno2NAz5eyP/yq6m8SQ7pK5nVz1CXPXp24M5DW -9mWWa0UCgYEA65YecXBRTkgIvFo8yJj8DmmKQKVfe1OI6qKIVXzY2Dmzd+NE+WKJ -h1AKajZBKEHMILnPEtEMB226A0Sl1VsTY+dhDSsk34sgsP7zpbFI3S2ZzJMEkwoh -thQ9ihegzt+gn/hiHwaanYjuwELx0h+nIIinSph7aBA66yeisfPU/LsCgYEA5wKD -VIHdE3dDSpCDhuZefZpRQvTsP13XGoYU7IL0cFrTKL00CVzCAEEG2QPzJGro1KM5 -+IRUf68G0C9z9MY+fPRY6/BLEKiV+S+sfPhlbxLg9IxJSO952advEpJWYYZHnh/d -SuXfglSLjWra3VgLh6aho9/jQ7+7enrEru3JRvcCgYEAuo3484mmyN+gE0893PfQ -ebU3prOOJcHjpTIp1dB0gt1GcgSFpRpTn9RROwRVmoRoGe4pvVPPO763U0k0LPzf -IPij0OK+Y0rwC1kJJcd61LL8nJQ7Rhj60w26IbVOQSOzNZpiUQFQxLkfnx4kEmnA -VbIBD8Ap0SExFvAfFN3qZmsCgYA8c53meW1e8LC9TH/+xz4m5EEromhIVMg7eqbz -FXneBQaI/KonYQyrgFjIZY41E30GWAiNjiOGnkjMJf7UKSSlElRKucELBPLqGJ2s -vlvc6zXPCP8MhQ5/9J7OX1kXgEoxiOkh9nG8617xjOrlTWsG/oYCGk6gpgXrkUDy -/erUFQKBgQDY8h3pTIC3ZvFcy0+UpvVMceLWfaP9+/8dTpAr0HClNOjQC0Fuq6cV -nazAREnDB62y4keGV5xcZdHQ9bZBR4dq4h1oFQUq7RJr5fsgaxN13JPJht2xf/ra -hK3WKZN5oa/hrRu5m+z9rOwR4T7B863cBs/b1YNj3eKUIakHJEv5xw== ------END RSA PRIVATE KEY----- diff --git a/tests/integration/assets/test_03/cloud-config.yml b/tests/integration/assets/test_03/cloud-config.yml deleted file mode 100644 index 839f7782..00000000 --- a/tests/integration/assets/test_03/cloud-config.yml +++ /dev/null @@ -1,5 +0,0 @@ -#cloud-config -rancher: - console: debian -ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt diff --git a/tests/integration/assets/test_05/cloud-config.yml b/tests/integration/assets/test_05/cloud-config.yml deleted file mode 100644 index 839f7782..00000000 --- a/tests/integration/assets/test_05/cloud-config.yml +++ /dev/null @@ -1,5 +0,0 @@ -#cloud-config -rancher: - console: debian -ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt diff --git a/tests/integration/assets/test_11/cloud-config.yml b/tests/integration/assets/test_11/cloud-config.yml deleted file mode 100644 index c8956870..00000000 --- a/tests/integration/assets/test_11/cloud-config.yml +++ /dev/null @@ -1,18 +0,0 @@ -#cloud-config -rancher: - environment: - A: A - BB: BB - BC: BC - services: - env: - image: busybox - command: env - labels: - io.rancher.os.scope: system - io.rancher.os.before: console - environment: - - A - - B* -ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt diff --git a/tests/integration/assets/test_12/cloud-config.yml b/tests/integration/assets/test_12/cloud-config.yml deleted file mode 100644 index 164579e4..00000000 --- a/tests/integration/assets/test_12/cloud-config.yml +++ /dev/null @@ -1,3 +0,0 @@ -#cloud-config -ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt diff --git a/tests/integration/assets/test_13/cloud-config.yml b/tests/integration/assets/test_13/cloud-config.yml deleted file mode 100644 index 749199c8..00000000 --- a/tests/integration/assets/test_13/cloud-config.yml +++ /dev/null @@ -1,4 +0,0 @@ -#cloud-config -hostname: rancher-test -ssh_authorized_keys: - - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDUlsWAL5Rf0Wis/A7k7Tlqx0fZS60VzCZrPZYbP/wkL95jv0XzCx8bd1rZHeybblHPDNpND3BLv4qPY5DxRyexF4seGuzcJI/pOvGUGjQondeMPgDTFEo5w939gSdeTZcfXzQ0wAVhzwDbgH4zPfMzbdoo8Aiu9jkKljXw8IFju0gh+t6iKkGZCIjKT9o7zza1vGfkodhvi2V3VzPdNO28gaxZaRNtmBYUoVnGyR6nXN1Q3CJaVuh5o6GPCOqrhHNbYOFZKBpDiHbxPhVpxHQD2+8yUSGTG7WW75FfZePja5y8d0c/O5L37ZYx4AZAd3KgQYDBT2XCEJGQNawNbfpt diff --git a/tests/integration/requirements.txt b/tests/integration/requirements.txt deleted file mode 100644 index 59cebadf..00000000 --- a/tests/integration/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -PyYAML==3.11 -pytest==2.7.2 diff --git a/tests/integration/rostest/__init__.py b/tests/integration/rostest/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/integration/rostest/conftest.py b/tests/integration/rostest/conftest.py deleted file mode 100644 index 43afaba5..00000000 --- a/tests/integration/rostest/conftest.py +++ /dev/null @@ -1,13 +0,0 @@ -import subprocess - -import os -import pytest -import rostest - - -@pytest.fixture(scope="session", autouse=True) -def chdir_to_project_root(): - os.chdir(os.path.join(os.path.dirname(rostest.__file__), '../../..')) - print('\nChdir to project root dir: ' + subprocess.check_output('pwd')) - os.chmod('./tests/integration/assets/test.key', 0o600) - print('Also, `chmod 600 tests/integration/assets/test.key` to make ssh happy') diff --git a/tests/integration/rostest/test_00_system.py b/tests/integration/rostest/test_00_system.py deleted file mode 100644 index ee0a5194..00000000 --- a/tests/integration/rostest/test_00_system.py +++ /dev/null @@ -1,49 +0,0 @@ -from __future__ import print_function - -import subprocess - -import pytest -import rostest.util as u - - -@pytest.fixture(scope="module") -def qemu(request): - return u.run_qemu(request) - - -@pytest.mark.timeout(30) -def test_system_boot(qemu): - u.flush_out(qemu.stdout) - - -busybox = {'amd64': 'busybox', 'arm': 'armhf/busybox', 'arm64': 'aarch64/busybox'} - - -@pytest.mark.timeout(60) -def test_run_system_container(qemu): - u.wait_for_ssh(qemu) - - ssh = subprocess.Popen( - './scripts/ssh --qemu sudo system-docker run --rm ' + busybox[u.arch] + ' /bin/true', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) - - for ln in u.iter_lines(ssh.stdout): - print(ln) - ssh.wait() - - assert ssh.returncode == 0 - - -@pytest.mark.timeout(60) -def test_ros_dev(qemu): - u.wait_for_ssh(qemu) - - ssh = subprocess.Popen( - './scripts/ssh --qemu sudo ros dev', - shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) - - for ln in u.iter_lines(ssh.stdout): - print(ln) - ssh.wait() - - assert ssh.returncode == 0 diff --git a/tests/integration/rostest/test_01_cloud_config.py b/tests/integration/rostest/test_01_cloud_config.py deleted file mode 100644 index b0a88c51..00000000 --- a/tests/integration/rostest/test_01_cloud_config.py +++ /dev/null @@ -1,103 +0,0 @@ -import string - -import pytest -import rostest.util as u -from rostest.util import SSH -import yaml - -ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key'] -cloud_config_path = './tests/integration/assets/test_01/cloud-config.yml' - - -net_args = {'amd64': ['-net', 'nic,vlan=1,model=virtio,macaddr=52:54:00:12:34:59', - '-net', 'user,vlan=1,net=10.10.2.0/24'], - 'arm64': ['-netdev', 'user,id=net1,net=10.10.2.0/24', - '-device', 'virtio-net-device,netdev=net1,mac=52:54:00:12:34:59']} -net_args['arm'] = net_args['arm64'] - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--cloud-config', cloud_config_path] + net_args[u.arch]) - u.flush_out(q.stdout) - return q - - -@pytest.fixture(scope="module") -def cloud_config(): - return yaml.load(open(cloud_config_path)) - - -@pytest.mark.timeout(40) -def test_ssh_authorized_keys(qemu): - u.wait_for_ssh(qemu, ssh_command) - assert True - - -@pytest.mark.timeout(40) -def test_rancher_environment(qemu, cloud_config): - v = SSH(qemu, ssh_command).check_output(''' -sudo ros env printenv FLANNEL_NETWORK - '''.strip()) - - assert v.strip() == cloud_config['rancher']['environment']['FLANNEL_NETWORK'] - - -@pytest.mark.timeout(40) -def test_docker_args(qemu, cloud_config): - v = SSH(qemu, ssh_command).check_output(''' -ps -ef | grep docker - '''.strip()) - - expected = string.join(cloud_config['rancher']['docker']['args']) - - assert v.find(expected) != -1 - - -@pytest.mark.timeout(40) -def test_dhcpcd(qemu, cloud_config): - v = SSH(qemu, ssh_command).check_output(''' -ps -ef | grep dhcpcd - '''.strip()) - - assert v.find('dhcpcd -M') != -1 - - -@pytest.mark.timeout(40) -def test_services_include(qemu, cloud_config): - u.wait_for_ssh(qemu, ssh_command, ['docker inspect kernel-headers >/dev/null 2>&1']) - - -@pytest.mark.timeout(40) -def test_docker_tls_args(qemu, cloud_config): - SSH(qemu, ssh_command).check_call(''' -set -e -x -sudo ros tls gen --server -H localhost -sudo ros tls gen -sudo ros c set rancher.docker.tls true -sudo system-docker restart docker -sleep 5 -docker --tlsverify version - '''.strip()) - - -@pytest.mark.timeout(40) -def test_rancher_network(qemu, cloud_config): - v = SSH(qemu, ssh_command).check_output(''' -ip route get to 10.10.2.120 - '''.strip()) - - assert v.split(' ')[5] + '/24' == \ - cloud_config['rancher']['network']['interfaces']['mac=52:54:00:12:34:59']['address'] - - -def test_docker_pid_one(qemu): - SSH(qemu, ssh_command).check_call(''' -set -e -x -for i in $(pidof docker); do - if [ $i = 1 ]; then - found=true - fi -done -[ "$found" = "true" ] - '''.strip()) diff --git a/tests/integration/rostest/test_02_tls.py b/tests/integration/rostest/test_02_tls.py deleted file mode 100644 index b5c7bf19..00000000 --- a/tests/integration/rostest/test_02_tls.py +++ /dev/null @@ -1,22 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key'] -cloud_config_path = './tests/integration/assets/test_02/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -@pytest.mark.timeout(40) -def test_docker_tls_args(qemu): - SSH(qemu, ssh_command).check_call(''' -set -e -x -sudo ros tls gen -docker --tlsverify version - '''.strip()) diff --git a/tests/integration/rostest/test_03_docker_in_persistent_console.py b/tests/integration/rostest/test_03_docker_in_persistent_console.py deleted file mode 100644 index b492cc2b..00000000 --- a/tests/integration/rostest/test_03_docker_in_persistent_console.py +++ /dev/null @@ -1,38 +0,0 @@ -import time - -import pytest -import rostest.util as u -from rostest.util import SSH - -ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key'] -cloud_config_path = './tests/integration/assets/test_03/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -nginx = {'amd64': 'nginx', 'arm': 'armhfbuild/nginx', 'arm64': 'armhfbuild/nginx'} - - -@pytest.mark.timeout(40) -def test_reboot_with_container_running(qemu): - try: - SSH(qemu, ssh_command).check_call(''' -set -ex -docker run -d --restart=always %(image)s -sudo reboot - '''.strip() % {'image': nginx[u.arch]}) - except: - pass - - time.sleep(3) - - v = SSH(qemu, ssh_command).check_output(''' -docker ps -f status=running - '''.strip()) - - assert v.find('nginx') != -1 diff --git a/tests/integration/rostest/test_04_ros_install.py b/tests/integration/rostest/test_04_ros_install.py deleted file mode 100644 index b51899d1..00000000 --- a/tests/integration/rostest/test_04_ros_install.py +++ /dev/null @@ -1,34 +0,0 @@ -import subprocess - -import pytest -import rostest.util as u -from rostest.util import SSH - -ssh_command = ['./scripts/ssh', '--qemu'] - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--no-format']) - u.flush_out(q.stdout) - return q - - -@pytest.mark.timeout(40) -def test_ros_install_on_formatted_disk(qemu): - u.wait_for_ssh(qemu, ssh_command) - - subprocess.check_call( - ['sh', '-c', 'docker save rancher/os:%s%s | ./scripts/ssh sudo system-docker load' % (u.version, u.suffix)], - stderr=subprocess.STDOUT, universal_newlines=True) - - SSH(qemu, ssh_command).check_call(''' -set -e -x -sudo mkfs.ext4 /dev/vda -sudo ros install -f --no-reboot -d /dev/vda -i rancher/os:%s%s - '''.strip() % (u.version, u.suffix)) - - subprocess.call(ssh_command + ['sudo', 'reboot'], - stderr=subprocess.STDOUT, universal_newlines=True) - - u.wait_for_ssh(qemu, ssh_command) diff --git a/tests/integration/rostest/test_05_custom_docker_in_persistent_console.py b/tests/integration/rostest/test_05_custom_docker_in_persistent_console.py deleted file mode 100644 index dd906433..00000000 --- a/tests/integration/rostest/test_05_custom_docker_in_persistent_console.py +++ /dev/null @@ -1,39 +0,0 @@ -import subprocess - -import pytest -import rostest.util as u - -ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key'] -cloud_config_path = './tests/integration/assets/test_05/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - -docker_url = {'amd64': 'https://experimental.docker.com/builds/Linux/x86_64/docker-1.10.0-dev', - 'arm': 'https://github.com/rancher/docker/releases/download/v1.10.3-arm/docker-1.10.3_arm', - 'arm64': 'https://github.com/rancher/docker/releases/download/v1.10.3-arm/docker-1.10.3_arm64'} - - -@pytest.mark.timeout(40) -def test_system_docker_survives_custom_docker_install(qemu): - u.wait_for_ssh(qemu, ssh_command) - subprocess.check_call(ssh_command + ['curl', '-Lfo', './docker', docker_url[u.arch]], - stderr=subprocess.STDOUT, universal_newlines=True) - - subprocess.check_call(ssh_command + ['chmod', '+x', '/home/rancher/docker'], - stderr=subprocess.STDOUT, universal_newlines=True) - - subprocess.check_call(ssh_command + ['sudo', 'ln', '-sf', '/home/rancher/docker', '/usr/bin/docker'], - stderr=subprocess.STDOUT, universal_newlines=True) - - subprocess.check_call(ssh_command + ['sudo', 'system-docker', 'restart', 'docker'], - stderr=subprocess.STDOUT, universal_newlines=True) - - subprocess.check_call(ssh_command + ['sudo', 'system-docker', 'version'], - stderr=subprocess.STDOUT, universal_newlines=True) - - u.wait_for_ssh(qemu, ssh_command) diff --git a/tests/integration/rostest/test_06_subdir.py b/tests/integration/rostest/test_06_subdir.py deleted file mode 100644 index 4d8aad40..00000000 --- a/tests/integration/rostest/test_06_subdir.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--append', 'rancher.state.directory=ros_subdir']) - u.flush_out(q.stdout) - return q - - -def test_system_docker_survives_custom_docker_install(qemu): - SSH(qemu).check_call(''' -set -x -e -mkdir x -sudo mount $(sudo ros dev LABEL=RANCHER_STATE) x -[ -d x/ros_subdir/home/rancher ] - '''.strip()) diff --git a/tests/integration/rostest/test_09_network.py b/tests/integration/rostest/test_09_network.py deleted file mode 100644 index 66a58f29..00000000 --- a/tests/integration/rostest/test_09_network.py +++ /dev/null @@ -1,50 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -pytestmark = pytest.mark.skipif(u.arch != 'amd64', reason='amd64 network setup impossible to replicate for arm64') - -cloud_config_path = './tests/integration/assets/test_09/cloud-config.yml' - -net_args_arch = {'amd64': ['-net', 'nic,vlan=0,model=virtio'], - 'arm64': ['-device', 'virtio-net-device']} -net_args_arch['arm'] = net_args_arch['arm64'] -net_args = net_args_arch[u.arch] - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, - run_args=['--cloud-config', cloud_config_path] + - net_args + net_args + net_args + net_args + net_args + net_args + net_args) - u.flush_out(q.stdout) - return q - - -def test_network_interfaces_conf(qemu): - SSH(qemu).check_call('''cat > test-merge << "SCRIPT" -set -x -e - -ip link show dev br0 -ip link show dev br0.100 | grep br0.100@br0 -ip link show dev eth1.100 | grep 'master br0' -ip link show dev eth6 | grep 'master bond0' -ip link show dev eth7 | grep 'master bond0' -[ "$( test-merge << "SCRIPT" -set -x -e - -cat /etc/resolv.conf | grep "search mydomain.com example.com" -cat /etc/resolv.conf | grep "nameserver 208.67.222.123" -cat /etc/resolv.conf | grep "nameserver 208.67.220.123" - -SCRIPT -sudo bash test-merge - '''.strip()) diff --git a/tests/integration/rostest/test_10_network_from_url.py b/tests/integration/rostest/test_10_network_from_url.py deleted file mode 100644 index 550ad4d1..00000000 --- a/tests/integration/rostest/test_10_network_from_url.py +++ /dev/null @@ -1,62 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -pytestmark = pytest.mark.skipif(u.arch != 'amd64', reason='amd64 network setup impossible to replicate for arm64') - -cloud_config_path = './tests/integration/assets/test_10/cloud-config.yml' - -net_args_arch = {'amd64': ['-net', 'nic,vlan=0,model=virtio'], - 'arm64': ['-device', 'virtio-net-device']} -net_args_arch['arm'] = net_args_arch['arm64'] -net_args = net_args_arch[u.arch] - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, - run_args=['--cloud-config', cloud_config_path] + - net_args + net_args + net_args + net_args + net_args + net_args + net_args) - u.flush_out(q.stdout) - return q - - -def test_network_interfaces_conf(qemu): - SSH(qemu).check_call('''cat > test-merge << "SCRIPT" -set -x -e - -ip link show dev br0 -ip link show dev br0.100 | grep br0.100@br0 -ip link show dev eth1.100 | grep 'master br0' - -SCRIPT -sudo bash test-merge - '''.strip()) - - -def test_network_dns_conf(qemu): - SSH(qemu).check_call('''cat > test-merge << "SCRIPT" -set -x -e - -cat /etc/resolv.conf | grep "search mydomain.com example.com" -cat /etc/resolv.conf | grep "nameserver 208.67.222.123" -cat /etc/resolv.conf | grep "nameserver 208.67.220.123" - -SCRIPT -sudo bash test-merge - '''.strip()) - - -def test_network_dns_ros_set(qemu): - SSH(qemu).check_call(''' -set -x -e - -sudo ros config set rancher.network.dns.search '[a,b]' -if [ "$(sudo ros config get rancher.network.dns.search)" == "- a - - b - - " ]; then - sudo ros config get rancher.network.dns.search - exit 1 - fi - '''.strip()) diff --git a/tests/integration/rostest/test_11_environment.py b/tests/integration/rostest/test_11_environment.py deleted file mode 100644 index 01f36cf7..00000000 --- a/tests/integration/rostest/test_11_environment.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key'] -cloud_config_path = {'amd64': './tests/integration/assets/test_11/cloud-config.yml', - 'arm': './tests/integration/assets/test_11/cloud-config_arm.yml', - 'arm64': './tests/integration/assets/test_11/cloud-config_arm64.yml'} - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--cloud-config', cloud_config_path[u.arch]]) - u.flush_out(q.stdout) - return q - - -@pytest.mark.timeout(40) -def test_rancher_environment_in_system_service(qemu): - SSH(qemu, ssh_command).check_call(''' -sudo system-docker logs env | grep A=A -sudo system-docker logs env | grep BB=BB -sudo system-docker logs env | grep BC=BC - ''') diff --git a/tests/integration/rostest/test_12_dhcp_hostname.py b/tests/integration/rostest/test_12_dhcp_hostname.py deleted file mode 100644 index 92ba3453..00000000 --- a/tests/integration/rostest/test_12_dhcp_hostname.py +++ /dev/null @@ -1,21 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key'] -cloud_config_path = './tests/integration/assets/test_12/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -@pytest.mark.timeout(40) -def test_dhcp_hostname(qemu): - SSH(qemu, ssh_command).check_call(''' -hostname | grep rancher-dev -cat /etc/hosts | grep rancher-dev - ''') diff --git a/tests/integration/rostest/test_13_cloud_config_hostname.py b/tests/integration/rostest/test_13_cloud_config_hostname.py deleted file mode 100644 index bd607932..00000000 --- a/tests/integration/rostest/test_13_cloud_config_hostname.py +++ /dev/null @@ -1,21 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -ssh_command = ['./scripts/ssh', '--qemu', '--key', './tests/integration/assets/test.key'] -cloud_config_path = './tests/integration/assets/test_13/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, ['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -@pytest.mark.timeout(40) -def test_cloud_config_hostname(qemu): - SSH(qemu, ssh_command).check_call(''' -hostname | grep rancher-test -cat /etc/hosts | grep rancher-test - ''') diff --git a/tests/integration/rostest/test_15_shared_mount.py b/tests/integration/rostest/test_15_shared_mount.py deleted file mode 100644 index 9c0154f6..00000000 --- a/tests/integration/rostest/test_15_shared_mount.py +++ /dev/null @@ -1,21 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request) - u.flush_out(q.stdout) - return q - - -def test_shared_mount(qemu): - SSH(qemu).check_call(''' -set -x -e - -sudo mkdir /mnt/shared -sudo touch /test -sudo system-docker run --privileged -v /mnt:/mnt:shared -v /test:/test {busybox_image} mount --bind / /mnt/shared -ls /mnt/shared | grep test - '''.format(busybox_image=u.busybox_image)) diff --git a/tests/integration/rostest/test_16_cloud_config_mounts.py b/tests/integration/rostest/test_16_cloud_config_mounts.py deleted file mode 100644 index 69b7f0d1..00000000 --- a/tests/integration/rostest/test_16_cloud_config_mounts.py +++ /dev/null @@ -1,17 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - - -cloud_config_path = './tests/integration/assets/test_16/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -def test_cloud_config_mounts(qemu): - SSH(qemu).check_call('cat /home/rancher/test | grep test') diff --git a/tests/integration/rostest/test_17_http_proxy.py b/tests/integration/rostest/test_17_http_proxy.py deleted file mode 100644 index f2601bf7..00000000 --- a/tests/integration/rostest/test_17_http_proxy.py +++ /dev/null @@ -1,45 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -cloud_config_path = './tests/integration/assets/test_17/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -def test_docker_http_proxy(qemu): - SSH(qemu).check_call(''' -set -x -e - -sudo system-docker exec docker env | grep HTTP_PROXY=invalid -sudo system-docker exec docker env | grep HTTPS_PROXY=invalid -sudo system-docker exec docker env | grep NO_PROXY=invalid - -if docker pull busybox; then - exit 1 -else - exit 0 -fi - ''') - - -def test_system_docker_http_proxy(qemu): - try: - SSH(qemu).check_call('sudo reboot') - except: - pass - - SSH(qemu).check_call(''' -set -x -e - -if sudo system-docker pull busybox; then - exit 1 -else - exit 0 -fi - ''') diff --git a/tests/integration/rostest/test_18_network_on_boot.py b/tests/integration/rostest/test_18_network_on_boot.py deleted file mode 100644 index dcab210d..00000000 --- a/tests/integration/rostest/test_18_network_on_boot.py +++ /dev/null @@ -1,26 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -pytestmark = pytest.mark.skipif(u.arch != 'amd64', reason='amd64 network setup impossible to replicate for arm64') - -cloud_config_path = './tests/integration/assets/test_18/cloud-config.yml' - -net_args_arch = {'amd64': ['-net', 'nic,vlan=1,model=virtio'], - 'arm64': ['-device', 'virtio-net-device']} -net_args_arch['arm'] = net_args_arch['arm64'] -net_args = net_args_arch[u.arch] - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, - run_args=['--cloud-config', cloud_config_path] + - net_args + net_args + net_args) - u.flush_out(q.stdout) - return q - - -def test_network_resources_loaded(qemu): - SSH(qemu).check_call("apt-get --version") - SSH(qemu).check_call("sudo system-docker images | grep tianon/true") diff --git a/tests/integration/rostest/test_19_lenient_service_parsing.py b/tests/integration/rostest/test_19_lenient_service_parsing.py deleted file mode 100644 index fa7fdfc8..00000000 --- a/tests/integration/rostest/test_19_lenient_service_parsing.py +++ /dev/null @@ -1,18 +0,0 @@ -import time -import pytest -import rostest.util as u -from rostest.util import SSH - -cloud_config_path = './tests/integration/assets/test_19/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -def test_lenient_service_parsing(qemu): - time.sleep(5) - SSH(qemu).check_call("sudo system-docker ps -a | grep test-parsing") diff --git a/tests/integration/rostest/test_20_sysctl.py b/tests/integration/rostest/test_20_sysctl.py deleted file mode 100644 index cf7de89d..00000000 --- a/tests/integration/rostest/test_20_sysctl.py +++ /dev/null @@ -1,17 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -cloud_config_path = './tests/integration/assets/test_20/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -def test_sysctl(qemu): - SSH(qemu).check_call("sudo cat /proc/sys/kernel/domainname | grep test") - SSH(qemu).check_call("sudo cat /proc/sys/dev/cdrom/debug | grep 1") diff --git a/tests/integration/rostest/test_21_swap.py b/tests/integration/rostest/test_21_swap.py deleted file mode 100644 index 9b1f9d40..00000000 --- a/tests/integration/rostest/test_21_swap.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -import rostest.util as u -from rostest.util import SSH - -cloud_config_path = './tests/integration/assets/test_21/cloud-config.yml' - - -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--second-drive', '--cloud-config', - cloud_config_path]) - u.flush_out(q.stdout) - return q - - -def test_swap(qemu): - SSH(qemu).check_call("sudo mkswap /dev/vdb") - SSH(qemu).check_call("sudo cloud-init -execute") - SSH(qemu).check_call("cat /proc/swaps | grep /dev/vdb") diff --git a/tests/integration/rostest/util.py b/tests/integration/rostest/util.py deleted file mode 100644 index 9837c697..00000000 --- a/tests/integration/rostest/util.py +++ /dev/null @@ -1,116 +0,0 @@ -from __future__ import print_function - -import itertools as it -import os -import subprocess -import time - -import pytest - -ros_test = 'ros-test' -arch = os.environ.get('ARCH', 'amd64') -version = os.environ.get('VERSION') -suffix = os.environ.get('SUFFIX') - - -if version is None or version == '' or suffix is None: - raise RuntimeError("Could not get VERSION or SUFFIX from environment") - - -busybox_image = {'amd64': 'busybox', - 'arm': 'armhf/busybox', - 'arm64': 'aarch64/busybox'}[arch] - - -def iter_lines(s): - return it.imap(str.rstrip, iter(s.readline, '')) - - -def strip_comment(prefix): - return lambda s: s.partition(prefix)[0].strip() - - -def non_empty(s): - return s != '' - - -def parse_value(var): - def get_value(s): - (k, _, v) = s.partition('=') - (k, v) = (k.strip(), v.strip()) - if k == var: - return v - return '' - - return get_value - - -def with_effect(p): - def effect(s): - p(s) - return s - - return effect - - -def run_qemu(request, run_args=[]): - print('\nStarting QEMU') - p = subprocess.Popen(['./scripts/run', '--qemu', '--no-rebuild', '--no-rm-usr', '--fresh'] + run_args, - stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) - assert p.returncode is None - - def fin(): - print('\nTerminating QEMU') - p.terminate() - p.wait() - - request.addfinalizer(fin) - return p - - -def has_substr(token): - return lambda s: str.find(s, token) > -1 - - -def flush_out(stdout, substr='RancherOS '): - for _ in it.ifilter(has_substr(substr), - it.imap(with_effect(print), iter_lines(stdout))): - return - - -@pytest.mark.timeout(10) -def wait_for_ssh(qemu, ssh_command=['./scripts/ssh', '--qemu'], command=['docker version >/dev/null 2>&1']): - i = 0 - assert qemu.returncode is None - print('\nWaiting for ssh and docker... ' + str(i)) - while subprocess.call(ssh_command + command) != 0: - i += 1 - print('\nWaiting for ssh and docker... ' + str(i)) - time.sleep(1) - if i > 150: - raise AssertionError('Failed to connect to SSH') - assert qemu.returncode is None - - -class SSH: - def __init__(self, qemu, ssh_command=['./scripts/ssh', '--qemu']): - self._qemu = qemu - self._ssh_command = ssh_command - self._waited = False - - def wait(self): - if not self._waited: - wait_for_ssh(self._qemu, ssh_command=self._ssh_command) - self._waited = True - - def check_call(self, *args, **kw): - self.wait() - kw['stderr'] = subprocess.STDOUT - kw['universal_newlines'] = True - return subprocess.check_call(self._ssh_command + list(args), **kw) - - def check_output(self, *args, **kw): - self.wait() - kw['stderr'] = subprocess.STDOUT - kw['universal_newlines'] = True - return subprocess.check_output(self._ssh_command + list(args), **kw) diff --git a/tests/integration/setup.py b/tests/integration/setup.py deleted file mode 100644 index 2d48f65b..00000000 --- a/tests/integration/setup.py +++ /dev/null @@ -1,11 +0,0 @@ -from distutils.core import setup - -setup( - name='RancherOSIntegrationTests', - version='0.1', - packages=[ - 'rostest' - ], - license='ASL 2.0', - long_description=open('README.txt').read(), -) diff --git a/tests/integration/tox.ini b/tests/integration/tox.ini deleted file mode 100644 index bdd1de7f..00000000 --- a/tests/integration/tox.ini +++ /dev/null @@ -1,15 +0,0 @@ -[tox] -envlist=flake8, py27 -skipsdist=True - -[testenv] -deps=-rrequirements.txt -passenv=HOST_ARCH ARCH VERSION SUFFIX -commands=py.test -s --durations=20 rostest {posargs} - -[testenv:flake8] -deps=flake8 -commands=flake8 rostest - -[flake8] -max-line-length = 120 diff --git a/tests/lenient_service_parsing_test.go b/tests/lenient_service_parsing_test.go new file mode 100644 index 00000000..d19521f5 --- /dev/null +++ b/tests/lenient_service_parsing_test.go @@ -0,0 +1,12 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestLenientServiceParsing(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_19/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, ` +sleep 5 +sudo system-docker ps -a | grep test-parsing`) +} diff --git a/tests/misc_test.go b/tests/misc_test.go new file mode 100644 index 00000000..e3f0f20a --- /dev/null +++ b/tests/misc_test.go @@ -0,0 +1,35 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestMisc(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_01/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, "sudo ros env printenv FLANNEL_NETWORK | grep '10.244.0.0/16'") + + s.CheckCall(c, "ps -ef | grep 'daemon --log-opt max-file=2 --log-opt max-size=25m -s overlay -G docker -H unix:///var/run/docker.sock --userland-proxy=false'") + s.CheckCall(c, "ps -ef | grep 'dhcpcd -M'") + + s.CheckCall(c, ` +set -e -x +sudo ros tls gen --server -H localhost +sudo ros tls gen +sudo ros c set rancher.docker.tls true +sudo system-docker restart docker +sleep 5 +docker --tlsverify version`) + + s.CheckCall(c, ` +set -e -x +for i in $(pidof docker); do + if [ $i = 1 ]; then + found=true + fi +done +[ "$found" = "true" ]`) + + s.CheckCall(c, ` +sleep 5 +docker inspect kernel-headers`) +} diff --git a/tests/network_from_url_test.go b/tests/network_from_url_test.go new file mode 100644 index 00000000..fac7d018 --- /dev/null +++ b/tests/network_from_url_test.go @@ -0,0 +1,35 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestNetworkFromUrl(c *C) { + netArgs := []string{"-net", "nic,vlan=0,model=virtio"} + args := []string{"--cloud-config", "./tests/assets/test_10/cloud-config.yml"} + for i := 0; i < 7; i++ { + args = append(args, netArgs...) + } + err := s.RunQemu(args...) + c.Assert(err, IsNil) + + s.CheckCall(c, ` +cat > test-merge << "SCRIPT" +set -x -e + +ip link show dev br0 +ip link show dev br0.100 | grep br0.100@br0 +ip link show dev eth1.100 | grep 'master br0' + +SCRIPT +sudo bash test-merge`) + + s.CheckCall(c, ` +cat > test-merge << "SCRIPT" +set -x -e + +cat /etc/resolv.conf | grep "search mydomain.com example.com" +cat /etc/resolv.conf | grep "nameserver 208.67.222.123" +cat /etc/resolv.conf | grep "nameserver 208.67.220.123" + +SCRIPT +sudo bash test-merge`) +} diff --git a/tests/network_on_boot_test.go b/tests/network_on_boot_test.go new file mode 100644 index 00000000..6ffc570d --- /dev/null +++ b/tests/network_on_boot_test.go @@ -0,0 +1,11 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestNetworkOnBoot(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_18/cloud-config.yml", "-net", "nic,vlan=1,model=virtio") + c.Assert(err, IsNil) + + s.CheckCall(c, "apt-get --version") + s.CheckCall(c, "sudo system-docker images | grep tianon/true") +} diff --git a/tests/network_test.go b/tests/network_test.go new file mode 100644 index 00000000..ba603473 --- /dev/null +++ b/tests/network_test.go @@ -0,0 +1,38 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestNetwork(c *C) { + netArgs := []string{"-net", "nic,vlan=0,model=virtio"} + args := []string{"--cloud-config", "./tests/assets/test_09/cloud-config.yml"} + for i := 0; i < 7; i++ { + args = append(args, netArgs...) + } + err := s.RunQemu(args...) + c.Assert(err, IsNil) + + s.CheckCall(c, ` +cat > test-merge << "SCRIPT" +set -x -e + +ip link show dev br0 +ip link show dev br0.100 | grep br0.100@br0 +ip link show dev eth1.100 | grep 'master br0' +ip link show dev eth6 | grep 'master bond0' +ip link show dev eth7 | grep 'master bond0' +[ "$( test-merge << "SCRIPT" +set -x -e + +cat /etc/resolv.conf | grep "search mydomain.com example.com" +cat /etc/resolv.conf | grep "nameserver 208.67.222.123" +cat /etc/resolv.conf | grep "nameserver 208.67.220.123" + +SCRIPT +sudo bash test-merge`) +} diff --git a/tests/integration/rostest/test_07_oem.py b/tests/oem_test.go similarity index 50% rename from tests/integration/rostest/test_07_oem.py rename to tests/oem_test.go index aea8767e..1ce23799 100644 --- a/tests/integration/rostest/test_07_oem.py +++ b/tests/oem_test.go @@ -1,19 +1,12 @@ -import time -import pytest -import rostest.util as u -from rostest.util import SSH +package integration +import . "gopkg.in/check.v1" -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--append', 'rancher.state.dev=x']) - u.flush_out(q.stdout) - return q +func (s *QemuSuite) TestOem(c *C) { + err := s.RunQemu("--append", "rancher.state.dev=x") + c.Assert(err, IsNil) - -def test_oem(qemu): - try: - SSH(qemu).check_call(''' + s.CheckCall(c, ` set -x set -e sudo mkfs.ext4 -L RANCHER_OEM /dev/vda @@ -25,15 +18,11 @@ rancher: url: 'foo' EOF sudo cp /tmp/oem-config.yml /mnt -sudo umount /mnt -sudo reboot - '''.strip()) - except: - pass +sudo umount /mnt`) - time.sleep(3) + s.Reboot() - SSH(qemu).check_call(''' + s.CheckCall(c, ` set -x if [ ! -e /usr/share/ros/oem/oem-config.yml ]; then echo Failed to find /usr/share/ros/oem/oem-config.yml @@ -44,5 +33,5 @@ FOO="$(sudo ros config get rancher.upgrade.url)" if [ "$FOO" != "foo" ]; then echo rancher.upgrade.url is not foo exit 1 -fi - '''.strip()) +fi`) +} diff --git a/tests/integration/rostest/test_14_ros_config.py b/tests/ros_config_test.go similarity index 68% rename from tests/integration/rostest/test_14_ros_config.py rename to tests/ros_config_test.go index 4a05f9f8..fb96ac8c 100644 --- a/tests/integration/rostest/test_14_ros_config.py +++ b/tests/ros_config_test.go @@ -1,19 +1,12 @@ -import pytest -import rostest.util as u -from rostest.util import SSH +package integration -cloud_config_path = './tests/integration/assets/test_14/cloud-config.yml' +import . "gopkg.in/check.v1" +func (s *QemuSuite) TestRosConfig(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_14/cloud-config.yml") + c.Assert(err, IsNil) -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request, run_args=['--cloud-config', cloud_config_path]) - u.flush_out(q.stdout) - return q - - -def test_ros_config_string(qemu): - SSH(qemu).check_call(''' + s.CheckCall(c, ` set -x -e if [ "$(sudo ros config get hostname)" == "hostname3 @@ -27,12 +20,9 @@ if [ "$(sudo ros config get hostname)" == "rancher-test " ]; then sudo ros config get hostname exit 1 - fi - '''.strip()) + fi`) - -def test_ros_config_bool(qemu): - SSH(qemu).check_call(''' + s.CheckCall(c, ` set -x -e if [ "$(sudo ros config get rancher.log)" == "true @@ -59,12 +49,9 @@ if [ "$(sudo ros config get rancher.debug)" == "true " ]; then sudo ros config get rancher.debug exit 1 - fi - '''.strip()) +fi`) - -def test_ros_config_slice(qemu): - SSH(qemu).check_call(''' + s.CheckCall(c, ` set -x -e sudo ros config set rancher.network.dns.search '[a,b]' @@ -81,12 +68,9 @@ if [ "$(sudo ros config get rancher.network.dns.search)" == "[] " ]; then sudo ros config get rancher.network.dns.search exit 1 - fi - '''.strip()) + fi`) - -def test_ros_export(qemu): - SSH(qemu).check_call(''' + s.CheckCall(c, ` set -x -e if sudo ros config export | grep "PRIVATE KEY"; then @@ -99,5 +83,5 @@ sudo ros config export --full | grep "udev" sudo ros config export --private --full | grep "ntp" sudo ros config export --full | grep "labels" -sudo ros config export --private --full | grep "PRIVATE KEY" - '''.strip()) +sudo ros config export --private --full | grep "PRIVATE KEY"`) +} diff --git a/tests/shared_mount_test.go b/tests/shared_mount_test.go new file mode 100644 index 00000000..de70b588 --- /dev/null +++ b/tests/shared_mount_test.go @@ -0,0 +1,20 @@ +package integration + +import ( + "fmt" + + . "gopkg.in/check.v1" +) + +func (s *QemuSuite) TestSharedMount(c *C) { + err := s.RunQemu() + c.Assert(err, IsNil) + + s.CheckCall(c, fmt.Sprintf(` +set -x -e + +sudo mkdir /mnt/shared +sudo touch /test +sudo system-docker run --privileged -v /mnt:/mnt:shared -v /test:/test %s mount --bind / /mnt/shared +ls /mnt/shared | grep test`, BusyboxImage)) +} diff --git a/tests/integration/rostest/test_08_ssh_key_merge.py b/tests/ssh_key_merge_test.go similarity index 57% rename from tests/integration/rostest/test_08_ssh_key_merge.py rename to tests/ssh_key_merge_test.go index 0e49d365..05ef929c 100644 --- a/tests/integration/rostest/test_08_ssh_key_merge.py +++ b/tests/ssh_key_merge_test.go @@ -1,17 +1,13 @@ -import pytest -import rostest.util as u -from rostest.util import SSH +package integration +import . "gopkg.in/check.v1" -@pytest.fixture(scope="module") -def qemu(request): - q = u.run_qemu(request) - u.flush_out(q.stdout) - return q +func (s *QemuSuite) TestSshKeyMerge(c *C) { + err := s.RunQemu() + c.Assert(err, IsNil) - -def test_ssh_key_merging(qemu): - SSH(qemu).check_call('''cat > test-merge << "SCRIPT" + s.CheckCall(c, ` +cat > test-merge << "SCRIPT" set -x -e rm /var/lib/rancher/conf/cloud-config.yml @@ -39,5 +35,5 @@ ros config get ssh_authorized_keys > got diff got expected SCRIPT -sudo bash test-merge - '''.strip()) +sudo bash test-merge`) +} diff --git a/tests/subdir_test.go b/tests/subdir_test.go new file mode 100644 index 00000000..9d4afa67 --- /dev/null +++ b/tests/subdir_test.go @@ -0,0 +1,14 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestSubdir(c *C) { + err := s.RunQemu("--append", "rancher.state.directory=ros_subdir") + c.Assert(err, IsNil) + + s.CheckCall(c, ` +set -x -e +mkdir x +sudo mount $(sudo ros dev LABEL=RANCHER_STATE) x +[ -d x/ros_subdir/home/rancher ]`) +} diff --git a/tests/swap_test.go b/tests/swap_test.go new file mode 100644 index 00000000..e712584f --- /dev/null +++ b/tests/swap_test.go @@ -0,0 +1,12 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestSwap(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_21/cloud-config.yml", "--second-drive") + c.Assert(err, IsNil) + + s.CheckCall(c, "sudo mkswap /dev/vdb") + s.CheckCall(c, "sudo cloud-init -execute") + s.CheckCall(c, "cat /proc/swaps | grep /dev/vdb") +} diff --git a/tests/sysctl_test.go b/tests/sysctl_test.go new file mode 100644 index 00000000..b7b3ff3b --- /dev/null +++ b/tests/sysctl_test.go @@ -0,0 +1,11 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestSysctl(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_20/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, "sudo cat /proc/sys/kernel/domainname | grep test") + s.CheckCall(c, "sudo cat /proc/sys/dev/cdrom/debug | grep 1") +} diff --git a/tests/tls_test.go b/tests/tls_test.go new file mode 100644 index 00000000..7a816f97 --- /dev/null +++ b/tests/tls_test.go @@ -0,0 +1,13 @@ +package integration + +import . "gopkg.in/check.v1" + +func (s *QemuSuite) TestTls(c *C) { + err := s.RunQemu("--cloud-config", "./tests/assets/test_02/cloud-config.yml") + c.Assert(err, IsNil) + + s.CheckCall(c, ` +set -e -x +sudo ros tls gen +docker --tlsverify version`) +}