From 4afef396e84d1a06c70fff716d196423b954e166 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 18 May 2023 10:01:18 -0400 Subject: [PATCH 1/5] update the log level to trace This ensures full return values and assigned values are logged, which means we need fewer explicit log calls. Signed-off-by: Doug Hellmann --- test/run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run.sh b/test/run.sh index 1564c4e5a2..5c80c6ac9e 100755 --- a/test/run.sh +++ b/test/run.sh @@ -81,7 +81,7 @@ else # shellcheck disable=SC2086 "${RF_BINARY}" \ --randomize all \ - --loglevel DEBUG \ + --loglevel TRACE \ -V "${RF_VARIABLES}" \ -x junit.xml \ --outputdir "${OUTDIR}" \ From a63bfe3a93bfc5d579475bf3d12dd631328920ad Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Sat, 29 Apr 2023 14:59:08 -0400 Subject: [PATCH 2/5] return stdout from commands run with kubeconfig We will use the output of some commands, so return it. Signed-off-by: Doug Hellmann --- test/resources/kubeconfig.resource | 1 + 1 file changed, 1 insertion(+) diff --git a/test/resources/kubeconfig.resource b/test/resources/kubeconfig.resource index 344e18d65b..5a08581bc3 100644 --- a/test/resources/kubeconfig.resource +++ b/test/resources/kubeconfig.resource @@ -37,6 +37,7 @@ Run With Kubeconfig IF ${allow_fail} == False Should Be Equal As Integers ${result.rc} 0 END + RETURN ${result.stdout} Create Namespace [Documentation] Creates a namespace with the given name. From 7aa09d405899d327757e8d50ee501cea74407030 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 18 May 2023 10:01:54 -0400 Subject: [PATCH 3/5] log stderr in Run With Kubeconfig Signed-off-by: Doug Hellmann --- test/resources/kubeconfig.resource | 1 + 1 file changed, 1 insertion(+) diff --git a/test/resources/kubeconfig.resource b/test/resources/kubeconfig.resource index 5a08581bc3..ad624955a7 100644 --- a/test/resources/kubeconfig.resource +++ b/test/resources/kubeconfig.resource @@ -34,6 +34,7 @@ Run With Kubeconfig [Arguments] ${cmd} ${allow_fail}=False ${result}= Run Process ${cmd} env:KUBECONFIG=${KUBECONFIG} stderr=STDOUT shell=True Log ${result.stdout} + Log ${result.stderr} IF ${allow_fail} == False Should Be Equal As Integers ${result.rc} 0 END From 678b33ed7a121d5d962d0e63807c6dad7483d390 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Sat, 6 May 2023 13:05:21 -0400 Subject: [PATCH 4/5] USHIFT-1198: add tests for version API Signed-off-by: Doug Hellmann --- test/resources/YAML.py | 10 +++ test/resources/microshift-host.resource | 6 +- test/resources/microshift-process.resource | 22 ++++++ test/resources/oc.resource | 13 ++++ test/suites/version.robot | 83 ++++++++++++++++++++++ 5 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 test/resources/YAML.py create mode 100644 test/resources/microshift-process.resource create mode 100644 test/resources/oc.resource create mode 100755 test/suites/version.robot diff --git a/test/resources/YAML.py b/test/resources/YAML.py new file mode 100644 index 0000000000..de066175e6 --- /dev/null +++ b/test/resources/YAML.py @@ -0,0 +1,10 @@ +"""Expose YAML parser to robot tests. +""" +import yaml +from robot.utils import DotDict + + +def yaml_parse(data): + """Parse input string as YAML and return DotDict instance.""" + parsed = yaml.safe_load(data) + return DotDict(parsed) diff --git a/test/resources/microshift-host.resource b/test/resources/microshift-host.resource index 4e95e863cf..8bca593f60 100644 --- a/test/resources/microshift-host.resource +++ b/test/resources/microshift-host.resource @@ -5,7 +5,11 @@ Library SSHLibrary *** Keywords *** Login MicroShift Host [Documentation] Login to the MicroShift host via ssh and leave the connection open - [Arguments] + ... + ... This keyword is meant to be used at the suite level. This ensures + ... most tests already have an open connection. Any tests that will take + ... action that disrupt that connection are responsible for restoring it. + Log Host: ${USHIFT_HOST} SSHLibrary.Open Connection ${USHIFT_HOST} ${variables}= Get Variables diff --git a/test/resources/microshift-process.resource b/test/resources/microshift-process.resource new file mode 100644 index 0000000000..70566e5ece --- /dev/null +++ b/test/resources/microshift-process.resource @@ -0,0 +1,22 @@ +*** Settings *** +Library Process +Library SSHLibrary +Library String +Library OperatingSystem +Resource ../resources/systemd.resource +Resource ../resources/microshift-host.resource +Library ../resources/YAML.py + + +*** Keywords *** +MicroShift Version + [Documentation] Run the version command + Login MicroShift host + ${version_text} ${rc}= Execute Command + ... microshift version -o yaml + ... sudo=True return_rc=True + Should Be Equal As Integers ${rc} 0 + Should Not Be Empty ${version_text} + Logout MicroShift Host + ${version}= Yaml Parse ${version_text} + RETURN ${version} diff --git a/test/resources/oc.resource b/test/resources/oc.resource new file mode 100644 index 0000000000..776440127c --- /dev/null +++ b/test/resources/oc.resource @@ -0,0 +1,13 @@ +*** Settings *** +Resource common.resource +Library YAML.py + +*** Keywords *** + +Oc Get + [Arguments] ${type} ${namespace} ${resource} + + ${yaml_text}= Run With Kubeconfig oc get -n ${namespace} -o yaml ${type} ${resource} + ${yaml_data}= Yaml Parse ${yaml_text} + + RETURN ${yaml_data} diff --git a/test/suites/version.robot b/test/suites/version.robot new file mode 100755 index 0000000000..dd451ac28f --- /dev/null +++ b/test/suites/version.robot @@ -0,0 +1,83 @@ +*** Settings *** +Documentation Tests related to the version of MicroShift + +Resource ../resources/common.resource +Resource ../resources/oc.resource +Resource ../resources/microshift-process.resource +Library Collections +Library ../resources/YAML.py + +Suite Setup Setup +Suite Teardown Teardown + + +*** Variables *** +${USHIFT_HOST} ${EMPTY} +${USHIFT_USER} ${EMPTY} + + +*** Test Cases *** +ConfigMap Contents + [Documentation] Check the version of the server + + ${configmap}= Oc Get configmap kube-public microshift-version + Should Be Equal As Integers ${configmap.data.major} ${MAJOR_VERSION} + Should Be Equal As Integers ${configmap.data.minor} ${MINOR_VERSION} + +CLI Output + [Documentation] Check the version reported by the process + + ${version}= MicroShift Version + Should Be Equal As Integers ${version.major} ${MAJOR_VERSION} + Should Be Equal As Integers ${version.minor} ${MINOR_VERSION} + Should Start With ${version.gitVersion} ${Y_STREAM} + +ConfigMap Matches CLI + [Documentation] Ensure the ConfigMap is being updated based on the actual binary version + + ${configmap}= Oc Get configmap kube-public microshift-version + ${cli}= MicroShift Version + Should Be Equal ${configmap.data.version} ${cli.gitVersion} + + +*** Keywords *** +Setup + [Documentation] Test suite setup + Check Required Env Variables + Setup Kubeconfig + Read Expected Versions + +Teardown + [Documentation] Test suite teardown + Remove Kubeconfig + +Read Expected Versions # robocop: disable=too-many-calls-in-keyword + [Documentation] Read ../Makefile.version.aarch64.var to find the expected versions + ... Sets suite variables FULL_VERSION, MAJOR_VERSION, MINOR_VERSION, and Y_STREAM based on + ... the content. + + # The file contains content in this format: + # + # OCP_VERSION := 4.14.0-0.nightly-arm64-2023-05-04-012046 + + ${unparsed}= OperatingSystem.Get File ../Makefile.version.aarch64.var + + # 4.14.0-0.nightly-arm64-2023-05-04-012046 + ${version_full_raw}= Fetch From Right ${unparsed} := + ${version_full}= Strip String ${version_full_raw} + Set Suite Variable \${FULL_VERSION} ${version_full} + + # 4 + ${major}= Fetch From Left ${version_full} . + Set Suite Variable \${MAJOR_VERSION} ${major} + + # 14.0-0.nightly-arm64-2023-05-04-012046 + ${without_major}= Get Substring ${version_full} 2 + + # 14 + ${minor}= Fetch From Left ${without_major} . + Set Suite Variable \${MINOR_VERSION} ${minor} + + # 4.14 + ${ystream}= Format String {}.{} ${major} ${minor} + Set Suite Variable \${Y_STREAM} ${ystream} From ffb0966e51eb68af765f019decdd109fed4f9b58 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Fri, 19 May 2023 12:41:11 -0400 Subject: [PATCH 5/5] move login/logout to suite setup/teardown steps Instead of logging into the microshift host each time we need to do something on that host, login when the test suite starts. This means most tests already have an open connection. Any tests that will take action that disrupt that connection are responsible for restoring it. Signed-off-by: Doug Hellmann --- test/resources/common.resource | 2 ++ test/resources/kubeconfig.resource | 2 -- test/resources/microshift-process.resource | 3 --- test/suites/version.robot | 2 ++ 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test/resources/common.resource b/test/resources/common.resource index 5945f0ac35..cf3ebd79cb 100644 --- a/test/resources/common.resource +++ b/test/resources/common.resource @@ -12,6 +12,7 @@ Setup Suite Setup Suite With Namespace [Documentation] Setup a test suite by creating a unique namespace and configuring Kubeconfig Check Required Env Variables + Login MicroShift Host Setup Kubeconfig ${rand}= Generate Random String ${rand}= Convert To Lower Case ${rand} @@ -22,6 +23,7 @@ Setup Suite With Namespace Teardown Suite [Documentation] Teardown the namespace-less test suite by removing the Kubeconfig. Remove Kubeconfig + Login MicroShift Host Teardown Suite With Namespace [Documentation] Teardown the namespaced test suite by removing the namespace and removing the Kubeconfig. diff --git a/test/resources/kubeconfig.resource b/test/resources/kubeconfig.resource index ad624955a7..82a5ac5fb6 100644 --- a/test/resources/kubeconfig.resource +++ b/test/resources/kubeconfig.resource @@ -7,11 +7,9 @@ Resource ../resources/microshift-host.resource Get Kubeconfig [Documentation] Get the kubeconfig file from the host argument and return contents [Arguments] ${host} - Login MicroShift Host ${kubeconfig} ${rc}= Execute Command ... cat /var/lib/microshift/resources/kubeadmin/${host}/kubeconfig ... sudo=True return_rc=True - Logout MicroShift Host Should Be Equal As Integers ${rc} 0 Should Not Be Empty ${kubeconfig} [Return] ${kubeconfig} diff --git a/test/resources/microshift-process.resource b/test/resources/microshift-process.resource index 70566e5ece..679213cffd 100644 --- a/test/resources/microshift-process.resource +++ b/test/resources/microshift-process.resource @@ -3,7 +3,6 @@ Library Process Library SSHLibrary Library String Library OperatingSystem -Resource ../resources/systemd.resource Resource ../resources/microshift-host.resource Library ../resources/YAML.py @@ -11,12 +10,10 @@ Library ../resources/YAML.py *** Keywords *** MicroShift Version [Documentation] Run the version command - Login MicroShift host ${version_text} ${rc}= Execute Command ... microshift version -o yaml ... sudo=True return_rc=True Should Be Equal As Integers ${rc} 0 Should Not Be Empty ${version_text} - Logout MicroShift Host ${version}= Yaml Parse ${version_text} RETURN ${version} diff --git a/test/suites/version.robot b/test/suites/version.robot index dd451ac28f..1c84d86725 100755 --- a/test/suites/version.robot +++ b/test/suites/version.robot @@ -44,12 +44,14 @@ ConfigMap Matches CLI Setup [Documentation] Test suite setup Check Required Env Variables + Login MicroShift Host Setup Kubeconfig Read Expected Versions Teardown [Documentation] Test suite teardown Remove Kubeconfig + Logout MicroShift Host Read Expected Versions # robocop: disable=too-many-calls-in-keyword [Documentation] Read ../Makefile.version.aarch64.var to find the expected versions