Skip to content

Commit

Permalink
Added oauth provision and executing tests from image
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrewTSW committed Jul 3, 2023
1 parent e758607 commit 6792f7d
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 35 deletions.
165 changes: 142 additions & 23 deletions .ci/oci-dashboard-happy-path.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
# SPDX-License-Identifier: EPL-2.0
#

set +e
set -e
set -o pipefail
set -u
set -x

export CHE_REPO_BRANCH=${CHE_REPO_BRANCH:-"main"}
export CHE_REPO_ARCHIVE=${CHE_REPO_ARCHIVE:-"https://github.com/eclipse/che/archive/refs/heads/${CHE_REPO_BRANCH}.zip"}
START=$(date +%s.%N)
SCRIPT_DIR=$(dirname $(readlink -f "$0"))

export WORKDIR=${WORKDIR:-"${SCRIPT_DIR}/workdir"}
export CHE_NAMESPACE=${CHE_NAMESPACE:-"eclipse-che"}
export HAPPY_PATH_POD_NAME='happy-path-che'
export HAPPY_PATH_POD_FILE="${SCRIPT_DIR}/resources/pod-che-smoke-test.yaml"
export ARTIFACT_DIR=${ARTIFACT_DIR:-"/tmp/devworkspace-happy-path-artifacts"}

# debug info regarding system executables
which docker
which podman
which git
which npm
rm -rf ${WORKDIR}
mkdir -p ${WORKDIR}

# method originally extracted from eclipse/che/tests/devworkspace-happy-path/common.sh
function bumpPodsInfo() {
Expand Down Expand Up @@ -57,27 +61,142 @@ function collectLogs() {
echo "[INFO] Logs are collected and can be found in $ARTIFACT_DIR"
}

# method originally extracted from eclipse/che/tests/devworkspace-happy-path/launch.sh
# Create cluster-admin user inside of OpenShift cluster and login
function provisionOpenShiftOAuthUser() {
echo "[INFO] Testing if Che User exists."
KUBECONFIG="${KUBECONFIG:-${HOME}/.kube/config}"
TMP_KUBECONFIG="$WORKDIR/kubeconfig"
cp "$KUBECONFIG" "$TMP_KUBECONFIG"

if oc login -u che-user -p user --kubeconfig $TMP_KUBECONFIG; then
echo "[INFO] Che User already exists. Using it"
return 0
fi
echo "[INFO] Che User does not exist. Setting up htpasswd oauth for it."
oc delete secret dev-htpasswd-secret -n openshift-config || true
oc create secret generic dev-htpasswd-secret --from-file=htpasswd="$SCRIPT_DIR/resources/users.htpasswd" -n openshift-config

if [[ $(oc get oauth/cluster -o=json | jq -e 'select (.spec.identityProviders == null)') ]]; then
# there are no identity providers. We can do merge and set the whole .spec.identityProviders field
echo "[INFO] No identity providers found, provisioning Che one."
oc patch oauth/cluster --type=merge -p "$(cat $SCRIPT_DIR/resources/cluster-oauth-patch.json)"
elif [[ ! $(oc get oauth/cluster -o=json | jq -e '.spec.identityProviders[]?.name? | select ( . == ("dev-htpasswd"))') ]]; then
# there are some identity providers. We should do add patch not to override existing identity providers
echo "[INFO] OAuth Cluster is found but dev-htpasswd provider missing. Provisioning it."
oc patch oauth/cluster --type=json -p '[{
"op": "add",
"path": "/spec/identityProviders/0",
"value": {
"name":"dev-htpasswd",
"mappingMethod":"add",
"type":"HTPasswd",
"htpasswd": {
"fileData":{"name":"dev-htpasswd-secret"}
}
}
}]'
else
echo "[INFO] dev-htpasswd oauth provider is found. Using it"
fi

echo "[INFO] rollout oauth-openshift pods for applying OAuth configuration"
# apply just added identity providers, we need to rollout deployment for make sure
# that new IDP item will appear in the IDP table
# https://github.com/eclipse/che/issues/20822

oc rollout status -n openshift-authentication deployment/oauth-openshift
echo -e "[INFO] Waiting for htpasswd auth to be working up to 5 minutes"
CURRENT_TIME=$(date +%s)
ENDTIME=$(($CURRENT_TIME + 300))
while [ $(date +%s) -lt $ENDTIME ]; do
if oc login -u happypath-dev -p dev --kubeconfig $TMP_KUBECONFIG; then
return 0
fi
sleep 10
done
echo "[ERROR] Che htpasswd changes are not affected after timeout."
exit 1
}

# method originally extracted from eclipse/che/tests/devworkspace-happy-path/launch.sh
startHappyPathTest() {
oc delete pod happy-path-che -n eclipse-che --grace-period=30 --ignore-not-found
# patch happy-path-che.yaml
ECLIPSE_CHE_URL=http://$(oc get route -n "${CHE_NAMESPACE}" che -o jsonpath='{.status.ingress[0].host}')
cp $HAPPY_PATH_POD_FILE ${WORKDIR}/e2e-pod.yaml
sed -i "s@CHE_URL@${ECLIPSE_CHE_URL}@g" ${WORKDIR}/e2e-pod.yaml
sed -i "s@CHE-NAMESPACE@${CHE_NAMESPACE}@g" ${WORKDIR}/e2e-pod.yaml
echo "[INFO] Applying the following patched Che Happy Path Pod:"
cat ${WORKDIR}/e2e-pod.yaml
echo "[INFO] --------------------------------------------------"
oc apply -f ${WORKDIR}/e2e-pod.yaml
# wait for the pod to start
n=0
while [ $n -le 120 ]
do
PHASE=$(oc get pod -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME} \
--template='{{ .status.phase }}')
if [[ ${PHASE} == "Running" ]]; then
echo "[INFO] Happy-path test started successfully."
return
fi

