From d82e16c853a78667c4fa8b3dba02547bf0d3c442 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 21 Apr 2020 19:25:40 +0000 Subject: [PATCH] deploy: Add --no-merge All of the underlying libostree APIs have supported passing `NULL` for a merge deployment for...a long time. But we never plumbed it up into the CLI. Add a `--no-merge` option to aid people who want to do a "factory reset": https://github.com/ostreedev/ostree/issues/1793 --- src/ostree/ot-admin-builtin-deploy.c | 4 +++- tests/admin-test.sh | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c index c1c3353de0..bcece3f655 100644 --- a/src/ostree/ot-admin-builtin-deploy.c +++ b/src/ostree/ot-admin-builtin-deploy.c @@ -37,6 +37,7 @@ static gboolean opt_retain_pending; static gboolean opt_retain_rollback; static gboolean opt_not_as_default; static gboolean opt_no_prune; +static gboolean opt_no_merge; static char **opt_kernel_argv; static char **opt_kernel_argv_append; static gboolean opt_kernel_proc_cmdline; @@ -48,6 +49,7 @@ static GOptionEntry options[] = { { "os", 0, 0, G_OPTION_ARG_STRING, &opt_osname, "Use a different operating system root than the current one", "OSNAME" }, { "origin-file", 0, 0, G_OPTION_ARG_FILENAME, &opt_origin_path, "Specify origin file", "FILENAME" }, { "no-prune", 0, 0, G_OPTION_ARG_NONE, &opt_no_prune, "Don't prune the repo when done", NULL}, + { "no-merge", 0, 0, G_OPTION_ARG_NONE, &opt_no_merge, "Do not apply configuration (/etc and kernel arguments) from booted deployment", NULL}, { "retain", 0, 0, G_OPTION_ARG_NONE, &opt_retain, "Do not delete previous deployments", NULL }, { "stage", 0, 0, G_OPTION_ARG_NONE, &opt_stage, "Complete deployment at OS shutdown", NULL }, { "retain-pending", 0, 0, G_OPTION_ARG_NONE, &opt_retain_pending, "Do not delete pending deployments", NULL }, @@ -113,7 +115,7 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeCommandInvocation *invocat return FALSE; g_autoptr(OstreeDeployment) merge_deployment = - ostree_sysroot_get_merge_deployment (sysroot, opt_osname); + opt_no_merge ? NULL : ostree_sysroot_get_merge_deployment (sysroot, opt_osname); /* Here we perform cleanup of any leftover data from previous * partial failures. This avoids having to call diff --git a/tests/admin-test.sh b/tests/admin-test.sh index 11b9ea1481..4dca176a15 100644 --- a/tests/admin-test.sh +++ b/tests/admin-test.sh @@ -21,7 +21,7 @@ set -euo pipefail -echo "1..$((27 + ${extra_admin_tests:-0}))" +echo "1..$((28 + ${extra_admin_tests:-0}))" mkdir sysrootmin ${CMD_PREFIX} ostree admin init-fs --modern sysrootmin @@ -352,3 +352,21 @@ fi assert_file_has_content err.txt "fifreeze watchdog was run" assert_file_has_content err.txt "During fsfreeze-thaw: aborting due to test-fifreeze" echo "ok fifreeze test" + +# Test that we can deploy with a pristine /etc and exactly one kernel argument. +# First, reset all state. +for x in $(seq 4); do + ostree admin undeploy 0 +done +${CMD_PREFIX} ostree admin deploy --os=testos --karg=root=LABEL=foo --karg=testkarg=1 testos:testos/buildmaster/x86_64-runtime +origdeployment=$(${CMD_PREFIX} ostree admin --sysroot=sysroot --print-current-dir) +testconfig=etc/modified-config-file-that-will-be-removed +touch "${origdeployment}"/"${testconfig}" +assert_file_has_content sysroot/boot/loader/entries/ostree-1-testos.conf "^options.*root=LABEL=foo.*testkarg" +${CMD_PREFIX} ostree admin deploy --os=testos --no-merge --karg=root=LABEL=bar testos:testos/buildmaster/x86_64-runtime +deployment=$(${CMD_PREFIX} ostree admin --sysroot=sysroot --print-current-dir) +assert_not_streq "${origdeployment}" "${deployment}" +assert_not_has_file "${deployment}/${testconfig}" +assert_file_has_content sysroot/boot/loader/entries/ostree-1-testos.conf "^options root=LABEL=bar" +assert_not_file_has_content sysroot/boot/loader/entries/ostree-1-testos.conf "^options .*testkarg" +echo "ok no merge deployment"