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.

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