From 19b738ae28e87c23e79be0c92958e854324e1998 Mon Sep 17 00:00:00 2001
From: Denis Pynkin <denis.pynkin@collabora.com>
Date: Wed, 3 Apr 2019 00:28:58 +0300
Subject: [PATCH] Update manual tests for checking offline upgrade

After completion of APERTIS-5594 the offline upgrade test has been changed.
Now it is not possible to use random update bundle hence we must to
prepare the system to be upgraded to the same commit.
Added the description how to do that into all AUM manual tests.

Fixes: APERTIS-5808

Signed-off-by: Denis Pynkin <denis.pynkin@collabora.com>
---
 test-cases/apertis-update-manager-api.yaml    | 25 ++++++++++++++++--
 .../apertis-update-manager-automount.yaml     | 25 +++++++++++++++---
 .../apertis-update-manager-diskfull.yaml      | 23 +++++++++++++++-
 test-cases/apertis-update-manager-manual.yaml | 26 ++++++++++++++++---
 .../apertis-update-manager-powercut.yaml      | 23 +++++++++++++++-
 .../apertis-update-manager-rollback.yaml      | 23 +++++++++++++++-
 .../apertis-update-manager-usb-unplug.yaml    | 23 +++++++++++++++-
 7 files changed, 156 insertions(+), 12 deletions(-)

diff --git a/test-cases/apertis-update-manager-api.yaml b/test-cases/apertis-update-manager-api.yaml
index 5eb99c0..840ae28 100644
--- a/test-cases/apertis-update-manager-api.yaml
+++ b/test-cases/apertis-update-manager-api.yaml
@@ -13,8 +13,9 @@ metadata:
                 The automated version of this test: https://qa.apertis.org/aum-api.html"
 
   resources:
-    - "A static update bundle file from https://images.apertis.org/updater-test/armhf-minimal/static-update.bundle"
+    - "A static update bundle file of the same architecture, variant and version as the testing image"
     - "A Fat32 USB flash drive, preloaded with the update bundle at the root of the disk"
+    - "Downloaded update file (with '.delta' extension) should be copied to flash drive using the name 'static-update.bundle'"
     - "The DUT u-boot environment must be clean: in u-boot, run: `env default -a` followed by `saveenv`"
     - "A PC must be connected to DUT serial port"
 
@@ -24,6 +25,26 @@ metadata:
 
 run:
   steps:
+    - "Check the initial deployment"
+    - $ sudo ostree admin status
+    - "Prepare the copy of commit and deploy to allow the upgrade to the same version"
+    - "Command below shows you an initial commit ID, for instance"
+    - |
+        $ export BOOTID=$(sudo ostree admin status | sed -n -e 's/^\* apertis \([0-9a-f]*\)\.[0-9]$/\1/p'); echo $BOOTID
+    - "Get the Collection ID and ref"
+    -  $ export CID=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 1 -d ' '); echo COLLECTION_ID=$CID
+    -  $ export REF=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 2 -d ' '); echo REF=$REF
+    - "Create the commit with changed timestamp to allow upgrade with recent update file"
+    - |
+        $ export NEWID=$(sudo ostree commit --orphan --tree=ref=$BOOTID --add-metadata-string=ostree.collection-binding=$CID --bind-ref=$REF --timestamp="1 year ago"); echo "New commit: $NEWID"
+    - "Deploy the prepared commit"
+    - $ sudo ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$NEWID --reboot
+    - "Wait until the system is booted again and check the deployment"
+    - $ sudo ostree admin status
+    - "The booted commit (started with '*') must have ID which we prepare and the initial commit ID should be marked as '(rollback)'"
+    - "Remove the initial deployment"
+    - $ sudo ostree admin undeploy 1
+    - "Reboot the system"
     - "Check the current deployment"
     - $ sudo ostree admin status
     - "Start the user interface agent with mode preventing automatic system reboot after update"
@@ -39,7 +60,7 @@ run:
     - "Check if there is pending deployment and reboot the DUT"
     - $ sudo ostree admin status
     - $ sudo reboot
