-
Notifications
You must be signed in to change notification settings - Fork 23
/
test-prow-e2e.sh
executable file
·144 lines (110 loc) · 4.88 KB
/
test-prow-e2e.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env bash
set -eExuo pipefail
if [ $# -eq 0 ]
then
echo "kubevirt plugin image not provided"
echo "exiting..."
exit 1
fi
function generateLogsAndCopyArtifacts {
oc cluster-info dump > ${ARTIFACT_DIR}/cluster_info.json
oc get catalogsource -A -o wide > ${ARTIFACT_DIR}/catalogsource.yaml
oc get catalogsource -A -o yaml >> ${ARTIFACT_DIR}/catalogsource.yaml
oc get subscriptions -n ${NS} -o wide > ${ARTIFACT_DIR}/subscription_details.yaml
oc get subscriptions -n ${NS} -o yaml >> ${ARTIFACT_DIR}/subscription_details.yaml
oc get csvs -n ${NS} -o wide > ${ARTIFACT_DIR}/csvs.yaml
oc get csvs -n ${NS} -o yaml >> ${ARTIFACT_DIR}/csvs.yaml
oc get deployments -n ${NS} -o wide > ${ARTIFACT_DIR}/deployment_details.yaml
oc get deployments -n ${NS} -o yaml >> ${ARTIFACT_DIR}/deployment_details.yaml
oc get installplan -n ${NS} -o wide > ${ARTIFACT_DIR}/installplan.yaml
oc get installplan -n ${NS} -o yaml >> ${ARTIFACT_DIR}/installplan.yaml
oc get nodes -o wide > ${ARTIFACT_DIR}/node.yaml
oc get nodes -o yaml >> ${ARTIFACT_DIR}/node.yaml
oc get pods -n ${NS} -o wide >> ${ARTIFACT_DIR}/pod_details_openshift-kubevirt.yaml
oc get pods -n ${NS} -o yaml >> ${ARTIFACT_DIR}/pod_details_openshift-kubevirt.yaml
for pod in `oc get pods -n ${NS} --no-headers -o custom-columns=":metadata.name" | grep "kubevirt"`; do
echo $pod
oc logs $pod -n ${NS} > ${ARTIFACT_DIR}/${pod}.logs
done
oc get serviceaccounts -n ${NS} -o wide > ${ARTIFACT_DIR}/serviceaccount.yaml
oc get serviceaccounts -n ${NS} -o yaml >> ${ARTIFACT_DIR}/serviceaccount.yaml
oc get console.v1.operator.openshift.io cluster -o yaml >> ${ARTIFACT_DIR}/cluster.yaml
if [ -d "$ARTIFACT_DIR" ] && [ -d "$SCREENSHOTS_DIR" ]; then
if [[ -z "$(ls -A -- "$SCREENSHOTS_DIR")" ]]; then
echo "No artifacts were copied."
else
echo "Copying artifacts from $(pwd)..."
cp -r "$SCREENSHOTS_DIR" "${ARTIFACT_DIR}/gui-test-screenshots"
fi
fi
}
trap generateLogsAndCopyArtifacts EXIT
trap generateLogsAndCopyArtifacts ERR
PULL_SECRET_PATH="/var/run/operator-secret/dockerconfig"
NAMESPACE="openshift-marketplace"
SECRET_NAME="ocs-secret"
NS="kubevirt-hyperconverged"
ARTIFACT_DIR=${ARTIFACT_DIR:=/tmp/artifacts}
SCREENSHOTS_DIR="cypress/gui-test-screenshots"
function createSecret {
oc create secret generic ${SECRET_NAME} --from-file=.dockerconfigjson=${PULL_SECRET_PATH} --type=kubernetes.io/dockerconfigjson -n $1
}
function linkSecrets {
for serviceAccount in `oc get serviceaccounts -n ${NS} --no-headers -o custom-columns=":metadata.name" | sed 's/"//g'`; do
echo "Linking ${SECRET_NAME} to ${serviceAccount}"
oc secrets link ${serviceAccount} ${SECRET_NAME} -n ${NS} --for=pull
done
}
function deleteAllPods {
oc delete pods --all -n $1
}
echo "Creating secret for CI builds in ${NAMESPACE}"
createSecret ${NAMESPACE}
echo "Creating secret for linking pods"
createSecret ${NS}
echo "Adding secret to all service accounts in ${NS} namespace"
linkSecrets
echo "Restarting pods for secret update"
deleteAllPods ${NS}
sleep 30
echo "Adding secret to all service accounts in ${NS} namespace"
linkSecrets
echo "Restarting pods for secret update"
deleteAllPods ${NS}
sleep 120
echo "Adding secret to all service accounts in ${NS} namespace"
linkSecrets
echo "Restarting pods for secret update"
deleteAllPods ${NS}
sleep 120
# Enable console plugin for Kubevirt
export CONSOLE_CONFIG_NAME="cluster"
export KUBEVIRT_PLUGIN_NAME="kubevirt-plugin"
KUBEVIRT_PLUGIN_IMAGE="$1"
echo "Modify the kubevirt console plugin image"
CSV=$(oc get csv -o name -n ${NS})
oc get $CSV -n ${NS} -o json > /tmp/hco_csv.json
EXISTING_PLUGIN_IMAGE=$(jq -r '.spec.install.spec.deployments[] | select(.name=="hco-operator").spec.template.spec.containers[0].env[] | select(.name=="KV_CONSOLE_PLUGIN_IMAGE").value' /tmp/hco_csv.json)
sed -i -r "s|$EXISTING_PLUGIN_IMAGE|$KUBEVIRT_PLUGIN_IMAGE|" /tmp/hco_csv.json
oc apply -f /tmp/hco_csv.json
until \
oc wait pods -n ${NS} --for=jsonpath='{.spec.containers[0].image}'="$KUBEVIRT_PLUGIN_IMAGE" -l app=kubevirt-hyperconverged -l app.kubernetes.io/component=kubevirt-console-plugin
do
sleep 1
done
INSTALLER_DIR=${INSTALLER_DIR:=${ARTIFACT_DIR}/installer}
BRIDGE_KUBEADMIN_PASSWORD="$(cat "${KUBEADMIN_PASSWORD_FILE:-${INSTALLER_DIR}/auth/kubeadmin-password}")"
export BRIDGE_KUBEADMIN_PASSWORD
BRIDGE_BASE_ADDRESS="$(oc get consoles.config.openshift.io cluster -o jsonpath='{.status.consoleURL}')"
export BRIDGE_BASE_ADDRESS
# Disable color codes in Cypress since they do not render well CI test logs.
# https://docs.cypress.io/guides/guides/continuous-integration.html#Colors
export NO_COLOR=1
# Install dependencies.
yarn install --ignore-engines
# Add mochawesome-report-generator
yarn add global mochawesome-report-generator --ignore-engines
# Run tests.
yarn run test-cypress-headless
# Generate Cypress report.
yarn run cypress-postreport