diff --git a/src/libostree/ostree-sysroot-upgrader.c b/src/libostree/ostree-sysroot-upgrader.c index a87548a3..8fb231a3 100644 --- a/src/libostree/ostree-sysroot-upgrader.c +++ b/src/libostree/ostree-sysroot-upgrader.c @@ -644,21 +644,37 @@ ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader *self, GError **error) { g_autoptr(OstreeDeployment) new_deployment = NULL; - if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname, - self->new_revision, - self->origin, - self->merge_deployment, - NULL, - &new_deployment, - cancellable, error)) - return FALSE; - if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname, - new_deployment, - self->merge_deployment, - 0, - cancellable, error)) - return FALSE; + /* Experimental flag to enable staging */ + if (getenv ("OSTREE_EX_STAGE_DEPLOYMENTS")) + { + if (!ostree_sysroot_stage_tree (self->sysroot, self->osname, + self->new_revision, + self->origin, + self->merge_deployment, + NULL, + &new_deployment, + cancellable, error)) + return FALSE; + } + else + { + if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname, + self->new_revision, + self->origin, + self->merge_deployment, + NULL, + &new_deployment, + cancellable, error)) + return FALSE; + + if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname, + new_deployment, + self->merge_deployment, + 0, + cancellable, error)) + return FALSE; + } return TRUE; } diff --git a/tests/admin-test.sh b/tests/admin-test.sh index dd87cd11..7384d8f3 100644 --- a/tests/admin-test.sh +++ b/tests/admin-test.sh @@ -21,7 +21,7 @@ set -euo pipefail -echo "1..$((24 + ${extra_admin_tests:-0}))" +echo "1..$((25 + ${extra_admin_tests:-0}))" function validate_bootloader() { cd ${test_tmpdir}; @@ -215,6 +215,11 @@ validate_bootloader echo "ok upgrade bare" os_repository_new_commit +if env OSTREE_EX_STAGE_DEPLOYMENTS=1 ${CMD_PREFIX} ostree admin upgrade --os=testos 2>err.txt; then + fatal "staged when not booted" +fi +echo "ok upgrade failed when staged" + ${CMD_PREFIX} ostree --repo=sysroot/ostree/repo remote add --set=gpg-verify=false testos file://$(pwd)/testos-repo testos/buildmaster/x86_64-runtime ${CMD_PREFIX} ostree admin upgrade --os=testos origrev=${rev} diff --git a/tests/installed/destructive-ansible.yml b/tests/installed/destructive-ansible.yml index a0e69aa1..c72f6b82 100644 --- a/tests/installed/destructive-ansible.yml +++ b/tests/installed/destructive-ansible.yml @@ -9,10 +9,7 @@ tests: "." tasks: - import_tasks: tasks/disable-all-rpmmd-repos.yml - - import_tasks: tasks/query-host.yml - - set_fact: - rpmostree_initial_deployment: "{{ rpmostree_status[\"deployments\"][0] }}" - import_tasks: tasks/install-git.yml when: use_git_build - + - import_tasks: tasks/query-host.yml - import_tasks: destructive/staged-deploy.yml diff --git a/tests/installed/destructive/staged-deploy.yml b/tests/installed/destructive/staged-deploy.yml index 723dbf55..f34550a2 100644 --- a/tests/installed/destructive/staged-deploy.yml +++ b/tests/installed/destructive/staged-deploy.yml @@ -27,16 +27,31 @@ - name: Check that deploy-staged service worked shell: | set -xeuo pipefail + rpm-ostree status # Assert that the previous boot had a journal entry for it journalctl -b "-1" -u ostree-finalize-staged.service | grep -q -e 'Transaction complete' # And there should not be a staged deployment test '!' -f /run/ostree/staged-deployment -- name: Rollback - shell: rpm-ostree rollback -- include_tasks: ../tasks/reboot.yml -- shell: | + +- name: Upgrade with staging + shell: | set -xeuo pipefail + test '!' -f /run/ostree/staged-deployment + ostree admin deploy --stage staged-deploy + test -f /run/ostree/staged-deployment + origcommit=$(ostree rev-parse staged-deploy) + cd /ostree/repo/tmp + ostree checkout -H "${origcommit}" t + ostree commit --no-bindings --parent="${origcommit}" -b staged-deploy -I --consume t + newcommit=$(ostree rev-parse staged-deploy) + env OSTREE_EX_STAGE_DEPLOYMENTS=1 ostree admin upgrade >out.txt + test -f /run/ostree/staged-deployment + # Debating bouncing back out to Ansible for this + firstdeploycommit=$(rpm-ostree status |grep 'Commit:' |head -1|sed -e 's,^ *Commit: *,,') + test "${firstdeploycommit}" = "${newcommit}" + # Cleanup rpm-ostree cleanup -rp +- import_tasks: ../tasks/query-host.yml # Ensure we can unstage - name: Write staged-deploy commit, then unstage @@ -50,8 +65,6 @@ ostree admin status > status.txt grep -vqFe '(staged)' status.txt test '!' -f /run/ostree/staged-deployment - environment: - commit: "{{ rpmostree_status['deployments'][0]['checksum'] }}" - name: Staged should be overwritten by non-staged shell: | diff --git a/tests/installed/tasks/install-git.yml b/tests/installed/tasks/install-git.yml index 33fe385e..8216afeb 100644 --- a/tests/installed/tasks/install-git.yml +++ b/tests/installed/tasks/install-git.yml @@ -8,7 +8,8 @@ synchronize: src=build/x86_64/ dest=/root/x86_64/ archive=yes - name: Install RPMs shell: rpm-ostree override replace /root/x86_64/*.rpm -- include_tasks: ../tasks/reboot.yml +- import_tasks: ../tasks/reboot.yml +- import_tasks: ../tasks/query-host.yml - command: ostree --version register: ostree_new_version - set_fact: diff --git a/tests/installed/tasks/query-host.yml b/tests/installed/tasks/query-host.yml index 2a67dbdf..d572ae64 100644 --- a/tests/installed/tasks/query-host.yml +++ b/tests/installed/tasks/query-host.yml @@ -1,4 +1,5 @@ -- command: rpm-ostree status --json +- name: Load status json + command: rpm-ostree status --json changed_when: False register: rpmostree_status_json - set_fact: