diff --git a/ods_ci/build/Dockerfile_interop b/ods_ci/build/Dockerfile_interop new file mode 100644 index 000000000..743064cc4 --- /dev/null +++ b/ods_ci/build/Dockerfile_interop @@ -0,0 +1,54 @@ +FROM quay.io/centos/centos:stream9 + +# Use this build arg to set any default test script arguments +ENV RUN_SCRIPT_ARGS=${RUN_SCRIPT_ARGS} +ENV ROBOT_EXTRA_ARGS='' +ENV SET_ENVIRONMENT=0 +ENV RETURN_PW=0 +ENV OC_HOST=${OC_HOST} +ENV RUN_FROM_CONTAINER=1 +ENV SE_BROWSER_PATH=/usr/bin/chromium-browser +ARG OC_VERSION=4.13 +ARG OC_CHANNEL=stable +ARG PYTHON_VERSION=3.11 + +ENV ODS_VENV="/ods_venv" \ + HOME="/ods_venv" \ + PATH="ods_venv/bin:${PATH}" \ + AM_I_IN_CONTAINER="Yes" \ + PYTHONUNBUFFERED="True" + +WORKDIR /ods_venv + +COPY . ${ODS_VENV} +COPY ods_ci/test-variables.yml.example ${ODS_VENV}/ods_ci/test-variables.yml + +RUN dnf install epel-release -y &&\ + dnf -y update &&\ + dnf install -y jq git unzip chromium chromedriver httpd-tools gcc \ + python3 python3-devel python3-distro python-pip python${PYTHON_VERSION} python${PYTHON_VERSION}-devel &&\ + dnf clean all && rm -rf /var/cache/yum &&\ + curl --proto "=https" -L https://github.com/mikefarah/yq/releases/download/v4.34.1/yq_linux_amd64 -o /usr/bin/yq &&\ + chmod +x /usr/bin/yq &&\ + curl --proto "=https" -L https://mirror.openshift.com/pub/openshift-v$(echo ${OC_VERSION} | cut -d'.' -f 1)/x86_64/clients/ocp/${OC_CHANNEL}-${OC_VERSION}/openshift-client-linux.tar.gz -o ${HOME}/oc_client.tar.gz && \ + tar xvf ${HOME}/oc_client.tar.gz -C /usr/local/bin/ && \ + rm -rf ${HOME}/oc_client.tar.gz && rm /usr/local/bin/README.md && chmod 755 /usr/local/bin/oc && oc version --client && \ + curl --proto "=https" -L https://github.com/openshift-online/ocm-cli/releases/download/v0.1.62/ocm-linux-amd64 -o ${HOME}/ocm && \ + mv ${HOME}/ocm /usr/local/bin/ && chmod 755 /usr/local/bin/ocm && ocm version + +RUN alternatives --install /usr/local/bin/python3 python3 /usr/bin/python${PYTHON_VERSION} 1 +RUN python3 --version +RUN curl -sSL https://install.python-poetry.org | python3 - +ENV PATH="${PATH}:${HOME}/.local/bin" +RUN poetry install + +ENV REQUESTS_CA_BUNDLE="/etc/pki/tls/certs/ca-bundle.crt" +RUN curl -L https://certs.corp.redhat.com/certs/Current-IT-Root-CAs.pem \ + -o /etc/pki/ca-trust/source/anchors/Current-IT-Root-CAs.pem && \ + update-ca-trust + +RUN chgrp -R 0 ${ODS_VENV} && \ + chmod -R g+rwX ${ODS_VENV} + +USER 1001 +WORKDIR ${ODS_VENV}/ods_ci \ No newline at end of file diff --git a/ods_ci/build/htpasswd/htpasswd_installation.sh b/ods_ci/build/htpasswd/htpasswd_installation.sh new file mode 100644 index 000000000..bcf4f64b2 --- /dev/null +++ b/ods_ci/build/htpasswd/htpasswd_installation.sh @@ -0,0 +1,3 @@ +#!/bin/bash +HTPASSWD_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +oc create secret generic htpasswd-bind-password --from-file=htpasswd=$HTPASSWD_PATH/users.txt -n openshift-config || echo "htpasswd secret exists" \ No newline at end of file diff --git a/ods_ci/build/htpasswd/oauth-htpasswd.idp.json b/ods_ci/build/htpasswd/oauth-htpasswd.idp.json new file mode 100644 index 000000000..5e2b17696 --- /dev/null +++ b/ods_ci/build/htpasswd/oauth-htpasswd.idp.json @@ -0,0 +1 @@ +{"name":"htpasswd-cluster-admin","mappingMethod":"claim","type":"HTPasswd","htpasswd":{"fileData":{"name":"htpasswd-bind-password"}}, "comment": "notsecret"} diff --git a/ods_ci/build/install_idp_interop.sh b/ods_ci/build/install_idp_interop.sh new file mode 100755 index 000000000..615425e24 --- /dev/null +++ b/ods_ci/build/install_idp_interop.sh @@ -0,0 +1,144 @@ +#!/bin/bash + +PROVIDER_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +OAUTH_HTPASSWD_JSON="$(cat $PROVIDER_PATH/htpasswd/oauth-htpasswd.idp.json)" +OAUTH_LDAP_JSON="$(cat $PROVIDER_PATH/ldap/oauth-ldap.idp.json)" +ARTIFACT_DIR="." +TEST_VARIABLES_FILE="test-variables.yml" + +install_htpasswd_identity_provider(){ + +# Test if any oauth identityProviders exists. If not, initialize the identityProvider list +CURRENT_IDP_LIST=$(oc get oauth cluster -o json | jq -e '.spec.identityProviders') +if [[ -z "${CURRENT_IDP_LIST}" ]] || [[ "${CURRENT_IDP_LIST}" == "null" ]]; then + echo 'No oauth identityProvider exists. Initializing oauth .spec.identityProviders = []' + oc patch oauth cluster --type json -p '[{"op": "add", "path": "/spec/identityProviders", "value": []}]' +fi + +# Patch in the HTPASSWD identityProviders +oc patch oauth cluster --type json -p '[{"op": "add", "path": "/spec/identityProviders/-", "value": '"$OAUTH_HTPASSWD_JSON"'}]' + +$PROVIDER_PATH/htpasswd/htpasswd_installation.sh +} + +install_ldap_identity_provider(){ + +# Test if any oauth identityProviders exists. If not, initialize the identityProvider list +CURRENT_IDP_LIST=$(oc get oauth cluster -o json | jq -e '.spec.identityProviders') +if [[ -z "${CURRENT_IDP_LIST}" ]] || [[ "${CURRENT_IDP_LIST}" == "null" ]]; then + echo 'No oauth identityProvider exists. Initializing oauth .spec.identityProviders = []' + oc patch oauth cluster --type json -p '[{"op": "add", "path": "/spec/identityProviders", "value": []}]' +fi + +# Patch in the LDAP identityProviders +oc patch oauth cluster --type json -p '[{"op": "add", "path": "/spec/identityProviders/-", "value": '"$OAUTH_LDAP_JSON"'}]' + +$PROVIDER_PATH/ldap/ldap_installation.sh +} + +add_groups_users() { +# create groups +oc adm groups new rhods-admins +oc adm groups new rhods-users +oc adm groups new rhods-noaccess +oc adm groups new dedicated-admins +# add users to groups +function add_users_to_groups(){ +for i in {1..10} + do + oc adm groups add-users $1 $2$i + done +} +add_users_to_groups rhods-admins htpasswd-admin +add_users_to_groups rhods-users htpasswd-user +add_users_to_groups rhods-noaccess htpasswd-noaccess +add_users_to_groups rhods-admins ldap-admin +add_users_to_groups dedicated-admins ldap-admin +add_users_to_groups rhods-users ldap-user +add_users_to_groups rhods-noaccess ldap-noaccess +oc adm groups add-users dedicated-admins htpasswd-cluster-admin-user + +oc adm groups add-users rhods-admins kubeadmin +oc adm policy add-cluster-role-to-group view rhods-admins +oc adm policy add-cluster-role-to-group cluster-admin dedicated-admins + +oc describe oauth.config.openshift.io/cluster +} + +function htpasswd_installation(){ + chk_htpasswd=1 + + while read -r line; do + + if [[ $line == *"htpasswd-cluster-admin"* ]]; then + echo -e "\033[0;33m Htpasswd Identity provider is installed. Skipping installation \033[0m" + chk_htpasswd=0 + break + fi + done < <(oc get oauth -o yaml) + + if [[ $chk_htpasswd == 1 ]]; then + install_htpasswd_identity_provider + fi +} + +function ldap_installation(){ + chk_ldap=1 + while read -r line; do + if [[ $line == *"ldap-provider-qe"* ]]; then + echo -e "\033[0;33m LDAP Identity provider is installed. Skipping installation \033[0m" + chk_ldap=0 + break + fi + done < <(oc get oauth -o yaml) + if [[ $chk_ldap == 1 ]]; then + install_ldap_identity_provider + fi +} + +function createHtpasswdIDP(){ + htpasswd -b -B -c $ARTIFACT_DIR/users.txt htpasswd-cluster-admin-user rhodsPW#123456 + oc create secret generic htpasswd-bind-password --from-file=htpasswd=$ARTIFACT_DIR/users.txt -n openshift-config + oc delete identity htpasswd-cluster-admin:htpasswd-cluster-admin-user --ignore-not-found + oc patch oauth cluster --type json -p '[{op: add, path: /spec/identityProviders, value: []}]' + oc patch oauth cluster --type json -p '[{"op": "add", "path": "/spec/identityProviders/-", "value": {"name":"htpasswd-cluster-admin","mappingMethod":"claim","type":"HTPasswd","htpasswd":{"fileData":{"name":"htpasswd-bind-password"}}}}]' + oc delete groups dedicated-admins --ignore-not-found + oc adm groups new dedicated-admins + oc delete user htpasswd-cluster-admin-user --ignore-not-found -n openshift-config + oc create user htpasswd-cluster-admin-user + oc adm groups add-users dedicated-admins htpasswd-cluster-admin-user + oc adm policy add-cluster-role-to-group cluster-admin dedicated-admins + oc adm policy add-cluster-role-to-user cluster-admin htpasswd-cluster-admin-user +} + +function updateTestConfig(){ + ldap_pass="rhodsPW#1" + export ldap_pass=$ldap_pass + + yq -i '.OCP_ADMIN_USER.AUTH_TYPE="htpasswd-cluster-admin"' ${TEST_VARIABLES_FILE} + yq -i '.OCP_ADMIN_USER.USERNAME="htpasswd-cluster-admin-user"' ${TEST_VARIABLES_FILE} + yq -i '.OCP_ADMIN_USER.PASSWORD="rhodsPW#123456"' ${TEST_VARIABLES_FILE} + + yq -i '.TEST_USER.AUTH_TYPE="ldap-provider-qe"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER.USERNAME="ldap-admin1"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER.PASSWORD=env(ldap_pass)' ${TEST_VARIABLES_FILE} + + yq -i '.TEST_USER_2.AUTH_TYPE="ldap-provider-qe"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER_2.USERNAME="ldap-admin2"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER_2.PASSWORD=env(ldap_pass)' ${TEST_VARIABLES_FILE} + + yq -i '.TEST_USER_3.AUTH_TYPE="ldap-provider-qe"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER_3.USERNAME="ldap-user2"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER_3.PASSWORD=env(ldap_pass)' ${TEST_VARIABLES_FILE} + + yq -i '.TEST_USER_4.AUTH_TYPE="ldap-provider-qe"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER_4.USERNAME="ldap-user9"' ${TEST_VARIABLES_FILE} + yq -i '.TEST_USER_4.PASSWORD=env(ldap_pass)' ${TEST_VARIABLES_FILE} +} + +createHtpasswdIDP +htpasswd_installation +ldap_installation +add_groups_users +updateTestConfig +sleep 60 \ No newline at end of file diff --git a/ods_ci/build/ldap/ldap.yaml b/ods_ci/build/ldap/ldap.yaml new file mode 100644 index 000000000..990ea7aa3 --- /dev/null +++ b/ods_ci/build/ldap/ldap.yaml @@ -0,0 +1,63 @@ +apiVersion: v1 +kind: Service +metadata: + name: openldap + namespace: openldap + labels: + app.kubernetes.io/name: openldap +spec: + type: ClusterIP + ports: + - name: tcp-ldap + port: 1389 + targetPort: tcp-ldap + selector: + app.kubernetes.io/name: openldap +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: openldap + namespace: openldap + labels: + app.kubernetes.io/name: openldap +spec: + selector: + matchLabels: + app.kubernetes.io/name: openldap + replicas: 1 + template: + metadata: + labels: + app.kubernetes.io/name: openldap + spec: + containers: + - name: openldap + image: quay.io/croberts/openldapserver@sha256:9d4ec0a31b48e165cbef6950c29a0a71a9508cee74fbca2b9df8a9b36f776be1 + imagePullPolicy: "Always" + resources: + requests: + memory: "256Mi" + limits: + memory: "512Mi" + env: + - name: LDAP_ADMIN_USERNAME + value: "admin" + - name: LDAP_ADMIN_PASSWORD + valueFrom: + secretKeyRef: + key: adminpassword + name: openldap + - name: LDAP_USERS + valueFrom: + secretKeyRef: + key: users + name: openldap + - name: LDAP_PASSWORDS + valueFrom: + secretKeyRef: + key: passwords + name: openldap + ports: + - name: tcp-ldap + containerPort: 1389 \ No newline at end of file diff --git a/ods_ci/build/ldap/ldap_installation.sh b/ods_ci/build/ldap/ldap_installation.sh new file mode 100755 index 000000000..470c97b76 --- /dev/null +++ b/ods_ci/build/ldap/ldap_installation.sh @@ -0,0 +1,5 @@ +#!/bin/bash +LDAP_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +oc create secret generic ldap-bind-password --from-literal=bindPassword=adminpassword -n openshift-config || echo "ldap secret exists" +oc apply -f $LDAP_PATH/ldap.yaml +sleep 25s \ No newline at end of file diff --git a/ods_ci/build/ldap/oauth-ldap.idp.json b/ods_ci/build/ldap/oauth-ldap.idp.json new file mode 100755 index 000000000..ab7ac9e0c --- /dev/null +++ b/ods_ci/build/ldap/oauth-ldap.idp.json @@ -0,0 +1 @@ +{"ldap":{"attributes":{"email":[],"id":["dn"],"name":["cn"],"preferredUsername":["uid"]},"insecure":true,"bindDN":"cn=admin,dc=example,dc=org","bindPassword":{"name":"ldap-bind-password"},"url":"ldap://openldap.openldap.svc.cluster.local:1389/dc=example,dc=org?uid"},"mappingMethod":"claim","name":"ldap-provider-qe","type":"LDAP"} diff --git a/ods_ci/run_interop.sh b/ods_ci/run_interop.sh new file mode 100755 index 000000000..725845c33 --- /dev/null +++ b/ods_ci/run_interop.sh @@ -0,0 +1,437 @@ +#!/bin/bash + +SKIP_OC_LOGIN=false +SERVICE_ACCOUNT="" +SA_NAMESPACE="default" +SET_RHODS_URLS=true +TEST_CASE_FILE=tests/Tests +TEST_VARIABLES_FILE=test-variables.yml +TEST_VARIABLES="" +TEST_ARTIFACT_DIR="test-output" +EXTRA_ROBOT_ARGS="" +SKIP_INSTALL=0 +TEST_INCLUDE_TAG="" +TEST_EXCLUDE_TAG="" +EMAIL_REPORT=false +EMAIL_TO="" +EMAIL_FROM="" +EMAIL_SERVER="localhost" +EMAIL_SERVER_USER="None" +EMAIL_SERVER_PW="None" +EMAIL_SERVER_SSL=false +EMAIL_SERVER_UNSECURE=false +OPEN_REPORT_IN_BROWSER=false +REPORT_BROWSER="firefox" # Default browser to open reports in +SUBFOLDER=true + +currentpath=$(pwd) +readonly currentpath + +basepath=$(dirname "$(readlink -f "${BASH_SOURCE[0]:-$0}")") +readonly basepath + +# Please keep this in sync with ./docs/RUN_ARGUMENTS.md file. +while [ "$#" -gt 0 ]; do + case $1 in + --skip-oclogin) + shift + SKIP_OC_LOGIN=$1 + shift + ;; + + --service-account) + shift + SERVICE_ACCOUNT=$1 + shift + ;; + + --sa-namespace) + shift + SA_NAMESPACE=$1 + shift + ;; + + # Override/Add global variables specified in the test variables file + --test-variable) + shift + TEST_VARIABLES="${TEST_VARIABLES} --variable $1" + shift + ;; + + --set-urls-variables) + shift + SET_RHODS_URLS=$1 + shift + ;; + + # Specify the test variable file + --test-variables-file) + shift + TEST_VARIABLES_FILE=$1 + shift + ;; + + # Specify test case to run + --test-case) + shift + TEST_CASE_FILE=$1 + shift + ;; + + # Specify directory to store artifacts and reports from each test run + --test-artifact-dir) + shift + TEST_ARTIFACT_DIR=$1 + shift + ;; + + # Specify included tags + # Example: sanityANDinstall sanityORinstall installNOTsanity + --test-suite) + shift + TEST_INCLUDE_TAG="${TEST_INCLUDE_TAG} --include $1" + shift + ;; + # Specify excluded tags + --exclude) + shift + TEST_EXCLUDE_TAG="${TEST_EXCLUDE_TAG} --exclude $1" + shift + ;; + # Additional arguments to pass to the robot cli + --extra-robot-args) + shift + EXTRA_ROBOT_ARGS=$1 + shift + ;; + + # Skip the dependency install during the execution of this script + --skip-install) + shift + SKIP_INSTALL=1 + ;; + + --email-report) + shift + EMAIL_REPORT=$1 + shift + ;; + + --email-from) + shift + EMAIL_FROM=$1 + shift + ;; + + --email-to) + shift + EMAIL_TO=$1 + shift + ;; + + --email-server) + shift + EMAIL_SERVER=$1 + shift + ;; + + --email-server-user) + shift + EMAIL_SERVER_USER=$1 + shift + ;; + + --email-server-pw) + shift + EMAIL_SERVER_PW=$1 + shift + ;; + + --email-server-ssl) + shift + EMAIL_SERVER_SSL=$1 + shift + ;; + + --email-server-unsecure) + shift + EMAIL_SERVER_UNSECURE=$1 + shift + ;; + + # place test results in a timestamped subfolder or not + # true: no subfolder, false: subfolder + --no-output-subfolder) + shift + SUBFOLDER=$1 + shift + ;; + + # If not `false`, then it opens reports in local browser after the tests run. + # If `true`, then default browser `REPORT_BROWSER` is used. + # You can override the default browser by specifying your own command as a value (e.g.: `--open-report nautilus`). + --open-report) + shift + OPEN_REPORT_IN_BROWSER="${1}" + shift + ;; + + *) + echo "Unknown command line switch: $1" + exit 1 + ;; + esac +done + +echo "${TEST_VARIABLES_FILE}" +if [[ ! -f "${TEST_VARIABLES_FILE}" ]]; then + echo "Robot Framework test variable file (test-variables.yml) is missing" + exit 1 +fi + +case "$(uname -s)" in + Darwin) + echo "MACOS" + echo "setting driver to $currentpath/Drivers/MACOS" + PATH=$PATH:$currentpath/drivers/MACOS + export PATH=$PATH + echo "$PATH" + ;; + Linux) + case "$(distro -j | jq '.id')" in + "fedora"|"centos") + ## Bootstrap script to setup drivers ## + echo "setting driver to $currentpath/Drivers/fedora" + PATH=$PATH:$currentpath/drivers/fedora + export PATH=$PATH + echo "$PATH" + ;; + "ubuntu") + echo "Ubuntu" + echo "setting driver to $currentpath/drivers/ubuntu" + PATH=$PATH:$currentpath/drivers/ubuntu + export PATH=$PATH + echo "$PATH" + ;; + "opensuse project"|"suse linux"|"opensuse") + echo "Not yet supported, but shouldn't be hard for you to fix :) " + echo "Please add the driver, test and submit PR" + exit 1 + ;; + esac + ;; + * ) + echo "Not yet supported OS, but shouldn't be hard for you to fix :) " + echo "Please add the driver, test and submit PR" + exit 1 + ;; +esac + +case "$(uname -s)" in + Darwin) + echo "MACOS" + echo "setting driver to $currentpath/Drivers/MACOS" + PATH=$PATH:$currentpath/drivers/MACOS + export PATH=$PATH + echo "$PATH" + ;; + Linux) + case "$(distro -j | jq '.id')" in + "fedora"|"centos") + ## Bootstrap script to setup drivers ## + echo "setting driver to $currentpath/Drivers/fedora" + PATH=$PATH:$currentpath/drivers/fedora + export PATH=$PATH + echo "$PATH" + ;; + "ubuntu") + echo "Ubuntu" + echo "setting driver to $currentpath/drivers/ubuntu" + PATH=$PATH:$currentpath/drivers/ubuntu + export PATH=$PATH + echo "$PATH" + ;; + "opensuse project"|"suse linux"|"opensuse") + echo "Not yet supported, but shouldn't be hard for you to fix :) " + echo "Please add the driver, test and submit PR" + exit 1 + ;; + esac + ;; + * ) + echo "Not yet supported OS, but shouldn't be hard for you to fix :) " + echo "Please add the driver, test and submit PR" + exit 1 + ;; +esac + +echo "Install IDP users and map them to test config file" +./build/install_idp_interop.sh + +# automatically get cluster URLs if already log into or running in a pod +if ${SET_RHODS_URLS} + then + echo "INFO: getting RHODS URLs from the cluster as per --set-urls-variables" + + yq -i '.OCP_API_URL=env(OC_HOST)' ${TEST_VARIABLES_FILE} + yq -i '.OCP_CONSOLE_URL=env(OCP_CONSOLE)' ${TEST_VARIABLES_FILE} + yq -i '.ODH_DASHBOARD_URL=env(RHODS_DASHBOARD)' ${TEST_VARIABLES_FILE} + yq -i '.BROWSER.NAME="firefox"' ${TEST_VARIABLES_FILE} + + echo "OCP Console URL set to: ${OCP_CONSOLE}" + echo "RHODS API Server URL set to: ${OC_HOST}" + echo "RHODS Dashboard URL set to: ${RHODS_DASHBOARD}" +fi + +## if we have yq installed +if command -v yq &> /dev/null + then + echo "INFO: we found a yq executable" + if ! ${SKIP_OC_LOGIN} + then + echo "INFO: OC Login enabled" + if [ -z "${SERVICE_ACCOUNT}" ] + then + echo "Performing oc login using username and password" + oc_user=$(yq -er '.OCP_ADMIN_USER.USERNAME' "${TEST_VARIABLES_FILE}") || { + echo "Couldn't find '.OCP_ADMIN_USER.USERNAME' variable in provided '${TEST_VARIABLES_FILE}'." + echo "Please either provide it or use '--skip-oclogin true' (don't forget to login to the testing cluster manually then)." + exit 1 + } + oc_pass=$(yq -er '.OCP_ADMIN_USER.PASSWORD' "${TEST_VARIABLES_FILE}") || { + echo "Couldn't find '.OCP_ADMIN_USER.PASSWORD' variable in provided '${TEST_VARIABLES_FILE}'." + echo "Please either provide it or use '--skip-oclogin true' (don't forget to login to the testing cluster manually then)." + exit 1 + } + oc login "${OC_HOST}" --username "${oc_user}" --password "${oc_pass}" --insecure-skip-tls-verify=true + retVal=$? + else + echo "Performing oc login using service account" + sa_token=$(oc create token "${SERVICE_ACCOUNT}" -n "${SA_NAMESPACE}" --duration 6h) + oc login --token="$sa_token" --server="${OC_HOSt}" --insecure-skip-tls-verify=true + retVal=$? + sa_fullname=$(oc whoami) + TEST_VARIABLES="${TEST_VARIABLES} --variable SERVICE_ACCOUNT.NAME:${SERVICE_ACCOUNT} --variable SERVICE_ACCOUNT.FULL_NAME:${sa_fullname}" + + fi + + ## no point in going further if the login is not working + if [ $retVal -ne 0 ]; then + echo "The oc login command seems to have failed" + echo "Please review the content of ${TEST_VARIABLES_FILE}" + exit "${retVal}" + fi + + oc cluster-info + printf "\nconnected as openshift user ' %s '\n" "$(oc whoami)" + echo "since the oc login was successful, continuing." + else + echo "skipping OC login as per parameter --skip-oclogin" + fi + else + echo "we did not find yq, so not trying the oc login" +fi + +if [[ ${SKIP_INSTALL} -eq 0 ]]; then + # Look for pre-created poetry .venv + # NOTE: handle that checkout might happen through `git checkout -f somehash` and branch names may include `/` char + refname="$(git branch --remote --no-abbrev --format="%(refname:lstrip=3)" --contains "HEAD" | head -1)" + venvdir="${refname%,*}" + echo "Git revision refname='${refname}', venvdir='${venvdir}'." + for venvdir in "${venvdir}" "master"; do + virtenv="${HOME}/.local/ods-ci/${venvdir}/.venv" + echo "Checking whether '${virtenv}' exists." + if [[ -d "${virtenv}" ]]; then + break + fi + done + if [[ -d "${basepath}/../.venv" ]]; then + echo "We ran already before and settled in venv we linked into '${basepath}/../.venv'." + elif [[ -d "${virtenv}" ]]; then + echo "Using a pre-created virtual environment in '${virtenv}' for poetry to save time." + poetry config --local virtualenvs.in-project true + # Workaround for Poetry urllib3 connection error + poetry config --local installer.parallel false + # Link in the venv we're going to be using + ln --symbolic "${virtenv}" "${basepath}/../.venv" + # Workaround for .venv directory not being movable (hashbangs in bin/ hardcode python interpreter path) + ln --symbolic "${virtenv}" "${HOME}/.local/ods-ci/.venv" + else + echo "Pre-created virtual environment has not been found in '${virtenv}'. All dependencies will be installed from scratch." + fi + # ensure python 3.11 + python=$(poetry env info --executable) + if [[ -n "${python}" ]] && ${python} -c 'import sys; sys.exit(0 if sys.version_info[0:2] == (3, 11) else 1)'; then + echo "Python '${python}' will be used" + else + echo "Python '${python}' is not of the correct version" + python311=$(which python3.11) + if [[ -n "${python311}" ]]; then + echo "Configuring poetry to use Python ${python311}" + poetry env use "${python311}" + else + echo "[ERROR] Python 3.11 was not found!" + echo "Install Python 3.11 on your machine. On Fedora, do 'sudo dnf install -y python3.11-devel'" + echo "then run 'poetry env use /path/to/python3.11' and then try running robot again" + exit 1 + fi + fi + + poetry install --no-interaction --sync || { + echo "[ERROR] poetry environment setup failed, aborting the execution!" + exit 1 + } +fi +# shellcheck disable=SC1091 +source "$(poetry env info --path)/bin/activate" + +#Create a unique directory to store the output for current test run +if [[ ! -d "${TEST_ARTIFACT_DIR}" ]]; then + mkdir -p "${TEST_ARTIFACT_DIR}" +fi +if ! ${SUBFOLDER}; then + case "$(uname -s)" in + Darwin) + # shellcheck disable=SC2046 + TEST_ARTIFACT_DIR=$(mktemp -d "${TEST_ARTIFACT_DIR}" -t "${TEST_ARTIFACT_DIR}"/ods-ci-$(date +%Y-%m-%d-%H-%M)-XXXXXXXXXX) + ;; + Linux) + # shellcheck disable=SC2046 + TEST_ARTIFACT_DIR=$(mktemp -d -p "${TEST_ARTIFACT_DIR}" -t ods-ci-$(date +%Y-%m-%d-%H-%M)-XXXXXXXXXX) + ;; + esac +fi + +robot ${TEST_EXCLUDE_TAG} ${TEST_INCLUDE_TAG} -d ${TEST_ARTIFACT_DIR} -x xunit_test_result.xml -r test_report.html ${TEST_VARIABLES} --variablefile ${TEST_VARIABLES_FILE} --exclude TBC ${EXTRA_ROBOT_ARGS} ${TEST_CASE_FILE} +# shellcheck disable=SC2116 +exit_status=$(echo $?) +echo "${exit_status}" + +# send test artifacts by email +if ${EMAIL_REPORT} + then + tar cvzf rf_results.tar.gz "${TEST_ARTIFACT_DIR}" &> /dev/null + size=$(du -k rf_results.tar.gz | cut -f1) + if [ "${size}" -gt 20000 ] + then + echo "Test results artifacts are too large for email" + rm rf_results.tar.gz + tar cvzf rf_results.tar.gz $(find "${TEST_ARTIFACT_DIR}" -regex '.*\(xml\|html\)$') &> /dev/null + fi + poetry run python3 utils/scripts/Sender/send_report.py send_email_report -s "${EMAIL_FROM}" -r "${EMAIL_TO}" -b "ODS-CI: Run Results" \ + -v "${EMAIL_SERVER}" -a "rf_results.tar.gz" -u "${EMAIL_SERVER_USER}" -p "${EMAIL_SERVER_PW}" \ + -l "${EMAIL_SERVER_SSL}" -d "${EMAIL_SERVER_UNSECURE}" +fi + +if test "${OPEN_REPORT_IN_BROWSER}" != "false" + then + if test "${OPEN_REPORT_IN_BROWSER}" != "true" + then + REPORT_BROWSER="${OPEN_REPORT_IN_BROWSER}" + fi + + ${REPORT_BROWSER} "${TEST_ARTIFACT_DIR}" & +fi + +deactivate +exit "${exit_status}" \ No newline at end of file