From 7da8e86adf828d6721d475a026dccdd13d8e4949 Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Tue, 25 Apr 2023 10:40:37 +0200 Subject: [PATCH 1/9] USHIFT-1119: Add makefile and gitignore --- test/Makefile | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/Makefile diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000000..a2dfacfefc --- /dev/null +++ b/test/Makefile @@ -0,0 +1,22 @@ +tests = $(wildcard **/*.robot) +RF_VENV :=../_output/.venv +RF_BINARY :=../_output/.venv/bin/robot +RF_OUT :=--outputdir ../_output/e2e-$$(date +''%Y%m%d-%H%M%S) + +.PHONY: setup dry-run with-filter with-tag all $(tests) + +setup: + python3 -m venv $(RF_VENV) && \ + $(RF_VENV)/bin/python3 -m pip install -r requirements.txt + +$(tests): + $(RF_BINARY) \ + $(RF_OPTIONS) \ + $(RF_OUT) \ + $@ + +dry-run: RF_OPTIONS=--dryrun +dry-run: $(tests) + +all: RF_OPTIONS=-v USHIFT_HOST:$${USHIFT_HOST} -v USHIFT_USER:microshift -x xunit.xml +all: $(tests) From 5007626d05c5c10e8a4f8c6bcee2bd6b2f0a1971 Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Tue, 25 Apr 2023 10:41:07 +0200 Subject: [PATCH 2/9] USHIFT-1119: Add requirements for python venv --- test/requirements.txt | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 test/requirements.txt diff --git a/test/requirements.txt b/test/requirements.txt new file mode 100644 index 0000000000..460192a03d --- /dev/null +++ b/test/requirements.txt @@ -0,0 +1,4 @@ +robotframework==6.0.2 +robotframework-requests==0.9.4 +robotframework-scplibrary==1.2.0 +robotframework-sshlibrary==3.8.0 From e45e0c9ecbae1261c3b4cabf75ab84cfef9f6c14 Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Tue, 25 Apr 2023 10:57:33 +0200 Subject: [PATCH 3/9] USHIFT-1119: Add RF resources --- test/resources/common.resource | 28 +++++++++++++++++ test/resources/kubeconfig.resource | 50 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 test/resources/common.resource create mode 100644 test/resources/kubeconfig.resource diff --git a/test/resources/common.resource b/test/resources/common.resource new file mode 100644 index 0000000000..7f051c9a36 --- /dev/null +++ b/test/resources/common.resource @@ -0,0 +1,28 @@ +*** Settings *** +Library OperatingSystem +Library SSHLibrary +Library String +Resource ../resources/kubeconfig.resource + +*** Keywords *** +Setup Suite + [Documentation] Setup a namespace-less test suite by configuring Kubeconfig + Setup Kubeconfig + +Setup Suite With Namespace + [Documentation] Setup a test suite by creating a unique namespace and configuring Kubeconfig + Setup Kubeconfig + ${rand}= Generate Random String + ${rand}= Convert To Lower Case ${rand} + ${ns}= Catenate SEPARATOR=- "test" ${rand} + Set Suite Variable \${NAMESPACE} ${ns} + Create Namespace ${ns} + +Teardown Suite + [Documentation] Teardown the namespace-less test suite by removing the Kubeconfig. + Remove Kubeconfig + +Teardown Suite With Namespace + [Documentation] Teardown the namespaced test suite by removing the namespace and removing the Kubeconfig. + Remove Namespace ${NAMESPACE} + Remove Kubeconfig diff --git a/test/resources/kubeconfig.resource b/test/resources/kubeconfig.resource new file mode 100644 index 0000000000..276a1cfce8 --- /dev/null +++ b/test/resources/kubeconfig.resource @@ -0,0 +1,50 @@ +*** Settings *** +Library OperatingSystem +Library SSHLibrary +Library String + +*** Keywords *** +Get Kubeconfig + [Documentation] Get the kubeconfig file from the host argument and return contents + [Arguments] ${host} + SSHLibrary.Open Connection ${host} + SSHLibrary.Login ${USHIFT_USER} allow_agent=True + ${kubeconfig} ${rc}= Execute Command + ... cat /var/lib/microshift/resources/kubeadmin/${host}/kubeconfig + ... sudo=True return_rc=True + SSHLibrary.Close Connection + Should Be Equal As Integers ${rc} 0 + Should Not Be Empty ${kubeconfig} + [Return] ${kubeconfig} + +Setup Kubeconfig + [Documentation] Get the kubeconfig file from the configured $USHIFT_HOST, create a temporary file + ... and export it as $KUBECONFIG variable. + ${kubeconfig}= Get Kubeconfig ${USHIFT_HOST} + ${rand}= Generate Random String + ${path}= Join Path /tmp ${rand} + Create File ${path} ${kubeconfig} + Set Suite Variable \${KUBECONFIG} ${path} + +Remove Kubeconfig + [Documentation] Remove kubeconfig ${KUBECONFIG} file. + Remove File ${KUBECONFIG} + +Run With Kubeconfig + [Documentation] Run a command using KUBECONFIG from the test suite. + [Arguments] ${cmd} ${allow_fail}=False + ${result}= Run Process ${cmd} env:KUBECONFIG=${KUBECONFIG} stderr=STDOUT shell=True + Log ${result.stdout} + IF ${allow_fail} == False + Should Be Equal As Integers ${result.rc} 0 + END + +Create Namespace + [Documentation] Creates a namespace with the given name. + [Arguments] ${ns} + Run With Kubeconfig oc create namespace ${ns} + +Remove Namespace + [Documentation] Removes the given namespace. + [Arguments] ${ns} + Run With Kubeconfig oc delete namespace ${ns} \ No newline at end of file From 6b27825b3be964d48deefb2965f58b2ffa2cfeda Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Tue, 25 Apr 2023 10:59:00 +0200 Subject: [PATCH 4/9] USHIFT-1119: Add load balancer RF test --- test/suites/load-balancer.robot | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test/suites/load-balancer.robot diff --git a/test/suites/load-balancer.robot b/test/suites/load-balancer.robot new file mode 100644 index 0000000000..5ab7e19299 --- /dev/null +++ b/test/suites/load-balancer.robot @@ -0,0 +1,49 @@ +*** Settings *** +Documentation Load balancer test suite. + +Library Process + +Resource ../resources/common.resource +Resource ../resources/kubeconfig.resource + +Suite Setup Setup Suite With Namespace +Suite Teardown Teardown Suite With Namespace + +*** Variables *** +${USHIFT_HOST} ${EMPTY} +${USHIFT_USER} ${EMPTY} + +*** Test Cases *** +Load Balancer Smoke Test + [Documentation] Verify that Load Balancer correctly exposes HTTP service + [Tags] smoke + [Setup] Run Keywords + ... Create Hello MicroShift Pod AND + ... Expose Hello MicroShift Pod 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 + Run With Kubeconfig oc create -f ../e2e/tests/assets/hello-microshift.yaml -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 + Run With Kubeconfig oc create service loadbalancer hello-microshift --tcp=5678:8080 -n ${NAMESPACE} + +Access Hello Microshift via LB + ${result}= Run Process + ... curl -i http://hello-microshift.cluster.local --connect-to "hello-microshift.cluster.local:80:${USHIFT_HOST}:5678" + ... shell=True timeout=15s + Log ${result} + Should Be Equal As Integers ${result.rc} 0 + Should Match Regexp ${result.stdout} HTTP.*200 + Should Match ${result.stdout} *Hello MicroShift* + +Delete Hello MicroShift Pod Route And Service + 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 ../e2e/tests/assets/hello-microshift.yaml -n ${NAMESPACE} True From 8304d415d4cf8bd802dcf6d39d2b755d4762f2fe Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Wed, 26 Apr 2023 18:05:40 +0200 Subject: [PATCH 5/9] USHIFT-1119: Add env vars check to bail out --- test/resources/common.resource | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/resources/common.resource b/test/resources/common.resource index 7f051c9a36..99f3bb32bc 100644 --- a/test/resources/common.resource +++ b/test/resources/common.resource @@ -7,10 +7,12 @@ Resource ../resources/kubeconfig.resource *** Keywords *** Setup Suite [Documentation] Setup a namespace-less test suite by configuring Kubeconfig + Check Required Env Variables Setup Kubeconfig Setup Suite With Namespace [Documentation] Setup a test suite by creating a unique namespace and configuring Kubeconfig + Check Required Env Variables Setup Kubeconfig ${rand}= Generate Random String ${rand}= Convert To Lower Case ${rand} @@ -26,3 +28,8 @@ Teardown Suite With Namespace [Documentation] Teardown the namespaced test suite by removing the namespace and removing the Kubeconfig. Remove Namespace ${NAMESPACE} Remove Kubeconfig + +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 From 7b54c5d63b58cc205d924ee00ef562c5e9f8a86e Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Fri, 5 May 2023 10:20:24 +0200 Subject: [PATCH 6/9] Add customizable ouput dir --- test/Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/Makefile b/test/Makefile index a2dfacfefc..57f2320c05 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,9 +1,10 @@ tests = $(wildcard **/*.robot) RF_VENV :=../_output/.venv RF_BINARY :=../_output/.venv/bin/robot -RF_OUT :=--outputdir ../_output/e2e-$$(date +''%Y%m%d-%H%M%S) +OUTPUT_DIR ?= ../_output/e2e-$$(date +''%Y%m%d-%H%M%S) +RF_OUT :=--outputdir $(OUTPUT_DIR) -.PHONY: setup dry-run with-filter with-tag all $(tests) +.PHONY: setup dry-run all $(tests) setup: python3 -m venv $(RF_VENV) && \ @@ -18,5 +19,9 @@ $(tests): dry-run: RF_OPTIONS=--dryrun dry-run: $(tests) -all: RF_OPTIONS=-v USHIFT_HOST:$${USHIFT_HOST} -v USHIFT_USER:microshift -x xunit.xml -all: $(tests) +all: RF_OPTIONS=-v USHIFT_HOST:$${USHIFT_HOST} -v USHIFT_USER:$${USHIFT_USER} -x junit.xml +all: + $(RF_BINARY) \ + $(RF_OPTIONS) \ + $(RF_OUT) \ + ./suites From ae9996beb5fce6f4dca69b1f622960140cad0dd8 Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Fri, 5 May 2023 11:18:24 +0200 Subject: [PATCH 7/9] USHIFT-1119: Add assets dir --- test/assets/hello-microshift.yaml | 26 ++++++++++++++++++++++++++ test/suites/load-balancer.robot | 5 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/assets/hello-microshift.yaml diff --git a/test/assets/hello-microshift.yaml b/test/assets/hello-microshift.yaml new file mode 100644 index 0000000000..11b27c5b90 --- /dev/null +++ b/test/assets/hello-microshift.yaml @@ -0,0 +1,26 @@ +kind: Pod +apiVersion: v1 +metadata: + name: hello-microshift + labels: + app: hello-microshift +spec: + terminationGracePeriodSeconds: 0 + containers: + - name: hello-microshift + image: busybox:1.35 + command: ["/bin/sh"] + args: ["-c", "while true; do echo -ne \"HTTP/1.0 200 OK\r\nContent-Length: 16\r\n\r\nHello MicroShift\" | nc -l -p 8080 ; done"] + ports: + - containerPort: 8080 + protocol: TCP + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + runAsNonRoot: true + runAsUser: 1001 + runAsGroup: 1001 + seccompProfile: + type: RuntimeDefault diff --git a/test/suites/load-balancer.robot b/test/suites/load-balancer.robot index 5ab7e19299..f7eef8ee96 100644 --- a/test/suites/load-balancer.robot +++ b/test/suites/load-balancer.robot @@ -12,6 +12,7 @@ Suite Teardown Teardown Suite With Namespace *** Variables *** ${USHIFT_HOST} ${EMPTY} ${USHIFT_USER} ${EMPTY} +${HELLO_USHIFT} assets/hello-microshift.yaml *** Test Cases *** Load Balancer Smoke Test @@ -28,7 +29,7 @@ Load Balancer Smoke Test *** Keywords *** Create Hello MicroShift Pod - Run With Kubeconfig oc create -f ../e2e/tests/assets/hello-microshift.yaml -n ${NAMESPACE} + 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 @@ -46,4 +47,4 @@ Access Hello Microshift via LB Delete Hello MicroShift Pod Route And Service 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 ../e2e/tests/assets/hello-microshift.yaml -n ${NAMESPACE} True + Run With Kubeconfig oc delete -f ${HELLO_USHIFT} -n ${NAMESPACE} True From 330e84d485ae60dff98f48a63ed324c03192859a Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Fri, 5 May 2023 13:41:09 +0200 Subject: [PATCH 8/9] USHIFT-1119: Add external variables file --- test/Makefile | 8 +++----- test/requirements.txt | 1 + test/suites/load-balancer.robot | 2 -- test/suites/variables.yaml | 6 ++++++ 4 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 test/suites/variables.yaml diff --git a/test/Makefile b/test/Makefile index 57f2320c05..16e98d15fa 100644 --- a/test/Makefile +++ b/test/Makefile @@ -2,7 +2,8 @@ tests = $(wildcard **/*.robot) RF_VENV :=../_output/.venv RF_BINARY :=../_output/.venv/bin/robot OUTPUT_DIR ?= ../_output/e2e-$$(date +''%Y%m%d-%H%M%S) -RF_OUT :=--outputdir $(OUTPUT_DIR) +RF_VARIABLES ?=suites/variables.yaml +RF_OPTIONS :=--randomize all --loglevel DEBUG -x junit.xml -V $(RF_VARIABLES) --outputdir $(OUTPUT_DIR) .PHONY: setup dry-run all $(tests) @@ -13,15 +14,12 @@ setup: $(tests): $(RF_BINARY) \ $(RF_OPTIONS) \ - $(RF_OUT) \ $@ -dry-run: RF_OPTIONS=--dryrun +dry-run: ROBOT_OPTIONS=--dryrun dry-run: $(tests) -all: RF_OPTIONS=-v USHIFT_HOST:$${USHIFT_HOST} -v USHIFT_USER:$${USHIFT_USER} -x junit.xml all: $(RF_BINARY) \ $(RF_OPTIONS) \ - $(RF_OUT) \ ./suites diff --git a/test/requirements.txt b/test/requirements.txt index 460192a03d..6423a3c296 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -2,3 +2,4 @@ robotframework==6.0.2 robotframework-requests==0.9.4 robotframework-scplibrary==1.2.0 robotframework-sshlibrary==3.8.0 +pyyaml==6.0 diff --git a/test/suites/load-balancer.robot b/test/suites/load-balancer.robot index f7eef8ee96..586b17f9cd 100644 --- a/test/suites/load-balancer.robot +++ b/test/suites/load-balancer.robot @@ -10,8 +10,6 @@ Suite Setup Setup Suite With Namespace Suite Teardown Teardown Suite With Namespace *** Variables *** -${USHIFT_HOST} ${EMPTY} -${USHIFT_USER} ${EMPTY} ${HELLO_USHIFT} assets/hello-microshift.yaml *** Test Cases *** diff --git a/test/suites/variables.yaml b/test/suites/variables.yaml new file mode 100644 index 0000000000..5ba6b40c73 --- /dev/null +++ b/test/suites/variables.yaml @@ -0,0 +1,6 @@ +# USHIFT_HOST: MicroShift host, can be a name or IP +USHIFT_HOST: microshift +# USHIFT_USER: User to log into MicroShift's host +USHIFT_USER: microshift +# SSH Private key to use when logging into MicroShift's host. If not defined will require ssh agent setup +SSH_PRIV_KEY: /home/microshift/.ssh/id_rsa From 9740160b613c824e8167a6d966233284cbac6e83 Mon Sep 17 00:00:00 2001 From: Pablo Acevedo Montserrat Date: Fri, 5 May 2023 15:39:06 +0200 Subject: [PATCH 9/9] USHIFT-1119: Add SSH with private key --- test/resources/common.resource | 1 - test/resources/kubeconfig.resource | 4 ++-- test/suites/variables.yaml | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/test/resources/common.resource b/test/resources/common.resource index 99f3bb32bc..5945f0ac35 100644 --- a/test/resources/common.resource +++ b/test/resources/common.resource @@ -1,6 +1,5 @@ *** Settings *** Library OperatingSystem -Library SSHLibrary Library String Resource ../resources/kubeconfig.resource diff --git a/test/resources/kubeconfig.resource b/test/resources/kubeconfig.resource index 276a1cfce8..362f58fd37 100644 --- a/test/resources/kubeconfig.resource +++ b/test/resources/kubeconfig.resource @@ -8,7 +8,7 @@ Get Kubeconfig [Documentation] Get the kubeconfig file from the host argument and return contents [Arguments] ${host} SSHLibrary.Open Connection ${host} - SSHLibrary.Login ${USHIFT_USER} allow_agent=True + SSHLibrary.Login With Public Key ${USHIFT_USER} ${SSH_PRIV_KEY} ${kubeconfig} ${rc}= Execute Command ... cat /var/lib/microshift/resources/kubeadmin/${host}/kubeconfig ... sudo=True return_rc=True @@ -47,4 +47,4 @@ Create Namespace Remove Namespace [Documentation] Removes the given namespace. [Arguments] ${ns} - Run With Kubeconfig oc delete namespace ${ns} \ No newline at end of file + Run With Kubeconfig oc delete namespace ${ns} diff --git a/test/suites/variables.yaml b/test/suites/variables.yaml index 5ba6b40c73..ff5625cc4c 100644 --- a/test/suites/variables.yaml +++ b/test/suites/variables.yaml @@ -2,5 +2,5 @@ USHIFT_HOST: microshift # USHIFT_USER: User to log into MicroShift's host USHIFT_USER: microshift -# SSH Private key to use when logging into MicroShift's host. If not defined will require ssh agent setup +# SSH Private key to use when logging into MicroShift's host. SSH_PRIV_KEY: /home/microshift/.ssh/id_rsa