Merge "Update provisioned OS to Ubuntu 20.04"
[icn.git] / deploy / addons / addons.sh
1 #!/usr/bin/env bash
2 set -eux -o pipefail
3
4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib"
6
7 source $LIBDIR/logging.sh
8 source $LIBDIR/common.sh
9
10 BUILDDIR=${SCRIPTDIR/deploy/build}
11 mkdir -p ${BUILDDIR}
12
13 function register_emco_controllers {
14     local -r cluster_name=${CLUSTER_NAME:-e2etest}
15     local -r host=$(kubectl -n metal3 get cluster/${cluster_name} -o jsonpath='{.spec.controlPlaneEndpoint.host}')
16     cat <<EOF >${BUILDDIR}/${cluster_name}-config.yaml
17 orchestrator:
18   host: ${host}
19   port: 30415
20 EOF
21     cat <<EOF >${BUILDDIR}/${cluster_name}-controllers.yaml
22 ---
23 version: emco/v2
24 resourceContext:
25   anchor: controllers
26 metadata:
27   name: rsync
28 spec:
29   host: ${host}
30   port: 30441
31 ---
32 version: emco/v2
33 resourceContext:
34   anchor: controllers
35 metadata:
36   name: gac
37 spec:
38   host: ${host}
39   port: 30493
40   type: "action"
41   priority: 1
42 ---
43 version: emco/v2
44 resourceContext:
45   anchor: controllers
46 metadata:
47   name: ovnaction
48 spec:
49   host: ${host}
50   port: 30473
51   type: "action"
52   priority: 1
53 ---
54 version: emco/v2
55 resourceContext:
56   anchor: controllers
57 metadata:
58   name: dtc
59 spec:
60   host: ${host}
61   port: 30483
62   type: "action"
63   priority: 1
64 EOF
65     emcoctl --config ${BUILDDIR}/${cluster_name}-config.yaml apply -f ${BUILDDIR}/${cluster_name}-controllers.yaml
66 }
67
68 function unregister_emco_controllers {
69     local -r cluster_name=${CLUSTER_NAME:-e2etest}
70     emcoctl --config ${BUILDDIR}/${cluster_name}-config.yaml delete -f ${BUILDDIR}/${cluster_name}-controllers.yaml
71 }
72
73 function test_addons {
74     # Create a temporary kubeconfig file for the tests
75     local -r cluster_name=${CLUSTER_NAME:-e2etest}
76     local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
77     clusterctl -n metal3 get kubeconfig ${cluster_name} >${cluster_kubeconfig}
78
79     clone_kud_repository
80     pushd ${KUDPATH}/kud/tests
81     failed_kud_tests=""
82     container_runtime=$(KUBECONFIG=${cluster_kubeconfig} kubectl get nodes -o jsonpath='{.items[].status.nodeInfo.containerRuntimeVersion}')
83     if [[ "${container_runtime}" == "containerd://1.2.13" ]]; then
84         # With containerd 1.2.13, the qat test container image fails to unpack.
85         kud_tests="topology-manager-sriov kubevirt multus ovn4nfv nfd sriov-network cmk"
86     else
87         kud_tests="topology-manager-sriov kubevirt multus ovn4nfv nfd sriov-network qat cmk"
88     fi
89     for test in ${kud_tests}; do
90         KUBECONFIG=${cluster_kubeconfig} bash ${test}.sh || failed_kud_tests="${failed_kud_tests} ${test}"
91     done
92     # The plugin_fw_v2 test needs the EMCO controllers in place
93     register_emco_controllers
94     DEMO_FOLDER=${KUDPATH}/kud/demo KUBECONFIG=${cluster_kubeconfig} bash plugin_fw_v2.sh --external || failed_kud_tests="${failed_kud_tests} plugin_fw_v2"
95     unregister_emco_controllers
96     popd
97     if [[ ! -z "$failed_kud_tests" ]]; then
98         echo "Test cases failed:${failed_kud_tests}"
99         exit 1
100     fi
101     echo "All test cases passed"
102
103     rm ${cluster_kubeconfig}
104 }
105
106 case $1 in
107     "test") test_addons ;;
108     *) cat <<EOF
109 Usage: $(basename $0) COMMAND
110
111 The "test" command looks for the CLUSTER_NAME variable in the
112 environment (default: "e2etest").  This should be the name of the
113 Cluster resource to execute the tests in.
114
115 Commands:
116   test  - Test the addons
117 EOF
118        ;;
119 esac