Skip to content

Commit

Permalink
Extract and reuse same code as in test-prow-e2e.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-jerolimov committed Jun 28, 2023
1 parent 8c48b58 commit 8cc5692
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 98 deletions.
45 changes: 45 additions & 0 deletions contrib/create-user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

set -exuo pipefail

function waitForAuthOperatorProgressing {
output=''
count=0
sleepDuration=15
maxRetries=40 # 10 minutes
action="started"
if [ "$1" == "False" ]; then
action="finished"
fi

until [ "$output" == "$1" ] || [ $count -gt $maxRetries ]; do
output=$(oc get co/authentication -o 'jsonpath={.status.conditions[?(@.type=="Progressing")].status}')
((count=count+1))
sleep $sleepDuration
done

secs=$((count*sleepDuration));
printf -v durationStr '%dm:%ds' $((secs%3600/60)) $((secs%60))
if [ "$output" == "$1" ]; then
echo "authentication operator $action Progressing 'test' idp (duration: $durationStr)"
else
echo "authentication operator: maximum retries reached (duration: $durationStr)"
exit 1
fi
}

# Add htpasswd IDP
# Skip wait for authentication operator to start Progressing when the Secret already exists.
# And ignore any kind of errors when the Secret doesn't exist.
htpasswd_secret_name=$(oc get --ignore-not-found secret -n openshift-config htpass-secret -o name 2> /dev/null)

if [ "$htpasswd_secret_name" == "" ]; then
oc create -f ./frontend/integration-tests/data/htpasswd-secret.yaml
oc patch oauths cluster --patch "$(cat ./frontend/integration-tests/data/patch-htpasswd.yaml)" --type=merge
set +x
echo "waiting for authentication operator to start Progressing 'test' idp..."
waitForAuthOperatorProgressing "True"
echo "waiting for authentication operator to finish Progressing 'test' idp..."
waitForAuthOperatorProgressing "False"
set -x
fi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
before(() => {
cy.exec(`./testData/create_user.sh`, { failOnNonZeroExit: false });
cy.exec(`../../../../create-user.sh`, { failOnNonZeroExit: false });
const bridgePasswordIDP: string = Cypress.env('BRIDGE_HTPASSWD_IDP') || 'test';
const bridgePasswordUsername: string = Cypress.env('BRIDGE_HTPASSWD_USERNAME') || 'test';
const bridgePasswordPassword: string = Cypress.env('BRIDGE_HTPASSWD_PASSWORD') || 'test';
Expand Down

This file was deleted.

44 changes: 1 addition & 43 deletions test-prow-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,6 @@ function copyArtifacts {
fi
}

function waitForAuthOperatorProgressing {
output=''
count=0
sleepDuration=15
maxRetries=40 #10 minutes
action="started"
if [ "$1" == "False" ]; then
action="finished"
fi

until [ "$output" == "$1" ] || [ $count -gt $maxRetries ]; do
output=$(oc get co/authentication -o 'jsonpath={.status.conditions[?(@.type=="Progressing")].status}')
((count=count+1))
sleep $sleepDuration
done

secs=$((count*sleepDuration));
printf -v durationStr '%dm:%ds' $((secs%3600/60)) $((secs%60))
if [ "$output" == "$1" ]; then
echo "authentication operator $action Progressing 'test' idp (duration: $durationStr)"
else
echo "authentication operator: maximum retries reached (duration: $durationStr)"
exit 1
fi
}

trap copyArtifacts EXIT

# don't log kubeadmin-password
Expand All @@ -49,23 +23,7 @@ set -x
BRIDGE_BASE_ADDRESS="$(oc get consoles.config.openshift.io cluster -o jsonpath='{.status.consoleURL}')"
export BRIDGE_BASE_ADDRESS

# Add htpasswd IDP
# Skip wait for authentication operator to start Progressing when the Secret already exists.
# And ignore any kind of errors when the Secret doesn't exist.

htpasswd_secret_name=$(oc get --ignore-not-found secret -n openshift-config htpass-secret -o name 2> /dev/null)


if [ "$htpasswd_secret_name" == "" ]; then
oc create -f ./frontend/integration-tests/data/htpasswd-secret.yaml
oc patch oauths cluster --patch "$(cat ./frontend/integration-tests/data/patch-htpasswd.yaml)" --type=merge
set +x
echo "waiting for authentication operator to start Progressing 'test' idp..."
waitForAuthOperatorProgressing "True"
echo "waiting for authentication operator to finish Progressing 'test' idp..."
waitForAuthOperatorProgressing "False"
set -x
fi
./contrib/create-user.sh

# "fake" dbus address to prevent errors
# https://github.com/SeleniumHQ/docker-selenium/issues/87
Expand Down

0 comments on commit 8cc5692

Please sign in to comment.