-    - "Check the current deployment has been updated and that the rollback entry points to the initial deployment"
+    - "Check the current deployment has been updated and that the rollback entry points to the prepared deployment"
     - $ sudo ostree admin status
     - "Start the user interface agent"
     - $ sudo updatectl &
diff --git a/test-cases/apertis-update-manager-automount.yaml b/test-cases/apertis-update-manager-automount.yaml
index ba6a1d9..e04e4b1 100644
--- a/test-cases/apertis-update-manager-automount.yaml
+++ b/test-cases/apertis-update-manager-automount.yaml
@@ -12,8 +12,9 @@ metadata:
   description: "Test the apertis-update-manager automatic update via mass storage device."
 
   resources:
-    - "A static update bundle file from https://images.apertis.org/updater-test/armhf-minimal/static-update.bundle"
+    - "A static update bundle file of the same architecture, variant and version as the testing image"
     - "A Fat32 USB flash drive, preloaded with the update bundle at the root of the disk"
+    - "Downloaded update file (with '.delta' extension) should be copied to flash drive using the name 'static-update.bundle'"
     - "The DUT u-boot environment must be clean: in u-boot, run: `env default -a` followed by `saveenv`"
     - "A PC must be connected to DUT serial port"
 
@@ -22,11 +23,29 @@ metadata:
 
 run:
   steps:
-    - "Check the current deployment"
+    - "Check the initial deployment"
     - $ sudo ostree admin status
+    - "Prepare the copy of commit and deploy to allow the upgrade to the same version"
+    - "Command below shows you an initial commit ID, for instance"
+    - |
+        $ export BOOTID=$(sudo ostree admin status | sed -n -e 's/^\* apertis \([0-9a-f]*\)\.[0-9]$/\1/p'); echo $BOOTID
+    - "Get the Collection ID and ref"
+    -  $ export CID=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 1 -d ' '); echo COLLECTION_ID=$CID
+    -  $ export REF=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 2 -d ' '); echo REF=$REF
+    - "Create the commit with changed timestamp to allow upgrade with recent update file"
+    - |
+        $ export NEWID=$(sudo ostree commit --orphan --tree=ref=$BOOTID --add-metadata-string=ostree.collection-binding=$CID --bind-ref=$REF --timestamp="1 year ago"); echo "New commit: $NEWID"
+    - "Deploy the prepared commit"
+    - $ sudo ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$NEWID --reboot
+    - "Wait until the system is booted again and check the deployment"
+    - $ sudo ostree admin status
+    - "The booted commit (started with '*') must have ID which we prepare and the initial commit ID should be marked as '(rollback)'"
+    - "Remove the initial deployment"
+    - $ sudo ostree admin undeploy 1
+    - "Reboot the system"
     - "Plug the USB flash drive in the device"
     - "The update starts automatically"
     - "After the update, the device will reboot automatically"
     - "Remove the USB flash drive immediatly after reboot"
-    - "Check the current deployment has been updated and that the rollback entry points to the initial deployment"
+    - "Check the current deployment has been updated and that the rollback entry points to the prepared deployment"
     - $ sudo ostree admin status
diff --git a/test-cases/apertis-update-manager-diskfull.yaml b/test-cases/apertis-update-manager-diskfull.yaml
index bb0a150..ab56686 100644
--- a/test-cases/apertis-update-manager-diskfull.yaml
+++ b/test-cases/apertis-update-manager-diskfull.yaml
@@ -13,8 +13,9 @@ metadata:
                 The automated version of this test: https://qa.apertis.org/aum-out-of-space.html"
 
   resources:
-    - "A static update bundle file from https://images.apertis.org/updater-test/armhf-minimal/static-update.bundle"
+    - "A static update bundle file of the same architecture, variant and version as the testing image"
     - "A Fat32 USB flash drive, preloaded with the update bundle at the root of the disk"
+    - "Downloaded update file (with '.delta' extension) should be copied to flash drive using the name 'static-update.bundle'"
     - "The DUT u-boot environment must be clean: in u-boot, run: `env default -a` followed by `saveenv`"
     - "A PC must be connected to DUT serial port"
 
