You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
6.5 KiB

  1. #!/bin/bash
  2. set -euxo pipefail
  3. echo "CI_JOB_NAME is $CI_JOB_NAME"
  4. CI_TEST_ADDITIONAL_VARS=""
  5. if [[ "$CI_JOB_NAME" =~ "upgrade" ]]; then
  6. if [ "${UPGRADE_TEST}" == "false" ]; then
  7. echo "Job name contains 'upgrade', but UPGRADE_TEST='false'"
  8. exit 1
  9. fi
  10. else
  11. if [ "${UPGRADE_TEST}" != "false" ]; then
  12. echo "UPGRADE_TEST!='false', but job names does not contain 'upgrade'"
  13. exit 1
  14. fi
  15. fi
  16. # needed for ara not to complain
  17. export TZ=UTC
  18. export ANSIBLE_REMOTE_USER=$SSH_USER
  19. export ANSIBLE_BECOME=true
  20. export ANSIBLE_BECOME_USER=root
  21. export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.setup.callback_plugins)"
  22. cd tests && make create-${CI_PLATFORM} -s ; cd -
  23. ansible-playbook tests/cloud_playbooks/wait-for-ssh.yml
  24. # Flatcar Container Linux needs auto update disabled
  25. if [[ "$CI_JOB_NAME" =~ "coreos" ]]; then
  26. ansible all -m raw -a 'systemctl disable locksmithd'
  27. ansible all -m raw -a 'systemctl stop locksmithd'
  28. mkdir -p /opt/bin && ln -s /usr/bin/python /opt/bin/python
  29. fi
  30. if [[ "$CI_JOB_NAME" =~ "opensuse" ]]; then
  31. # OpenSUSE needs netconfig update to get correct resolv.conf
  32. # See https://goinggnu.wordpress.com/2013/10/14/how-to-fix-the-dns-in-opensuse-13-1/
  33. ansible all -m raw -a 'netconfig update -f'
  34. # Auto import repo keys
  35. ansible all -m raw -a 'zypper --gpg-auto-import-keys refresh'
  36. fi
  37. if [[ "$CI_JOB_NAME" =~ "ubuntu" ]]; then
  38. # We need to tell ansible that ubuntu hosts are python3 only
  39. CI_TEST_ADDITIONAL_VARS="-e ansible_python_interpreter=/usr/bin/python3"
  40. fi
  41. ENABLE_040_TEST="true"
  42. if [[ "$CI_JOB_NAME" =~ "hardening" ]]; then
  43. # TODO: We need to remove this condition by finding alternative container
  44. # image instead of netchecker which doesn't work at hardening environments.
  45. ENABLE_040_TEST="false"
  46. fi
  47. # Check out latest tag if testing upgrade
  48. test "${UPGRADE_TEST}" != "false" && git fetch --all && git checkout "$KUBESPRAY_VERSION"
  49. # Checkout the CI vars file so it is available
  50. test "${UPGRADE_TEST}" != "false" && git checkout "${CI_BUILD_REF}" tests/files/${CI_JOB_NAME}.yml
  51. test "${UPGRADE_TEST}" != "false" && git checkout "${CI_BUILD_REF}" ${CI_TEST_REGISTRY_MIRROR}
  52. test "${UPGRADE_TEST}" != "false" && git checkout "${CI_BUILD_REF}" ${CI_TEST_SETTING}
  53. # Create cluster
  54. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} -e local_release_dir=${PWD}/downloads --limit "all:!fake_hosts" cluster.yml
  55. # Repeat deployment if testing upgrade
  56. if [ "${UPGRADE_TEST}" != "false" ]; then
  57. test "${UPGRADE_TEST}" == "basic" && PLAYBOOK="cluster.yml"
  58. test "${UPGRADE_TEST}" == "graceful" && PLAYBOOK="upgrade-cluster.yml"
  59. git checkout "${CI_BUILD_REF}"
  60. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} -e local_release_dir=${PWD}/downloads --limit "all:!fake_hosts" $PLAYBOOK
  61. fi
  62. # Test control plane recovery
  63. if [ "${RECOVER_CONTROL_PLANE_TEST}" != "false" ]; then
  64. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} -e local_release_dir=${PWD}/downloads --limit "${RECOVER_CONTROL_PLANE_TEST_GROUPS}:!fake_hosts" -e reset_confirmation=yes reset.yml
  65. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} -e local_release_dir=${PWD}/downloads -e etcd_retries=10 --limit etcd,kube_control_plane:!fake_hosts recover-control-plane.yml
  66. fi
  67. # Tests Cases
  68. ## Test Master API
  69. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/010_check-apiserver.yml $ANSIBLE_LOG_LEVEL
  70. ## Test that all nodes are Ready
  71. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/015_check-nodes-ready.yml $ANSIBLE_LOG_LEVEL
  72. ## Test that all pods are Running
  73. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/020_check-pods-running.yml $ANSIBLE_LOG_LEVEL
  74. ## Test pod creation and ping between them
  75. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/030_check-network.yml $ANSIBLE_LOG_LEVEL
  76. ## Advanced DNS checks
  77. if [ "${ENABLE_040_TEST}" = "true" ]; then
  78. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/040_check-network-adv.yml $ANSIBLE_LOG_LEVEL
  79. fi
  80. ## Kubernetes conformance tests
  81. ansible-playbook -i ${ANSIBLE_INVENTORY} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} --limit "all:!fake_hosts" tests/testcases/100_check-k8s-conformance.yml $ANSIBLE_LOG_LEVEL
  82. if [ "${IDEMPOT_CHECK}" = "true" ]; then
  83. ## Idempotency checks 1/5 (repeat deployment)
  84. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} ${CI_TEST_ADDITIONAL_VARS} -e @${CI_TEST_VARS} -e local_release_dir=${PWD}/downloads --limit "all:!fake_hosts" cluster.yml
  85. ## Idempotency checks 2/5 (Advanced DNS checks)
  86. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} --limit "all:!fake_hosts" tests/testcases/040_check-network-adv.yml
  87. if [ "${RESET_CHECK}" = "true" ]; then
  88. ## Idempotency checks 3/5 (reset deployment)
  89. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} -e reset_confirmation=yes --limit "all:!fake_hosts" reset.yml
  90. ## Idempotency checks 4/5 (redeploy after reset)
  91. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} -e local_release_dir=${PWD}/downloads --limit "all:!fake_hosts" cluster.yml
  92. ## Idempotency checks 5/5 (Advanced DNS checks)
  93. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} --limit "all:!fake_hosts" tests/testcases/040_check-network-adv.yml
  94. fi
  95. fi
  96. # Test node removal procedure
  97. if [ "${REMOVE_NODE_CHECK}" = "true" ]; then
  98. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} -e skip_confirmation=yes -e node=${REMOVE_NODE_NAME} --limit "all:!fake_hosts" remove-node.yml
  99. fi
  100. # Clean up at the end, this is to allow stage1 tests to include cleanup test
  101. if [ "${RESET_CHECK}" = "true" ]; then
  102. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_SETTING} -e @${CI_TEST_REGISTRY_MIRROR} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} -e reset_confirmation=yes --limit "all:!fake_hosts" reset.yml
  103. fi