Skip to content

Commit

Permalink
lib/deploy: Add flag ostree-kargs-override to bootconfig
Browse files Browse the repository at this point in the history
Add an ostree-kargs-override flag which is set to true if the
kargs of the current deployment were overridden. The flag is
written to the bootconfig, and persists in subsequent deployments.

This is in preparation for ostreedev#1836 which needs a way to determine
whether the previous deployment's kargs were modified by the user,
so that user-modified kargs can be carried forward to the next
deployment.
  • Loading branch information
Robert Fairley committed Apr 11, 2019
1 parent da57956 commit 65fe4e9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
26 changes: 18 additions & 8 deletions src/libostree/ostree-sysroot-deploy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,7 @@ _ostree_deployment_set_bootconfig_from_kargs (OstreeDeployment *deployment,
_ostree_kernel_args_append_argv (kargs, override_kernel_argv);
g_autofree char *new_options = _ostree_kernel_args_to_string (kargs);
ostree_bootconfig_parser_set (bootconfig, "options", new_options);
ostree_bootconfig_parser_set (bootconfig, "ostree-kargs-override", "true");
}
}

Expand Down Expand Up @@ -2580,17 +2581,26 @@ sysroot_finalize_deployment (OstreeSysroot *self,
if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &deployment_dfd, error))
return FALSE;

/* Only use the merge if we didn't get an override */
if (!override_kernel_argv && merge_deployment)
/* If we didn't get an override in this deployment, copy kargs directly from
* the merge deployment. */
if (!override_kernel_argv)
{
/* Override the bootloader arguments */
OstreeBootconfigParser *merge_bootconfig = ostree_deployment_get_bootconfig (merge_deployment);
if (merge_bootconfig)
OstreeBootconfigParser *merge_bootconfig = NULL;
gboolean kargs_overridden = FALSE;
if (merge_deployment)
{
const char *opts = ostree_bootconfig_parser_get (merge_bootconfig, "options");
ostree_bootconfig_parser_set (ostree_deployment_get_bootconfig (deployment), "options", opts);
merge_bootconfig = ostree_deployment_get_bootconfig (merge_deployment);
if (merge_bootconfig)
{
/* Copy kargs from the merge deployment. */
const char *opts = ostree_bootconfig_parser_get (merge_bootconfig, "options");
ostree_bootconfig_parser_set (ostree_deployment_get_bootconfig (deployment), "options", opts);
kargs_overridden = g_strcmp0 (ostree_bootconfig_parser_get (merge_bootconfig, "ostree-kargs-override"),
"true") == 0;
}
if (kargs_overridden)
ostree_bootconfig_parser_set (ostree_deployment_get_bootconfig (deployment), "ostree-kargs-override", "true");
}

}

if (merge_deployment)
Expand Down
33 changes: 31 additions & 2 deletions tests/test-admin-deploy-karg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set -euo pipefail
# Exports OSTREE_SYSROOT so --sysroot not needed.
setup_os_repository "archive" "syslinux"

echo "1..3"
echo "1..7"

${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmaster/x86_64-runtime
rev=$(${CMD_PREFIX} ostree --repo=sysroot/ostree/repo rev-parse testos/buildmaster/x86_64-runtime)
Expand Down Expand Up @@ -61,9 +61,38 @@ echo "ok deploy --karg-proc-cmdline"
${CMD_PREFIX} ostree admin status
${CMD_PREFIX} ostree admin undeploy 0

${CMD_PREFIX} ostree admin deploy --os=testos --karg-append=APPENDARG=VALAPPEND --karg-append=APPENDARG=2NDAPPEND testos:testos/buildmaster/x86_64-runtime
${CMD_PREFIX} ostree admin deploy --os=testos --karg-append=APPENDARG=VALAPPEND --karg-append=APPENDARG=2NDAPPEND testos:testos/buildmaster/x86_64-runtime
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*FOO=BAR'
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*TESTARG=TESTVALUE'
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'options.*APPENDARG=VALAPPEND .*APPENDARG=2NDAPPEND'

echo "ok deploy --karg-append"

${CMD_PREFIX} ostree admin status
${CMD_PREFIX} ostree admin undeploy 0

${CMD_PREFIX} ostree admin deploy --os=testos --karg-append=APPENDARG=VALAPPEND --karg-append=APPENDARG=2NDAPPEND testos:testos/buildmaster/x86_64-runtime
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'ostree-kargs-override.*true'

echo "ok kargs override flag"

${CMD_PREFIX} ostree admin deploy --os=testos testos:testos/buildmaster/x86_64-runtime
assert_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'ostree-kargs-override.*true'

echo "ok kargs override flag persists"

${CMD_PREFIX} ostree admin status
# Clear both previous deployments, to start with clean bootconfig.
${CMD_PREFIX} ostree admin undeploy 1
${CMD_PREFIX} ostree admin undeploy 0

# Create an extra deployment to use as the merge deployment.
${CMD_PREFIX} ostree admin deploy --os=testos testos:testos/buildmaster/x86_64-runtime
assert_not_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'ostree-kargs-override'

echo "ok no kargs override flag"

${CMD_PREFIX} ostree admin deploy --os=testos testos:testos/buildmaster/x86_64-runtime
assert_not_file_has_content sysroot/boot/loader/entries/ostree-2-testos.conf 'ostree-kargs-override'

echo "ok no kargs override flag persists"

0 comments on commit 65fe4e9

Please sign in to comment.