@@ -24,6 +25,26 @@ metadata:
 
 run:
   steps:
+    - "Check the initial deployment"
+    - $ sudo ostree admin status
+    - "Prepare the copy of commit and deploy to allow the upgrade to the same version"
+    - "Command below shows you an initial commit ID, for instance"
+    - |
+        $ export BOOTID=$(sudo ostree admin status | sed -n -e 's/^\* apertis \([0-9a-f]*\)\.[0-9]$/\1/p'); echo $BOOTID
+    - "Get the Collection ID and ref"
+    -  $ export CID=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 1 -d ' '); echo COLLECTION_ID=$CID
+    -  $ export REF=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 2 -d ' '); echo REF=$REF
+    - "Create the commit with changed timestamp to allow upgrade with recent update file"
+    - |
+        $ export NEWID=$(sudo ostree commit --orphan --tree=ref=$BOOTID --add-metadata-string=ostree.collection-binding=$CID --bind-ref=$REF --timestamp="1 year ago"); echo "New commit: $NEWID"
+    - "Deploy the prepared commit"
+    - $ sudo ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$NEWID --reboot
+    - "Wait until the system is booted again and check the deployment"
+    - $ sudo ostree admin status
+    - "The booted commit (started with '*') must have ID which we prepare and the initial commit ID should be marked as '(rollback)'"
+    - "Remove the initial deployment"
+    - $ sudo ostree admin undeploy 1
+    - "Reboot the system"
     - "Check the current deployment"
     - $ sudo ostree admin status
     - "Need to monitor the journal log"
diff --git a/test-cases/apertis-update-manager-manual.yaml b/test-cases/apertis-update-manager-manual.yaml
index 862a3f9..8b9d1a6 100644
--- a/test-cases/apertis-update-manager-manual.yaml
+++ b/test-cases/apertis-update-manager-manual.yaml
@@ -14,22 +14,42 @@ metadata:
 
   resources:
     - "A PC must be connected to DUT serial port"
+    - "A static update bundle file of the same architecture, variant and version as the testing image"
 
   expected:
     - "The update was properly applied"
 
 run:
   steps:
+    - "Check the initial deployment"
+    - $ sudo ostree admin status
+    - "Prepare the copy of commit and deploy to allow the upgrade to the same version"
+    - "Command below shows you an initial commit ID, for instance"
+    - |
+        $ export BOOTID=$(sudo ostree admin status | sed -n -e 's/^\* apertis \([0-9a-f]*\)\.[0-9]$/\1/p'); echo $BOOTID
+    - "Get the Collection ID and ref"
+    -  $ export CID=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 1 -d ' '); echo COLLECTION_ID=$CID
+    -  $ export REF=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 2 -d ' '); echo REF=$REF
+    - "Create the commit with changed timestamp to allow upgrade with recent update file"
+    - |
+        $ export NEWID=$(sudo ostree commit --orphan --tree=ref=$BOOTID --add-metadata-string=ostree.collection-binding=$CID --bind-ref=$REF --timestamp="1 year ago"); echo "New commit: $NEWID"
+    - "Deploy the prepared commit"
+    - $ sudo ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$NEWID --reboot
+    - "Wait until the system is booted again and check the deployment"
+    - $ sudo ostree admin status
+    - "The booted commit (started with '*') must have ID which we prepare and the initial commit ID should be marked as '(rollback)'"
+    - "Remove the initial deployment"
+    - $ sudo ostree admin undeploy 1
+    - "Reboot the system"
     - "Check the current deployment"
     - $ sudo ostree admin status
     - "Remove blacklist file if it exists"
     - $ sudo rm -f /var/aum_blacklist.conf
-    - "From the host, download a static delta update and copy it to the target using scp"
-    - $ wget https://images.apertis.org/updater-test/armhf-minimal/static-update.bundle
+    - "From the host, copy the static delta update to the target using scp"
     - $ scp /path/to/static/delta user@target:update.bundle
     - "The update does not start automatically, start it manually"
     - $ sudo updatectl --apply-static-delta /home/user/update.bundle
     - "After the update, the device will reboot automatically"
