metadata:
  name: apertis-update-manager-rollback
  format: "Apertis Test Definition 1.0"
  image-type: any
  image-arch: armhf
  type: functional
  exec-type: manual
  priority: medium
  maintainer: "Apertis Project"
  description: "Test the automatic rollback and blacklist mechanism of apertis-update-manager."

  resources:
    - "A Fat32 USB flash drive, preloaded with an update bundle named static-update.bundle at the root of the disk"
    - "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"

  expected:
    - "U-Boot is able to detect rollback situation"
    - "U-Boot is able to use rollback configuration for bootloader"
    - 'The "failed" update is rolled back'
    - '"Failed" update is marked as blacklisted'
    - 'Apertis-update-manager is able to detect blacklisted update and refuse to update the system with it' 

run:
  steps:
    - "Check the current deployment"
    - $ sudo ostree admin status
    - "Start the user interface agent with mode preventing automatic system reboot after update"
    - $ sudo updatectl --register-upgrade-handler &
    - "Plug the USB flash drive into the device"
    - "The update starts automatically"
    - "After the update, the device does *not* reboot automatically"
    - "Check that the user interface agent reports the pending update"
    - |
        >** Message: Upgrade status: Checking
         ** Message: An upgrade is pending
    - "Remove the USB flash drive"
    - "Check if there is pending deployment and reboot the DUT"
    - $ sudo ostree admin status
    - $ sudo reboot
    - "In `U-Boot` console check the status of upgrade"
    - $ printenv bootcount bootlimit upgrade_available
    - |
        >bootcount=1
        bootlimit=3
        upgrade_available=1
    - "Reset the DUT 3 times before the boot finishes"
    - "U-Boot should be able to detect the rollback mode and boot the system in rollback mode"
    - |
        >Warning: Bootlimit (3) exceeded. Using altbootcmd.
        Hit any key to stop autoboot:  0 
        switch to partitions #0, OK
        mmc0 is current device
        Scanning mmc 0:1...
        Found /extlinux/extlinux-rollback.conf
        Retrieving file: /extlinux/extlinux-rollback.conf
    - "Wait for system boot"
    - "Check the update has been rolled back and that the initial deployment is still the active deployment"
    - $ sudo ostree admin status
    - "Start the user interface agent"
    - $ sudo updatectl &
    - "Plug the USB flash drive with the same update file into the device"
    - "Check that the user interface agent reports the system is up to update"
    - |
        >** Message: Upgrade status: Checking
        ** Message: System is up to date
    - "Check the journal log should mention that the update ID has been blacklisted"
    - $ sudo journalctl -ef --unit apertis-update-manager
    - |
        >Dec 19 20:54:34 apertis apertis-update-[330]: Ostree static delta starting
        Dec 19 20:54:34 apertis apertis-update-[330]: Revision '9804c4f6e952f0ba61659f55262b9cdd8879cb480084e7f24d9167c2b35f7f28' is marked as blacklisted; skipping
        Dec 19 20:54:34 apertis apertis-update-[330]: Ostree already up to date