sleep 5
n=$(( n+1 ))
done

echo "[ERROR] Failed to start happy-path test."
exit 1
}

##########################
# LOGGING AND EXECUTIOIN #
##########################

# Catch the finish of the job and write logs in artifacts.
###trap 'collectLogs $?' EXIT SIGINT
trap 'collectLogs $?' EXIT SIGINT

run() {
# Deploy Eclipse Che with a custom dashboard image
cat > /tmp/che-cr-patch.yaml <<EOF
# Deploy Eclipse Che with a custom dashboard image
cat > /tmp/che-cr-patch.yaml <<EOF
apiVersion: org.eclipse.che/v2
spec:
components:
dashboard:
dashboardImage: '${CI_CHE_DASHBOARD_IMAGE}'
EOF
chectl server:deploy \
--platform openshift \
--che-operator-cr-patch-yaml /tmp/che-cr-patch.yaml \
--batch \
--telemetry=off

# Run Smoke test
#TODO launch video recording
#TODO launch eclipse/che Quarkus smoke test
}
chectl server:deploy \
--platform openshift \
--che-operator-cr-patch-yaml /tmp/che-cr-patch.yaml \
--batch \
--telemetry=off

# Configure user auth
provisionOpenShiftOAuthUser

# Run Smoke test
startHappyPathTest

echo "[INFO] Waiting until happy path pod finished"
oc logs -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME} -c happy-path-test -f
# just to sleep
sleep 3

# Download artifacts
echo "[INFO] Downloading test report."
mkdir ${ARTIFACT_DIR}/e2e
mkdir ${ARTIFACT_DIR}/ffmpeg_report
oc rsync -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME}:/tmp/e2e/report/ ${ARTIFACT_DIR}/e2e -c download-reports
oc rsync -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME}:/tmp/ffmpeg_report/ ${ARTIFACT_DIR}/ffmpeg_report -c download-ffmpeg
oc exec -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME} -c download-reports
oc exec -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME} -c download-ffmpeg -- touch /tmp/done
EXIT_CODE=$(oc logs -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME} -c happy-path-test | grep EXIT_CODE)
if [[ ${EXIT_CODE} != "+ EXIT_CODE=0" ]]; then
echo "[ERROR] Happy-path test failed. Check report at ${ARTIFACT_DIR}. Or happy path pod in eclipse-che namespace"
exit 1
fi
echo "[INFO] Happy-path test succeed."

###run
# End test
END=$(date +%s.%N)
echo "[INFO] Happy-path execution took $(echo "$END - $START" | bc) seconds."
16 changes: 16 additions & 0 deletions .ci/resources/cluster-oauth-patch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"spec": {
"identityProviders": [
{
"name": "dev-htpasswd",
"mappingMethod": "add",
"type": "HTPasswd",
"htpasswd": {
"fileData": {
"name": "dev-htpasswd-secret"
}
}
}
]
}
}
27 changes: 15 additions & 12 deletions .ci/resources/pod-che-smoke-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,37 @@ spec:
imagePullPolicy: Always
env:
- name: VIDEO_RECORDING
value: true
value: "true"
- name: TEST_SUITE
value: 'test-all-devfiles'
value: "test"
- name: TS_SELENIUM_EDITOR
value: 'che-code'
value: "che-code"
- name: USERSTORY
value: 'SmokeTest'
value: "SmokeTest"
- name: MOCHA_DIRECTORY
value: "."
- name: NODE_TLS_REJECT_UNAUTHORIZED
value: '0'
value: "0"
- name: TS_SELENIUM_BASE_URL
value: CHE_URL
value: "CHE_URL"
- name: TS_SELENIUM_MULTIUSER
value: 'true'
value: "true"
- name: TS_SELENIUM_LOG_LEVEL
value: TRACE
value: "TRACE"
- name: TS_SELENIUM_OCP_USERNAME
value: 'happypath-dev'
value: "happypath-dev"
- name: TS_SELENIUM_OCP_PASSWORD
value: "dev"
- name: TS_SELENIUM_VALUE_OPENSHIFT_OAUTH
value: 'true'
value: "true"
- name: TS_OCP_LOGIN_PAGE_PROVIDER_TITLE
value: "dev-htpasswd"
- name: DELETE_WORKSPACE_ON_FAILED_TEST
value: "true"
- name: TS_SELENIUM_START_WORKSPACE_TIMEOUT
value: '360000'
value: "360000"
- name: TS_IDE_LOAD_TIMEOUT
value: '40000'
value: "40000"
volumeMounts:
- name: test-run-results
mountPath: /tmp/e2e/report/
Expand All @@ -69,6 +71,7 @@ spec:
mountPath: /tmp/e2e/report/
- name: ffmpeg-video
mountPath: /tmp/ffmpeg_report/
resources:
command: ["sh"]
args:
[
Expand Down
1 change: 1 addition & 0 deletions .ci/resources/users.htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
happypath-dev:$2y$05$W0AwRfPa1A1ne8QI0rvzpOgroeASayQdvNR.5GteVqjx26TOWz/km

0 comments on commit 6792f7d

Please sign in to comment.