Adding scripts to handle initialization of cluster for openshift CI. (#1441)

* Adding scripts to handle initialization of cluster for openshift CI.

This also fixes couple of usernames on the side

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>

* Adding http-tools to build root so we can use htpasswd

* Adding login as developer and creation of first project

* Moving script to ./scripts and renaming makefile command

* Renaming scripts to incude tests in configure cluster script

* Making script more configurable

* Adding namespace to secret commands.

* Fixing missing username

* Simplifying script by removing unnessasary variables

* Adding TODO and slightly reduction wait time for auth config

* Making assets dir overwritable

* Making configure script executable.

* Fixing message for not existing kubeconfig

* Redirecting out and err of commands where we are not interested in msg

* Updating to 18 secs default sleep which can be overridden

* Adding workaround for missing wildfly in OpenShift 4.0

* Adding basic ci docs for prow

Signed-off-by: Mohammed Zeeshan Ahmed <mohammed.zee1000@gmail.com>
This commit is contained in:
Mohammed Ahmed
2019-03-13 11:20:34 +05:30
committed by Amit Rout
parent 54ff6263e3
commit 631b53d2a3
5 changed files with 104 additions and 4 deletions

View File

@@ -81,6 +81,10 @@ generate-cli-reference:
prepare-release: cross
./scripts/prepare-release.sh
.PHONY: configure-installer-tests-cluster
configure-installer-tests-cluster:
. ./scripts/configure-installer-tests-cluster.sh
.PHONY: test
test:
go test -race $(PKGS)

View File

@@ -29,3 +29,15 @@ If the need presents itself to run odo integration tests against a specific vers
- oc login -u developer
- make test-main-e2e
```
# How to run integtration tests on Prow
Prow is the Kubernetes / OpenShift way of managing workflow including tests. To get tests on there, you need to raise PR to openshift/release repository setting up appropriate ci operator config and job files. Reference for same is available there itself.
However note that prow gives you a bare bones cluster, so we need to preconfigure the same so that the cluster is in state expected such as auth being configured and so on.
You can do this by running `$ make configure-installer-tests-cluster` before running actual tests.
This script is configurable with environment variables as
- SLEEP_AFTER_SECRET_CREATION: The time to sleep after auth is configured. Default is 18 seconds
- DEFAULT_INSTALLER_ASSETS_DIR: The location where OpenShift installer creates assets such as kube admin password and the kubeconfig file.

View File

@@ -2,4 +2,4 @@
FROM registry.svc.ci.openshift.org/openshift/release:golang-1.11
RUN yum -y install make wget gcc git
RUN yum -y install make wget gcc git httpd-tools

View File

@@ -0,0 +1,84 @@
#!/bin/bash
# Setup to find nessasary data from cluster setup
## Constants
HTPASSWD_FILE="./htpass"
USERPASS="developer"
HTPASSWD_SECRET="htpasswd-secret"
# Overrideable information
DEFAULT_INSTALLER_ASSETS_DIR=${DEFAULT_INSTALLER_ASSETS_DIR:-$(pwd)}
KUBEADMIN_USER=${KUBEADMIN_USER:-"kubeadmin"}
KUBEADMIN_PASSWORD_FILE=${KUBEADMIN_PASSWORD_FILE:-"${DEFAULT_INSTALLER_ASSETS_DIR}/auth/kubeadmin-password"}
SLEEP_AFTER_SECRET_CREATION=${SLEEP_AFTER_SECRET_CREATION:-18}
# Exported to current env
export KUBECONFIG=${KUBECONFIG:-"${DEFAULT_INSTALLER_ASSETS_DIR}/auth/kubeconfig"}
# List of users to create
USERS="developer odonoprojectattemptscreateproject odosingleprojectattemptscreate odologinnoproject odologinsingleproject1"
# Check if nessasary files exist
if [ ! -f $KUBEADMIN_PASSWORD_FILE ]; then
echo "Could not find kubeadmin password file"
exit 1
fi
if [ ! -f $KUBECONFIG ]; then
echo "Could not find kubeconfig file"
exit 1
fi
# Get kubeadmin password from file
KUBEADMIN_PASSWORD=`cat $KUBEADMIN_PASSWORD_FILE`
# Remove existing htpasswd file, if any
if [ -f $HTPASSWD_FILE ]; then
rm -rf $HTPASSWD_FILE
fi
# Set so first time -c parameter gets applied to htpasswd
HTPASSWD_CREATED=" -c "
# Create htpasswd entries for all listed users
for i in `echo $USERS`; do
htpasswd -b $HTPASSWD_CREATED $HTPASSWD_FILE $i $USERPASS
HTPASSWD_CREATED=""
done
# Login as admin user
oc login -u $KUBEADMIN_USER -p $KUBEADMIN_PASSWORD
# Workarounds - Note we should find better soulutions asap
## Missing wildfly in OpenShift Adding it manually to cluster Please remove once wildfly is again visible
oc apply -n openshift -f https://raw.githubusercontent.com/openshift/library/master/arch/x86_64/community/wildfly/imagestreams/wildfly-centos7.json
# Create secret in cluster, removing if it already exists
oc get secret $HTPASSWD_SECRET -n openshift-config &> /dev/null
if [ $? -eq 0 ]; then
oc delete secret $HTPASSWD_SECRET -n openshift-config &> /dev/null
fi
oc create secret generic ${HTPASSWD_SECRET} --from-file=htpasswd=${HTPASSWD_FILE} -n openshift-config
# Upload htpasswd as new login config
oc apply -f - <<EOF
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: htpassidp
challenge: true
login: true
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: ${HTPASSWD_SECRET}
EOF
# TODO : Find better way to check application of settings on cluster
sleep ${SLEEP_AFTER_SECRET_CREATION}
# Login as developer and setup project
oc login -u developer -p $USERPASS
oc new-project myproject
sleep 4

View File

@@ -67,11 +67,11 @@ var _ = Describe("odoe2e", func() {
Context("Logs in an new user without active project and tries to create various objects", func() {
It("Login as test user without project", func() {
runCmdShouldPass(fmt.Sprintf("odo login -u %s -p %s", "odoNoProjectAttemptsCreate", loginTestUserPassword))
runCmdShouldPass(fmt.Sprintf("odo login -u %s -p %s", "odonoprojectattemptscreate", loginTestUserPassword))
})
It("Should fail if user tries to create anything other than project", func() {
runCmdShouldPass(fmt.Sprintf("odo login -u %s -p %s", "odoNoProjectAttemptsCreate", loginTestUserPassword))
runCmdShouldPass(fmt.Sprintf("odo login -u %s -p %s", "odonoprojectattemptscreate", loginTestUserPassword))
session := runCmdShouldFail("odo create nodejs")
Expect(session).To(ContainSubstring("You dont have permission to project 'default' or it doesnt exist."))
// The message should also give user apropriate command
@@ -100,7 +100,7 @@ var _ = Describe("odoe2e", func() {
Context("Logs in as user with a project, deletes it and tries to create various objects", func() {
It("Should login as a user and setup by creating a project, and then deleting it", func() {
runCmdShouldPass(fmt.Sprintf("odo login -u %s -p %s", "odoSingleProjectAttemptsCreate", loginTestUserPassword))
runCmdShouldPass(fmt.Sprintf("odo login -u %s -p %s", "odosingleprojectattemptscreate", loginTestUserPassword))
odoCreateProject("odosingleprojectattemptscreateproject")
odoDeleteProject("odosingleprojectattemptscreateproject")
})