Rename cluster-e2etest to cluster-icn
[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:-icn}
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:-icn}
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:-icn}
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     # TODO Temporarily remove kubevirt from kud_tests below.  The
84     # kubevirt self-test needs AllowTcpForwarding yes in
85     # /etc/ssh/sshd_config which is currently disabled by the OS
86     # security hardening.
87     if [[ "${container_runtime}" == "containerd://1.2.13" ]]; then
88         # With containerd 1.2.13, the qat test container image fails to unpack.
89         kud_tests="topology-manager-sriov multus ovn4nfv nfd sriov-network cmk"
90     else
91         kud_tests="topology-manager-sriov multus ovn4nfv nfd sriov-network qat cmk"
92     fi
93     for test in ${kud_tests}; do
94         KUBECONFIG=${cluster_kubeconfig} bash ${test}.sh || failed_kud_tests="${failed_kud_tests} ${test}"
95     done
96     # The plugin_fw_v2 test needs the EMCO controllers in place
97     register_emco_controllers
98     DEMO_FOLDER=${KUDPATH}/kud/demo KUBECONFIG=${cluster_kubeconfig} bash plugin_fw_v2.sh --external || failed_kud_tests="${failed_kud_tests} plugin_fw_v2"
99     unregister_emco_controllers
100     popd
101     if [[ ! -z "$failed_kud_tests" ]]; then
102         echo "Test cases failed:${failed_kud_tests}"
103         exit 1
104     fi
105     echo "All test cases passed"
106
107     rm ${cluster_kubeconfig}
108 }
109
110 case $1 in
111     "test") test_addons ;;
112     *) cat <<EOF
113 Usage: $(basename $0) COMMAND
114
115 The "test" command looks for the CLUSTER_NAME variable in the
116 environment (default: "icn").  This should be the name of the
117 Cluster resource to execute the tests in.
118
119 Commands:
120   test  - Test the addons
121 EOF
122        ;;
123 esac