Debian Codegraph @

ansible_collections/vmware/vmware_rest/tests/integration/run_eco_vcenter_ci.sh

raw
1 #!/usr/bin/env bash
2 # shellcheck disable=SC2155,SC2086
3
4 GREEN="\033[0;32m"
5 RED="\033[0;31m"
6 NC="\033[0m" # No Color
7 BASE_DIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")")
8 TEST_OUTPUT_LOG="/tmp/vmware_vmware_rest_tests_report.txt"
9
10 if [ -f "$TEST_OUTPUT_LOG" ]; then
11 rm -f "$TEST_OUTPUT_LOG"
12 fi
13
14 # Generates a string starting with 'test-' followed by 4 random lowercase characters
15 tiny_prefix="test-vmware-rest-$(uuidgen | tr -d '-' | cut -c1-4 | tr '[:upper:]' '[:lower:]')"
16 if grep -qa 'tiny_prefix' "${BASE_DIR}/integration_config.yml"; then
17 sed -i "s|tiny_prefix:.*|tiny_prefix: $tiny_prefix|" "${BASE_DIR}/integration_config.yml"
18 else
19 echo "tiny_prefix: $tiny_prefix" >> "${BASE_DIR}/integration_config.yml"
20 fi
21
22 echo ""
23 echo ""
24 echo "****** Starting Eco vCenter tests ******"
25 grep 'tiny_prefix' ${BASE_DIR}/integration_config.yml
26 grep 'vcenter_hostname' ${BASE_DIR}/integration_config.yml
27 echo ""
28 echo ""
29
30 failed=0
31 total=0
32 {
33 echo "==============="
34 echo "Tests Summary"
35 echo "==============="
36 } >> "$TEST_OUTPUT_LOG"
37
38 for target in $(ansible-test integration --list-target | grep 'vmware_'); do
39 echo "Running integration test for $target"
40 total=$((total + 1))
41 if ansible-test integration $target --skip-tags force-simulator-run; then
42 echo -e "Test: $target ${GREEN}Passed${NC}" | tee -a "$TEST_OUTPUT_LOG"
43 else
44 echo -e "Test: $target ${RED}Failed${NC}" | tee -a "$TEST_OUTPUT_LOG"
45 failed=$((failed + 1))
46 fi
47 done
48 echo "$failed test(s) failed out of $total." >> "$TEST_OUTPUT_LOG"
49 cat "$TEST_OUTPUT_LOG"
50 if [ $failed -gt 0 ]; then
51 exit 1
52 fi