diff --git a/Makefile b/Makefile index d3721396af..73bf88799e 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ verify: verify-fast # Fast verification checks that developers can/should run locally .PHONY: verify-fast -verify-fast: verify-go verify-assets verify-sh verify-py verify-config +verify-fast: verify-go verify-assets verify-sh verify-py verify-config verify-rf # Full verification checks that should run in CI .PHONY: verify-ci @@ -155,6 +155,10 @@ verify-sh: verify-py: ./scripts/verify/verify-py.sh +.PHONY: verify-rf +verify-rf: + ./scripts/verify/verify-rf.sh + .PHONY: verify-containers verify-containers: ./scripts/fetch_tools.sh hadolint && \ diff --git a/scripts/fetch_tools.sh b/scripts/fetch_tools.sh index 5c51563f42..6a11caf6a7 100755 --- a/scripts/fetch_tools.sh +++ b/scripts/fetch_tools.sh @@ -6,7 +6,9 @@ IFS=$'\n\t' ARCH="$(uname -m)" SCRIPT_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")" -DEST_DIR="${DEST_DIR:-${SCRIPT_DIR}/../_output/bin}" +ROOT_DIR=$(realpath "${SCRIPT_DIR}/..") +DEFAULT_DEST_DIR="${ROOT_DIR}/_output/bin" +DEST_DIR="${DEST_DIR:-${DEFAULT_DEST_DIR}}" [ -d "${DEST_DIR}" ] || mkdir -p "${DEST_DIR}" DEST_DIR="$(realpath "${DEST_DIR}")" WORK_DIR=$(mktemp -d) @@ -164,6 +166,25 @@ get_controller-gen() { GOBIN=${DEST_DIR} GOFLAGS="" go install sigs.k8s.io/controller-tools/cmd/controller-gen@${ver} } +get_robotframework() { + local venv + + if [ "${DEST_DIR}" = "${DEFAULT_DEST_DIR}" ]; then + # Probably running as the user, not in CI. + venv="${ROOT_DIR}/_output/robotenv" + else + # Probably running in automation environment where the output + # location has been changed. + venv="${DEST_DIR}" + fi + + if [ ! -f "${venv}/bin/robot" ]; then + python3 -m venv "${venv}" + "${venv}/bin/python3" -m pip install --upgrade pip + "${venv}/bin/python3" -m pip install -r "${ROOT_DIR}/test/requirements.txt" + fi +} + tool_getters=$(declare -F | cut -d' ' -f3 | grep "get_" | sed 's/get_//g') usage() { diff --git a/scripts/verify/verify-rf.sh b/scripts/verify/verify-rf.sh new file mode 100755 index 0000000000..ef2c213803 --- /dev/null +++ b/scripts/verify/verify-rf.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -euo pipefail + +ROOTDIR=$(git rev-parse --show-toplevel) + +RF_VENV="${ROOTDIR}/_output/robotenv" +"${ROOTDIR}/scripts/fetch_tools.sh" robotframework + +cd "${ROOTDIR}/test" +"${RF_VENV}/bin/robocop" diff --git a/test/requirements.txt b/test/requirements.txt index 6423a3c296..d9b2d90f98 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -3,3 +3,4 @@ robotframework-requests==0.9.4 robotframework-scplibrary==1.2.0 robotframework-sshlibrary==3.8.0 pyyaml==6.0 +robotframework-robocop==3.1.1 diff --git a/test/resources/common.resource b/test/resources/common.resource index cf3ebd79cb..8f5df5e811 100644 --- a/test/resources/common.resource +++ b/test/resources/common.resource @@ -1,8 +1,10 @@ *** Settings *** +Documentation Keywords common to many test suites Library OperatingSystem Library String Resource ../resources/kubeconfig.resource + *** Keywords *** Setup Suite [Documentation] Setup a namespace-less test suite by configuring Kubeconfig @@ -32,5 +34,9 @@ Teardown Suite With Namespace Check Required Env Variables [Documentation] Fail if any of the required environment variables is missing. - Run Keyword If "${USHIFT_HOST}"=="${EMPTY}" Fatal Error USHIFT_HOST variable is required - Run Keyword If "${USHIFT_USER}"=="${EMPTY}" Fatal Error USHIFT_USER variable is required + IF "${USHIFT_HOST}"=="${EMPTY}" + Fatal Error USHIFT_HOST variable is required + END + IF "${USHIFT_USER}"=="${EMPTY}" + Fatal Error USHIFT_USER variable is required + END diff --git a/test/resources/kubeconfig.resource b/test/resources/kubeconfig.resource index 82a5ac5fb6..621d79131a 100644 --- a/test/resources/kubeconfig.resource +++ b/test/resources/kubeconfig.resource @@ -1,8 +1,10 @@ *** Settings *** +Documentation Keywords for accessing a kubeconfig file for the MicroShift host Library OperatingSystem Library String Resource ../resources/microshift-host.resource + *** Keywords *** Get Kubeconfig [Documentation] Get the kubeconfig file from the host argument and return contents @@ -12,7 +14,7 @@ Get Kubeconfig ... sudo=True return_rc=True Should Be Equal As Integers ${rc} 0 Should Not Be Empty ${kubeconfig} - [Return] ${kubeconfig} + RETURN ${kubeconfig} Setup Kubeconfig [Documentation] Get the kubeconfig file from the configured $USHIFT_HOST, create a temporary file diff --git a/test/resources/microshift-host.resource b/test/resources/microshift-host.resource index 8bca593f60..74a7f54433 100644 --- a/test/resources/microshift-host.resource +++ b/test/resources/microshift-host.resource @@ -1,5 +1,6 @@ *** Settings *** -Library SSHLibrary +Documentation Keywords for working with the MicroShift host +Library SSHLibrary *** Keywords *** diff --git a/test/resources/microshift-process.resource b/test/resources/microshift-process.resource index 679213cffd..ddf57de475 100644 --- a/test/resources/microshift-process.resource +++ b/test/resources/microshift-process.resource @@ -1,8 +1,11 @@ *** Settings *** +Documentation Keywords for running the microshift command line. + Library Process -Library SSHLibrary Library String Library OperatingSystem + +Library SSHLibrary Resource ../resources/microshift-host.resource Library ../resources/YAML.py diff --git a/test/resources/oc.resource b/test/resources/oc.resource index 776440127c..cc9219b42a 100644 --- a/test/resources/oc.resource +++ b/test/resources/oc.resource @@ -1,10 +1,19 @@ *** Settings *** +Documentation Keywords for using the oc command line. +... +... Requires that the openshift-clients package be installed and +... 'oc' is in the $PATH. + Resource common.resource Library YAML.py -*** Keywords *** +*** Keywords *** Oc Get + [Documentation] Run 'oc get' for a specific instance of a type in a namespace. + ... Returns the YAML output parsed to a DottedDict for use in + ... other keywords. + [Arguments] ${type} ${namespace} ${resource} ${yaml_text}= Run With Kubeconfig oc get -n ${namespace} -o yaml ${type} ${resource} diff --git a/test/run.sh b/test/run.sh index 5ea0b71370..7734053eab 100755 --- a/test/run.sh +++ b/test/run.sh @@ -68,11 +68,7 @@ if [ ! -f "${RF_VARIABLES}" ]; then exit 1 fi -if [ ! -d "${RF_VENV}" ]; then - python3 -m venv "${RF_VENV}" - "${RF_VENV}/bin/python3" -m pip install --upgrade pip - "${RF_VENV}/bin/python3" -m pip install -r "${SCRIPTDIR}/requirements.txt" -fi +DEST_DIR="${RF_VENV}" "${ROOTDIR}/scripts/fetch_tools.sh" robotframework cd "${SCRIPTDIR}" || (echo "Did not find ${SCRIPTDIR}" 1>&2; exit 1) diff --git a/test/suites/load-balancer.robot b/test/suites/load-balancer.robot index 586b17f9cd..64cb63676c 100644 --- a/test/suites/load-balancer.robot +++ b/test/suites/load-balancer.robot @@ -9,9 +9,11 @@ Resource ../resources/kubeconfig.resource Suite Setup Setup Suite With Namespace Suite Teardown Teardown Suite With Namespace + *** Variables *** ${HELLO_USHIFT} assets/hello-microshift.yaml + *** Test Cases *** Load Balancer Smoke Test [Documentation] Verify that Load Balancer correctly exposes HTTP service @@ -20,20 +22,24 @@ Load Balancer Smoke Test ... Create Hello MicroShift Pod AND ... Expose Hello MicroShift Pod Via LB - Wait Until Keyword Succeeds 3x 3s Access Hello Microshift via LB + Wait Until Keyword Succeeds 3x 3s Access Hello Microshift Via LB [Teardown] Run Keywords ... Delete Hello MicroShift Pod Route And Service + *** Keywords *** Create Hello MicroShift Pod + [Documentation] Create a pod running the "hello microshift" application Run With Kubeconfig oc create -f ${HELLO_USHIFT} -n ${NAMESPACE} Run With Kubeconfig oc wait pods -l app\=hello-microshift --for condition\=Ready --timeout\=60s -n ${NAMESPACE} Expose Hello MicroShift Pod Via LB + [Documentation] Expose the "hello microshift" application through the load balancer Run With Kubeconfig oc create service loadbalancer hello-microshift --tcp=5678:8080 -n ${NAMESPACE} -Access Hello Microshift via LB +Access Hello Microshift Via LB + [Documentation] Try to retrieve data from the "hello microshift" service end point ${result}= Run Process ... curl -i http://hello-microshift.cluster.local --connect-to "hello-microshift.cluster.local:80:${USHIFT_HOST}:5678" ... shell=True timeout=15s @@ -43,6 +49,7 @@ Access Hello Microshift via LB Should Match ${result.stdout} *Hello MicroShift* Delete Hello MicroShift Pod Route And Service + [Documentation] Remove the "hello microshift" resources Run With Kubeconfig oc delete route hello-microshift -n ${NAMESPACE} True Run With Kubeconfig oc delete service hello-microshift -n ${NAMESPACE} True Run With Kubeconfig oc delete -f ${HELLO_USHIFT} -n ${NAMESPACE} True