-    - "Check the current deployment has been updated and that the rollback entry points to the initial deployment"
+    - "Check the current deployment has been updated and that the rollback entry points to the prepared deployment"
     - $ sudo ostree admin status
 
diff --git a/test-cases/apertis-update-manager-powercut.yaml b/test-cases/apertis-update-manager-powercut.yaml
index d1958a9..006e3cb 100644
--- a/test-cases/apertis-update-manager-powercut.yaml
+++ b/test-cases/apertis-update-manager-powercut.yaml
@@ -13,8 +13,9 @@ metadata:
                 The automated version of this test: https://qa.apertis.org/aum-power-cut.html"
 
   resources:
-    - "A static update bundle file from https://images.apertis.org/updater-test/armhf-minimal/static-update.bundle"
+    - "A static update bundle file of the same architecture, variant and version as the testing image"
     - "A Fat32 USB flash drive, preloaded with the update bundle at the root of the disk"
+    - "Downloaded update file (with '.delta' extension) should be copied to flash drive using the name 'static-update.bundle'"
     - "The DUT u-boot environment must be clean: in u-boot, run: `env default -a` followed by `saveenv`"
     - "A PC must be connected to DUT serial port"
 
@@ -25,6 +26,26 @@ metadata:
 
 run:
   steps:
+    - "Check the initial deployment"
+    - $ sudo ostree admin status
+    - "Prepare the copy of commit and deploy to allow the upgrade to the same version"
+    - "Command below shows you an initial commit ID, for instance"
+    - |
+        $ export BOOTID=$(sudo ostree admin status | sed -n -e 's/^\* apertis \([0-9a-f]*\)\.[0-9]$/\1/p'); echo $BOOTID
+    - "Get the Collection ID and ref"
+    -  $ export CID=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 1 -d ' '); echo COLLECTION_ID=$CID
+    -  $ export REF=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 2 -d ' '); echo REF=$REF
+    - "Create the commit with changed timestamp to allow upgrade with recent update file"
+    - |
+        $ export NEWID=$(sudo ostree commit --orphan --tree=ref=$BOOTID --add-metadata-string=ostree.collection-binding=$CID --bind-ref=$REF --timestamp="1 year ago"); echo "New commit: $NEWID"
+    - "Deploy the prepared commit"
+    - $ sudo ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$NEWID --reboot
+    - "Wait until the system is booted again and check the deployment"
+    - $ sudo ostree admin status
+    - "The booted commit (started with '*') must have ID which we prepare and the initial commit ID should be marked as '(rollback)'"
+    - "Remove the initial deployment"
+    - $ sudo ostree admin undeploy 1
+    - "Reboot the system"
     - "Check the current deployment"
     - $ sudo ostree admin status
     - "Need to monitor the journal log to catch events in time"
diff --git a/test-cases/apertis-update-manager-rollback.yaml b/test-cases/apertis-update-manager-rollback.yaml
index 07c08e5..d1c5e2b 100644
--- a/test-cases/apertis-update-manager-rollback.yaml
+++ b/test-cases/apertis-update-manager-rollback.yaml
@@ -13,8 +13,9 @@ metadata:
                 The automated version of this test: https://qa.apertis.org/aum-rollback-blacklist.html"
 
   resources:
-    - "A static update bundle file from https://images.apertis.org/updater-test/armhf-minimal/static-update.bundle"
+    - "A static update bundle file of the same architecture, variant and version as the testing image"
     - "A Fat32 USB flash drive, preloaded with the update bundle at the root of the disk"
+    - "Downloaded update file (with '.delta' extension) should be copied to flash drive using the name 'static-update.bundle'"
     - "The DUT u-boot environment must be clean: in u-boot, run: `env default -a` followed by `saveenv`"
     - "A PC must be connected to DUT serial port"
 
@@ -27,6 +28,26 @@ metadata:
 
 run:
   steps:
