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.

120 lines
6.2 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. # Check out latest tag if testing upgrade
  42. test "${UPGRADE_TEST}" != "false" && git fetch --all && git checkout "$KUBESPRAY_VERSION"
  43. # Checkout the CI vars file so it is available
  44. test "${UPGRADE_TEST}" != "false" && git checkout "${CI_BUILD_REF}" tests/files/${CI_JOB_NAME}.yml
  45. test "${UPGRADE_TEST}" != "false" && git checkout "${CI_BUILD_REF}" ${CI_TEST_REGISTRY_MIRROR}
  46. test "${UPGRADE_TEST}" != "false" && git checkout "${CI_BUILD_REF}" ${CI_TEST_SETTING}
  47. # Create cluster
  48. 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
  49. # Repeat deployment if testing upgrade
  50. if [ "${UPGRADE_TEST}" != "false" ]; then
  51. test "${UPGRADE_TEST}" == "basic" && PLAYBOOK="cluster.yml"
  52. test "${UPGRADE_TEST}" == "graceful" && PLAYBOOK="upgrade-cluster.yml"
  53. git checkout "${CI_BUILD_REF}"
  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" $PLAYBOOK
  55. fi
  56. # Test control plane recovery
  57. if [ "${RECOVER_CONTROL_PLANE_TEST}" != "false" ]; then
  58. 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
  59. 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
  60. fi
  61. # Tests Cases
  62. ## Test Master API
  63. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/010_check-apiserver.yml $ANSIBLE_LOG_LEVEL
  64. ## Test that all nodes are Ready
  65. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/015_check-nodes-ready.yml $ANSIBLE_LOG_LEVEL
  66. ## Test that all pods are Running
  67. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/020_check-pods-running.yml $ANSIBLE_LOG_LEVEL
  68. ## Test pod creation and ping between them
  69. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/030_check-network.yml $ANSIBLE_LOG_LEVEL
  70. ## Advanced DNS checks
  71. ansible-playbook --limit "all:!fake_hosts" -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} tests/testcases/040_check-network-adv.yml $ANSIBLE_LOG_LEVEL
  72. ## Kubernetes conformance tests
  73. 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
  74. if [ "${IDEMPOT_CHECK}" = "true" ]; then
  75. ## Idempotency checks 1/5 (repeat deployment)
  76. 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
  77. ## Idempotency checks 2/5 (Advanced DNS checks)
  78. ansible-playbook ${ANSIBLE_LOG_LEVEL} -e @${CI_TEST_VARS} ${CI_TEST_ADDITIONAL_VARS} --limit "all:!fake_hosts" tests/testcases/040_check-network-adv.yml
  79. if [ "${RESET_CHECK}" = "true" ]; then
  80. ## Idempotency checks 3/5 (reset deployment)
  81. 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
  82. ## Idempotency checks 4/5 (redeploy after reset)
  83. 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
  84. ## Idempotency checks 5/5 (Advanced DNS checks)
  85. 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
  86. fi
  87. fi
  88. # Test node removal procedure
  89. if [ "${REMOVE_NODE_CHECK}" = "true" ]; then
  90. 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
  91. fi
  92. # Clean up at the end, this is to allow stage1 tests to include cleanup test
  93. if [ "${RESET_CHECK}" = "true" ]; then
  94. 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
  95. fi