4 SCRIPTDIR="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
5 LIBDIR="$(dirname $(dirname ${SCRIPTDIR}))/env/lib"
7 source $LIBDIR/logging.sh
8 source $LIBDIR/common.sh
10 BUILDDIR=${SCRIPTDIR/deploy/build}
13 function install_deps {
17 function is_emco_ready {
18 local -r cluster_name=${CLUSTER_NAME:-icn}
19 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
20 kubectl --kubeconfig=${cluster_kubeconfig} -n emco wait pod --all --for=condition=Ready --timeout=0s >/dev/null 2>&1
23 function register_emco_controllers {
24 wait_for is_emco_ready
25 local -r cluster_name=${CLUSTER_NAME:-icn}
26 local -r host=$(kubectl -n metal3 get cluster/${cluster_name} -o jsonpath='{.spec.controlPlaneEndpoint.host}')
27 cat <<EOF >${BUILDDIR}/${cluster_name}-config.yaml
32 cat <<EOF >${BUILDDIR}/${cluster_name}-controllers.yaml
76 emcoctl --config ${BUILDDIR}/${cluster_name}-config.yaml apply -f ${BUILDDIR}/${cluster_name}-controllers.yaml
79 function unregister_emco_controllers {
80 local -r cluster_name=${CLUSTER_NAME:-icn}
81 emcoctl --config ${BUILDDIR}/${cluster_name}-config.yaml delete -f ${BUILDDIR}/${cluster_name}-controllers.yaml
84 function is_addon_ready {
86 local -r cluster_name=${CLUSTER_NAME:-icn}
87 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
88 if [[ $(kubectl --kubeconfig=${cluster_kubeconfig} -n kud get Kustomization/${addon} -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}') != "True" ]]; then
92 # Additional addon specific checks
95 for node in $(kubectl --kubeconfig=${cluster_kubeconfig} -n kud get pods -l app=cmk-reconcile-ds-all -o jsonpath='{range .items[*]}{.spec.nodeName}{"\n"}{end}' | sort | uniq); do
96 kubectl --kubeconfig=${cluster_kubeconfig} get cmk-nodereport ${node}
99 "node-feature-discovery")
100 node_name=$(kubectl --kubeconfig=${cluster_kubeconfig} get nodes -o jsonpath='{range .items[*]}{.metadata.name} {.spec.taints[?(@.effect=="NoSchedule")].effect}{"\n"}{end}' | awk 'NF==1 {print $0;exit}')
101 kernel_version=$(kubectl --kubeconfig=${cluster_kubeconfig} get node ${node_name} -o jsonpath='{.metadata.labels.feature\.node\.kubernetes\.io/kernel-version\.major}')
102 [[ -n ${kernel_version} ]]
107 function test_openebs {
108 local -r cluster_name=${CLUSTER_NAME:-icn}
109 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
110 kubectl --kubeconfig=${cluster_kubeconfig} apply -f ${SCRIPTDIR}/openebs-cstor.yaml
111 kubectl --kubeconfig=${cluster_kubeconfig} wait pod hello-cstor-csi-disk-pod --for=condition=Ready --timeout=5m
112 kubectl --kubeconfig=${cluster_kubeconfig} exec -it hello-cstor-csi-disk-pod -- cat /mnt/store/greet.txt
113 kubectl --kubeconfig=${cluster_kubeconfig} delete -f ${SCRIPTDIR}/openebs-cstor.yaml
116 function test_addons {
119 # Create a temporary kubeconfig file for the tests
120 local -r cluster_name=${CLUSTER_NAME:-icn}
121 local -r cluster_kubeconfig="${BUILDDIR}/${cluster_name}.conf"
122 clusterctl -n metal3 get kubeconfig ${cluster_name} >${cluster_kubeconfig}
125 # The vFW test in EMCO v21.12 does not use KubeVirt, so patch the
126 # KuD test and continue to use it
128 patch -p1 --forward <${SCRIPTDIR}/plugin_fw_v2.patch || true
131 pushd ${KUDPATH}/kud/tests
133 container_runtime=$(KUBECONFIG=${cluster_kubeconfig} kubectl get nodes -o jsonpath='{.items[].status.nodeInfo.containerRuntimeVersion}')
134 # TODO Temporarily remove kubevirt from kud_tests below. The
135 # kubevirt self-test needs AllowTcpForwarding yes in
136 # /etc/ssh/sshd_config which is currently disabled by the OS
137 # security hardening.
138 if [[ "${container_runtime}" == "containerd://1.2.13" ]]; then
139 # With containerd 1.2.13, the qat test container image fails to unpack.
140 kud_tests="topology-manager-sriov:sriov-network multus:multus-cni ovn4nfv:nodus-network nfd:node-feature-discovery sriov-network:sriov-network cmk:cpu-manager"
142 kud_tests="topology-manager-sriov:sriov-network multus:multus-cni ovn4nfv:nodus-network nfd:node-feature-discovery sriov-network:sriov-network qat:qat-plugin cmk:cpu-manager"
144 for kud_test in ${kud_tests}; do
145 addon="${kud_test#*:}"
146 test="${kud_test%:*}"
147 if [[ ! -z ${addon} ]]; then
148 wait_for is_addon_ready ${addon}
150 KUBECONFIG=${cluster_kubeconfig} bash ${test}.sh || failed_tests="${failed_tests} ${test}"
152 # The plugin_fw_v2 test needs the EMCO controllers in place
153 register_emco_controllers
154 DEMO_FOLDER=${KUDPATH}/kud/demo KUBECONFIG=${cluster_kubeconfig} bash plugin_fw_v2.sh --external || failed_tests="${failed_tests} plugin_fw_v2"
155 unregister_emco_controllers
158 test_openebs || failed_tests="${failed_tests} openebs"
160 if [[ ! -z "$failed_tests" ]]; then
161 echo "Test cases failed:${failed_tests}"
164 echo "All test cases passed"
166 rm ${cluster_kubeconfig}
170 "test") test_addons ;;
172 Usage: $(basename $0) COMMAND
174 The "test" command looks for the CLUSTER_NAME variable in the
175 environment (default: "icn"). This should be the name of the
176 Cluster resource to execute the tests in.
179 test - Test the addons