+    - "Check the initial deployment"
+    - $ sudo ostree admin status
+    - "Prepare the copy of commit and deploy to allow the upgrade to the same version"
+    - "Command below shows you an initial commit ID, for instance"
+    - |
+        $ export BOOTID=$(sudo ostree admin status | sed -n -e 's/^\* apertis \([0-9a-f]*\)\.[0-9]$/\1/p'); echo $BOOTID
+    - "Get the Collection ID and ref"
+    -  $ export CID=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 1 -d ' '); echo COLLECTION_ID=$CID
+    -  $ export REF=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 2 -d ' '); echo REF=$REF
+    - "Create the commit with changed timestamp to allow upgrade with recent update file"
+    - |
+        $ export NEWID=$(sudo ostree commit --orphan --tree=ref=$BOOTID --add-metadata-string=ostree.collection-binding=$CID --bind-ref=$REF --timestamp="1 year ago"); echo "New commit: $NEWID"
+    - "Deploy the prepared commit"
+    - $ sudo ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$NEWID --reboot
+    - "Wait until the system is booted again and check the deployment"
+    - $ sudo ostree admin status
+    - "The booted commit (started with '*') must have ID which we prepare and the initial commit ID should be marked as '(rollback)'"
+    - "Remove the initial deployment"
+    - $ sudo ostree admin undeploy 1
+    - "Reboot the system"
     - "Check the current deployment"
     - $ sudo ostree admin status
     - "Start the user interface agent with mode preventing automatic system reboot after update"
diff --git a/test-cases/apertis-update-manager-usb-unplug.yaml b/test-cases/apertis-update-manager-usb-unplug.yaml
index 9e85eaf..f3fa4b5 100644
--- a/test-cases/apertis-update-manager-usb-unplug.yaml
+++ b/test-cases/apertis-update-manager-usb-unplug.yaml
@@ -12,8 +12,9 @@ metadata:
   description: "Test the apertis-update-manager automatic update interrupted by mass storage removing."
 
   resources:
-    - "A static update bundle file from https://images.apertis.org/updater-test/armhf-minimal/static-update.bundle"
+    - "A static update bundle file of the same architecture, variant and version as the testing image"
     - "A Fat32 USB flash drive, preloaded with the update bundle at the root of the disk"
+    - "Downloaded update file (with '.delta' extension) should be copied to flash drive using the name 'static-update.bundle'"
     - "The DUT u-boot environment must be clean: in u-boot, run: `env default -a` followed by `saveenv`"
     - "A PC must be connected to DUT serial port"
 
@@ -23,6 +24,26 @@ metadata:
 
 run:
   steps:
+    - "Check the initial deployment"
+    - $ sudo ostree admin status
+    - "Prepare the copy of commit and deploy to allow the upgrade to the same version"
+    - "Command below shows you an initial commit ID, for instance"
+    - |
+        $ export BOOTID=$(sudo ostree admin status | sed -n -e 's/^\* apertis \([0-9a-f]*\)\.[0-9]$/\1/p'); echo $BOOTID
+    - "Get the Collection ID and ref"
+    -  $ export CID=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 1 -d ' '); echo COLLECTION_ID=$CID
+    -  $ export REF=$(sudo ostree refs -c | head -n 1 | tr -d '(),' | cut -f 2 -d ' '); echo REF=$REF
+    - "Create the commit with changed timestamp to allow upgrade with recent update file"
+    - |
+        $ export NEWID=$(sudo ostree commit --orphan --tree=ref=$BOOTID --add-metadata-string=ostree.collection-binding=$CID --bind-ref=$REF --timestamp="1 year ago"); echo "New commit: $NEWID"
+    - "Deploy the prepared commit"
+    - $ sudo ostree admin upgrade --allow-downgrade --deploy-only --override-commit=$NEWID --reboot
+    - "Wait until the system is booted again and check the deployment"
+    - $ sudo ostree admin status
+    - "The booted commit (started with '*') must have ID which we prepare and the initial commit ID should be marked as '(rollback)'"
+    - "Remove the initial deployment"
+    - $ sudo ostree admin undeploy 1
+    - "Reboot the system"
     - "Check the current deployment"
     - $ sudo ostree admin status
     - "Need to monitor the journal log to catch events in time"
-- 
GitLab