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.

173 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 current tests/ directory ; even when testing old version,
  19. # we want the up-to-date test setup/provisionning
  20. git checkout "${CI_COMMIT_SHA}" -- tests/
  21. fi
  22. # needed for ara not to complain
  23. export TZ=UTC
  24. export ANSIBLE_REMOTE_USER=$SSH_USER
  25. export ANSIBLE_BECOME=true
  26. export ANSIBLE_BECOME_USER=root
  27. export ANSIBLE_CALLBACK_PLUGINS="$(python -m ara.setup.callback_plugins)"
  28. export ANSIBLE_INVENTORY=${CI_PROJECT_DIR}/inventory/sample/
  29. make -C tests INVENTORY_DIR=${ANSIBLE_INVENTORY} create-${CI_PLATFORM} -s
  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. -e @tests/common_vars.yml \
  50. -e @tests/files/${CI_JOB_NAME}.yml \
  51. -e local_release_dir=${PWD}/downloads \
  52. "$@" \
  53. ${playbook}
  54. }
  55. # Create cluster
  56. run_playbook cluster.yml
  57. # Repeat deployment if testing upgrade
  58. if [ "${UPGRADE_TEST}" != "false" ]; then
  59. git checkout "${CI_COMMIT_SHA}"
  60. case "${UPGRADE_TEST}" in
  61. "basic")
  62. run_playbook cluster.yml
  63. ;;
  64. "graceful")
  65. run_playbook upgrade-cluster.yml
  66. ;;
  67. *)
  68. ;;
  69. esac
  70. fi
  71. # Test control plane recovery
  72. if [ "${RECOVER_CONTROL_PLANE_TEST}" != "false" ]; then
  73. run_playbook reset.yml --limit "${RECOVER_CONTROL_PLANE_TEST_GROUPS}" -e reset_confirmation=yes
  74. run_playbook recover-control-plane.yml -e etcd_retries=10 --limit "etcd:kube_control_plane"
  75. fi
  76. # Test collection build and install by installing our collection, emptying our repository, adding
  77. # cluster.yml, reset.yml, and remote-node.yml files that simply point to our collection's playbooks, and then
  78. # running the same tests as before
  79. if [[ "${CI_JOB_NAME}" =~ "collection" ]]; then
  80. # Build and install collection
  81. ansible-galaxy collection build
  82. ansible-galaxy collection install kubernetes_sigs-kubespray-$(grep "^version:" galaxy.yml | awk '{print $2}').tar.gz
  83. # Simply remove all of our files and directories except for our tests directory
  84. # to be absolutely certain that none of our playbooks or roles
  85. # are interfering with our collection
  86. find -maxdepth 1 ! -name tests -exec rm -rfv {} \;
  87. # Write cluster.yml
  88. cat > cluster.yml <<EOF
  89. - name: Install Kubernetes
  90. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.cluster
  91. EOF
  92. # Write reset.yml
  93. cat > reset.yml <<EOF
  94. - name: Remove Kubernetes
  95. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.reset
  96. EOF
  97. # Write remove-node.yml
  98. cat > remove-node.yml <<EOF
  99. - name: Remove node from Kubernetes
  100. ansible.builtin.import_playbook: kubernetes_sigs.kubespray.remove_node
  101. EOF
  102. fi
  103. # Tests Cases
  104. ## Test Control Plane API
  105. run_playbook tests/testcases/010_check-apiserver.yml
  106. run_playbook tests/testcases/015_check-nodes-ready.yml
  107. ## Test that all nodes are Ready
  108. if [[ ! ( "$CI_JOB_NAME" =~ "macvlan" ) ]]; then
  109. run_playbook tests/testcases/020_check-pods-running.yml
  110. run_playbook tests/testcases/030_check-network.yml
  111. if [[ ! ( "$CI_JOB_NAME" =~ "hardening" ) ]]; then
  112. # TODO: We need to remove this condition by finding alternative container
  113. # image instead of netchecker which doesn't work at hardening environments.
  114. run_playbook tests/testcases/040_check-network-adv.yml
  115. fi
  116. fi
  117. ## Kubernetes conformance tests
  118. run_playbook tests/testcases/100_check-k8s-conformance.yml
  119. if [ "${IDEMPOT_CHECK}" = "true" ]; then
  120. ## Idempotency checks 1/5 (repeat deployment)
  121. run_playbook cluster.yml
  122. ## Idempotency checks 2/5 (Advanced DNS checks)
  123. if [[ ! ( "$CI_JOB_NAME" =~ "hardening" ) ]]; then
  124. run_playbook tests/testcases/040_check-network-adv.yml
  125. fi
  126. if [ "${RESET_CHECK}" = "true" ]; then
  127. ## Idempotency checks 3/5 (reset deployment)
  128. run_playbook reset.yml -e reset_confirmation=yes
  129. ## Idempotency checks 4/5 (redeploy after reset)
  130. run_playbook cluster.yml
  131. ## Idempotency checks 5/5 (Advanced DNS checks)
  132. if [[ ! ( "$CI_JOB_NAME" =~ "hardening" ) ]]; then
  133. run_playbook tests/testcases/040_check-network-adv.yml
  134. fi
  135. fi
  136. fi
  137. # Test node removal procedure
  138. if [ "${REMOVE_NODE_CHECK}" = "true" ]; then
  139. run_playbook remove-node.yml -e skip_confirmation=yes -e node=${REMOVE_NODE_NAME}
  140. fi
  141. # Clean up at the end, this is to allow stage1 tests to include cleanup test
  142. if [ "${RESET_CHECK}" = "true" ]; then
  143. run_playbook reset.yml -e reset_confirmation=yes
  144. fi