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.

175 lines
5.5 KiB

  1. #!/bin/bash
  2. set -euxo pipefail
  3. echo "CI_JOB_NAME is $CI_JOB_NAME"
  4. if [[ "$CI_JOB_NAME" =~ "upgrade" ]]; then
  5. if [ "${UPGRADE_TEST}" == "false" ]; then
  6. echo "Job name contains 'upgrade', but UPGRADE_TEST='false'"
  7. exit 1
  8. fi
  9. else
  10. if [ "${UPGRADE_TEST}" != "false" ]; then
  11. echo "UPGRADE_TEST!='false', but job names does not contain 'upgrade'"
  12. exit 1
  13. fi
  14. fi
  15. # Check out latest tag if testing upgrade
  16. if [ "${UPGRADE_TEST}" != "false" ]; then
  17. git fetch --all && git checkout "$KUBESPRAY_VERSION"
  18. # Checkout the CI vars file so it is available
  19. git checkout "${CI_COMMIT_SHA}" tests/files/${CI_JOB_NAME}.yml
  20. git checkout "${CI_COMMIT_SHA}" ${CI_TEST_REGISTRY_MIRROR}
  21. git checkout "${CI_COMMIT_SHA}" ${CI_TEST_SETTING}
  22. fi
  23. # needed for ara not to complain
  24. export TZ=UTC
  25. export ANSIBLE_REMOTE_USER=$SSH_USER
  26. export ANSIBLE_BECOME=true
  27. export ANSIBLE_BECOME_USER=root
  28. export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.setup.callback_plugins)"
  29. cd tests && make create-${CI_PLATFORM} -s ; cd -
  30. ansible-playbook tests/cloud_playbooks/wait-for-ssh.yml
  31. # Flatcar Container Linux needs auto update disabled
  32. if [[ "$CI_JOB_NAME" =~ "coreos" ]]; then
  33. ansible all -m raw -a 'systemctl disable locksmithd'
  34. ansible all -m raw -a 'systemctl stop locksmithd'
  35. mkdir -p /opt/bin && ln -s /usr/bin/python /opt/bin/python
  36. fi
  37. if [[ "$CI_JOB_NAME" =~ "opensuse" ]]; then
  38. # OpenSUSE needs netconfig update to get correct resolv.conf
  39. # See https://goinggnu.wordpress.com/2013/10/14/how-to-fix-the-dns-in-opensuse-13-1/
  40. ansible all -m raw -a 'netconfig update -f'
  41. # Auto import repo keys
  42. ansible all -m raw -a 'zypper --gpg-auto-import-keys refresh'
  43. fi
  44. run_playbook () {
  45. playbook=$1
  46. shift
  47. # We can set --limit here and still pass it as supplemental args because `--limit` is a 'last one wins' option
  48. ansible-playbook \
  49. $ANSIBLE_LOG_LEVEL \
  50. -e @${CI_TEST_SETTING} \
  51. -e @${CI_TEST_REGISTRY_MIRROR} \
  52. -e @${CI_TEST_VARS} \
  53. -e local_release_dir=${PWD}/downloads \
  54. "$@" \
  55. ${playbook}
  56. }
  57. # Create cluster
  58. run_playbook cluster.yml
  59. # Repeat deployment if testing upgrade
  60. if [ "${UPGRADE_TEST}" != "false" ]; then
  61. git checkout "${CI_COMMIT_SHA}"
  62. case "${UPGRADE_TEST}" in
  63. "basic")
  64. run_playbook cluster.yml
  65. ;;
  66. "graceful")
  67. run_playbook upgrade-cluster.yml
  68. ;;
  69. *)
  70. ;;
  71. esac
  72. fi
  73. # Test control plane recovery
  74. if [ "${RECOVER_CONTROL_PLANE_TEST}" != "false" ]; then
  75. run_playbook reset.yml --limit "${RECOVER_CONTROL_PLANE_TEST_GROUPS}" -e reset_confirmation=yes
  76. run_playbook recover-control-plane.yml -e etcd_retries=10 --limit "etcd:kube_control_plane"
  77. fi
  78. # Test collection build and install by installing our collection, emptying our repository, adding
  79. # cluster.yml, reset.yml, and remote-node.yml files that simply point to our collection's playbooks, and then
  80. # running the same tests as before
  81. if [[ "${CI_JOB_NAME}" =~ "collection" ]]; then
  82. # Build and install collection
  83. ansible-galaxy collection build
  84. ansible-galaxy collection install kubernetes_sigs-kubespray-$(grep "^version:" galaxy.yml | awk '{print $2}').tar.gz
  85. # Simply remove all of our files and directories except for our tests directory
  86. # to be absolutely certain that none of our playbooks or roles
  87. # are interfering with our collection
  88. find -maxdepth 1 ! -name tests -exec rm -rfv {} \;
  89. # Write cluster.yml
  90. cat > cluster.yml <<EOF
  91. - name: Install Kubernetes
  92. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.cluster
  93. EOF
  94. # Write reset.yml
  95. cat > reset.yml <<EOF
  96. - name: Remove Kubernetes
  97. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.reset
  98. EOF
  99. # Write remove-node.yml
  100. cat > remove-node.yml <<EOF
  101. - name: Remove node from Kubernetes
  102. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.remove_node
  103. EOF
  104. fi
  105. # Tests Cases
  106. ## Test Control Plane API
  107. run_playbook tests/testcases/010_check-apiserver.yml
  108. run_playbook tests/testcases/015_check-nodes-ready.yml
  109. ## Test that all nodes are Ready
  110. if [[ ! ( "$CI_JOB_NAME" =~ "macvlan" ) ]]; then
  111. run_playbook tests/testcases/020_check-pods-running.yml
  112. run_playbook tests/testcases/030_check-network.yml
  113. if [[ ! ( "$CI_JOB_NAME" =~ "hardening" ) ]]; then
  114. # TODO: We need to remove this condition by finding alternative container
  115. # image instead of netchecker which doesn't work at hardening environments.
  116. run_playbook tests/testcases/040_check-network-adv.yml
  117. fi
  118. fi
  119. ## Kubernetes conformance tests
  120. run_playbook tests/testcases/100_check-k8s-conformance.yml
  121. if [ "${IDEMPOT_CHECK}" = "true" ]; then
  122. ## Idempotency checks 1/5 (repeat deployment)
  123. run_playbook cluster.yml
  124. ## Idempotency checks 2/5 (Advanced DNS checks)
  125. if [[ ! ( "$CI_JOB_NAME" =~ "hardening" ) ]]; then
  126. run_playbook tests/testcases/040_check-network-adv.yml
  127. fi
  128. if [ "${RESET_CHECK}" = "true" ]; then
  129. ## Idempotency checks 3/5 (reset deployment)
  130. run_playbook reset.yml -e reset_confirmation=yes
  131. ## Idempotency checks 4/5 (redeploy after reset)
  132. run_playbook cluster.yml
  133. ## Idempotency checks 5/5 (Advanced DNS checks)
  134. if [[ ! ( "$CI_JOB_NAME" =~ "hardening" ) ]]; then
  135. run_playbook tests/testcases/040_check-network-adv.yml
  136. fi
  137. fi
  138. fi
  139. # Test node removal procedure
  140. if [ "${REMOVE_NODE_CHECK}" = "true" ]; then
  141. run_playbook remove-node.yml -e skip_confirmation=yes -e node=${REMOVE_NODE_NAME}
  142. fi
  143. # Clean up at the end, this is to allow stage1 tests to include cleanup test
  144. if [ "${RESET_CHECK}" = "true" ]; then
  145. run_playbook reset.yml -e reset_confirmation=yes
  146. fi