From 7a715060a70f5305c896d73d09adc8520250e64c Mon Sep 17 00:00:00 2001 From: Patryk Matuszak <305846+pmtk@users.noreply.github.com> Date: Thu, 1 Jun 2023 08:49:56 +0200 Subject: [PATCH 1/2] rebooting healthy system should result in backing up the data --- test/resources/microshift-host.resource | 12 ++++ test/resources/microshift-process.resource | 13 ++++ test/resources/ostree.resource | 62 +++++++++++++++++ test/suites-ostree/upgrade-ostree.robot | 78 ++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 test/resources/ostree.resource create mode 100644 test/suites-ostree/upgrade-ostree.robot diff --git a/test/resources/microshift-host.resource b/test/resources/microshift-host.resource index 7a1218f1a1..43acace5e8 100644 --- a/test/resources/microshift-host.resource +++ b/test/resources/microshift-host.resource @@ -25,3 +25,15 @@ Login MicroShift Host Logout MicroShift Host [Documentation] Close the open ssh connection to the MicroShift host SSHLibrary.Close Connection + +Reboot MicroShift Host + [Documentation] Reboot the MicroShift host + ... + ... Expects that SSH connection to MicroShift host is active. + + SSHLibrary.Start Command reboot sudo=True + Sleep 30s + Wait Until Keyword Succeeds 5m 15s Login MicroShift Host + + ${rc}= SSHLibrary.Execute Command true return_stdout=False return_rc=True + Should Be Equal As Integers 0 ${rc} diff --git a/test/resources/microshift-process.resource b/test/resources/microshift-process.resource index e388837d7d..c00a288d36 100644 --- a/test/resources/microshift-process.resource +++ b/test/resources/microshift-process.resource @@ -47,6 +47,19 @@ Wait For MicroShift # greenboot check script to let us use it even when not on a # greenboot host? +MicroShift Service Is Active + [Documentation] Check if microshift.service is active + ... (process announced readiness) + ${state}= Get Systemd Setting microshift.service ActiveState + Should Be Equal As Strings ${state} active + +Wait For MicroShift Service + [Documentation] Wait for MicroShift service to be active + Wait Until Keyword Succeeds + ... 50x + ... 10s + ... MicroShift Service Is Active + Restart MicroShift [Documentation] Restart the MicroShift service # Use separate stop and start steps to avoid a race condition with diff --git a/test/resources/ostree.resource b/test/resources/ostree.resource new file mode 100644 index 0000000000..6d293509aa --- /dev/null +++ b/test/resources/ostree.resource @@ -0,0 +1,62 @@ +*** Settings *** +Documentation Keywords for OSTree-based systems + +Library SSHLibrary + + +*** Variables *** +${BACKUP_STORAGE} /var/lib/microshift-backups +${HEALTH_FILE} /var/lib/microshift-backups/health.json + + +*** Keywords *** +Get Booted Deployment Status + [Documentation] Get rpm-ostree status of booted deployment as a json + + ${ostree_status} ${rc}= Execute Command + ... rpm-ostree status --booted --json + ... return_rc=True + Should Be Equal As Integers 0 ${rc} + ${json}= Evaluate json.loads('''${ostree_status}''') json + RETURN ${json} + +Get Booted Deployment ID + [Documentation] Get ID of currently booted deployment + + ${status}= Get Booted Deployment Status + RETURN ${status["deployments"][0]["id"]} + +Get Booted Deployment Backup Prefix Path + [Documentation] Get backup path prefix for current deployment + ... + ... Prefix path is BACKUP_STORAGE/deployment-id. + ... Globbing directories starting with the prefix will yield + ... list of backups for the deployment. + + ${current_deployment_id}= Get Booted Deployment ID + Should Not Be Empty ${current_deployment_id} + Should Not Be Empty ${BACKUP_STORAGE} + ${backup_path}= Catenate SEPARATOR=/ ${BACKUP_STORAGE} ${current_deployment_id} + RETURN ${backup_path} + +Get System Health + [Documentation] Get system health information from health.json file + + ${health} ${stderr} ${rc}= Execute Command + ... jq -r '.health' ${BACKUP_STORAGE}/health.json + ... sudo=True return_rc=True return_stderr=True + Should Be Equal As Integers 0 ${rc} + RETURN ${health} + +Does Backup For Booted Deployment Exist + [Documentation] Checks if any backup for current deployment exists + ... by finding paths starting with "backup prefix path" + + ${deploy_id}= Get Booted Deployment ID + ${output} ${rc}= Execute Command + ... find ${BACKUP_STORAGE} -name '${deploy_id}*' | wc -l + ... sudo=True return_rc=True + Should Be Equal As Integers 0 ${rc} + + IF "${output}" == "0" RETURN ${False} + RETURN ${True} diff --git a/test/suites-ostree/upgrade-ostree.robot b/test/suites-ostree/upgrade-ostree.robot new file mode 100644 index 0000000000..14f4099aea --- /dev/null +++ b/test/suites-ostree/upgrade-ostree.robot @@ -0,0 +1,78 @@ +*** Settings *** +Documentation Tests related to MicroShift upgradeability on OSTree-based systems + +Resource ../resources/common.resource +Resource ../resources/ostree.resource +Resource ../resources/systemd.resource +Resource ../resources/microshift-process.resource +Library Collections + +Suite Setup Setup +Suite Teardown Teardown + +Test Tags ostree + + +*** Variables *** +${USHIFT_HOST} ${EMPTY} +${USHIFT_USER} ${EMPTY} + + +*** Test Cases *** +Rebooting Healthy System Should Result In Data Backup + [Documentation] Check if rebooting healthy system will result in backing up of MicroShift data + + Wait Until Greenboot Health Check Exited + System Should Be Healthy + Remove Existing Backup For Current Deployment + + Reboot MicroShift Host + Wait For MicroShift Service + + Backup For Booted Deployment Should Exist + + +*** Keywords *** +Setup + [Documentation] Test suite setup + Check Required Env Variables + Login MicroShift Host + +Teardown + [Documentation] Test suite teardown + Logout MicroShift Host + +Wait Until Greenboot Health Check Exited + [Documentation] Wait until greenboot healthchecks are done + + Wait Until Keyword Succeeds 5m 15s + ... Greenboot Health Check Exited + +Greenboot Health Check Exited + [Documentation] Checks if greenboot-healthcheck finished running + + ${value}= Get Systemd Setting greenboot-healthcheck.service SubState + Should Be Equal As Strings ${value} exited + +Remove Existing Backup For Current Deployment + [Documentation] Remove backups for current deployment + + ${path}= Get Booted Deployment Backup Prefix Path + Should Not Be Empty ${path} + + ${rm_output} ${rm_stderr} ${rc}= Execute Command + ... rm -rf ${path}* + ... sudo=True return_stderr=True return_rc=True + Log ${rm_stderr} + Log ${rm_output} + Should Be Equal As Integers 0 ${rc} + +Backup For Booted Deployment Should Exist + [Documentation] Asserts that backup for currently booted deployment exists + ${exists}= Does Backup For Booted Deployment Exist + Should Be True ${exists} + +System Should Be Healthy + [Documentation] Asserts that persisted health information is "healthy" + ${health}= Get System Health + Should Be Equal As Strings healthy ${health} From a7d4fdf3d1e02e61de8e15816059bfd593f671d6 Mon Sep 17 00:00:00 2001 From: Patryk Matuszak <305846+pmtk@users.noreply.github.com> Date: Mon, 12 Jun 2023 13:06:30 +0200 Subject: [PATCH 2/2] add JSON -> DotDict helper --- test/resources/{YAML.py => DataFormats.py} | 14 +++++++++++++- test/resources/microshift-config.resource | 2 +- test/resources/microshift-process.resource | 8 ++++---- test/resources/oc.resource | 2 +- test/resources/ostree.resource | 11 ++++++----- test/suites/show-config.robot | 2 +- test/suites/version.robot | 2 +- 7 files changed, 27 insertions(+), 14 deletions(-) rename test/resources/{YAML.py => DataFormats.py} (85%) diff --git a/test/resources/YAML.py b/test/resources/DataFormats.py similarity index 85% rename from test/resources/YAML.py rename to test/resources/DataFormats.py index 26f0fe152c..fd266d2610 100644 --- a/test/resources/YAML.py +++ b/test/resources/DataFormats.py @@ -1,9 +1,21 @@ -"""Expose YAML parser to robot tests. +"""Provides helpers for common data formats """ +import json import yaml from robot.utils import DotDict +def json_parse(data): + """Parse input string as JSON and return DotDict instance. + + If the input data is empty, return an empty DotDict. + """ + if not data: + return DotDict() + parsed = json.loads(data) + return DotDict(parsed) + + def yaml_parse(data): """Parse input string as YAML and return DotDict instance. diff --git a/test/resources/microshift-config.resource b/test/resources/microshift-config.resource index ab92f72aa8..f02d74e46e 100644 --- a/test/resources/microshift-config.resource +++ b/test/resources/microshift-config.resource @@ -6,7 +6,7 @@ Library String Library OperatingSystem Library SSHLibrary -Library ../resources/YAML.py +Library DataFormats.py *** Keywords *** diff --git a/test/resources/microshift-process.resource b/test/resources/microshift-process.resource index c00a288d36..0fbc41a5c6 100644 --- a/test/resources/microshift-process.resource +++ b/test/resources/microshift-process.resource @@ -6,10 +6,10 @@ Library String Library OperatingSystem Library SSHLibrary -Resource ../resources/oc.resource -Resource ../resources/systemd.resource -Resource ../resources/microshift-host.resource -Library ../resources/YAML.py +Resource oc.resource +Resource systemd.resource +Resource microshift-host.resource +Library DataFormats.py *** Keywords *** diff --git a/test/resources/oc.resource b/test/resources/oc.resource index cc9219b42a..58366ef103 100644 --- a/test/resources/oc.resource +++ b/test/resources/oc.resource @@ -5,7 +5,7 @@ Documentation Keywords for using the oc command line. ... 'oc' is in the $PATH. Resource common.resource -Library YAML.py +Library DataFormats.py *** Keywords *** diff --git a/test/resources/ostree.resource b/test/resources/ostree.resource index 6d293509aa..6f36479d39 100644 --- a/test/resources/ostree.resource +++ b/test/resources/ostree.resource @@ -1,7 +1,8 @@ *** Settings *** -Documentation Keywords for OSTree-based systems +Documentation Keywords for OSTree-based systems -Library SSHLibrary +Library SSHLibrary +Library DataFormats.py *** Variables *** @@ -17,14 +18,14 @@ Get Booted Deployment Status ... rpm-ostree status --booted --json ... return_rc=True Should Be Equal As Integers 0 ${rc} - ${json}= Evaluate json.loads('''${ostree_status}''') json - RETURN ${json} + ${status}= Json Parse ${ostree_status} + RETURN ${status} Get Booted Deployment ID [Documentation] Get ID of currently booted deployment ${status}= Get Booted Deployment Status - RETURN ${status["deployments"][0]["id"]} + RETURN ${status.deployments[0].id} Get Booted Deployment Backup Prefix Path [Documentation] Get backup path prefix for current deployment diff --git a/test/suites/show-config.robot b/test/suites/show-config.robot index 2b6b974935..70b48a733f 100644 --- a/test/suites/show-config.robot +++ b/test/suites/show-config.robot @@ -5,7 +5,7 @@ Resource ../resources/common.resource Resource ../resources/microshift-config.resource Resource ../resources/microshift-host.resource Resource ../resources/microshift-process.resource -Library ../resources/YAML.py +Library ../resources/DataFormats.py Suite Setup Setup Suite Teardown Teardown diff --git a/test/suites/version.robot b/test/suites/version.robot index 1c84d86725..09b85aba6a 100755 --- a/test/suites/version.robot +++ b/test/suites/version.robot @@ -5,7 +5,7 @@ Resource ../resources/common.resource Resource ../resources/oc.resource Resource ../resources/microshift-process.resource Library Collections -Library ../resources/YAML.py +Library ../resources/DataFormats.py Suite Setup Setup Suite Teardown Teardown