Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grub2: Generate config from pending deployment #1831

Conversation

rfairley
Copy link
Member

Attempt at a fix for #1774. Previously pushed these changes (see #1774 (comment)) - posting a PR so we can discuss here.

Involves an interface change to add the new_deployments argument to each bootloader *_write_config function. It'd be preferable to avoid passing down the extra argument - but this seems to be what's needed to expose the pending deployment to the bootloader functions.

Need to verify that the tests work (recently updated my dev environment and tests that previously passed are failing locally).

Copy link
Member

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is going wrong in PAPR I think, but let's get the tests passing. Otherwise besides one minor nit, LGTM!

src/libostree/ostree-bootloader-grub2.c Outdated Show resolved Hide resolved
@rfairley
Copy link
Member Author

Taking a look at the failing CI test, thanks!

Robert Fairley added 2 commits April 2, 2019 16:20
Split the creation of the directory containing grub.cfg, and the creation
of the file, so that a failure in the mkdir command will fail the test
and not attempt the touch command.
@rfairley rfairley force-pushed the rfairley-generate-config-pending-deployment branch 2 times, most recently from 16df565 to 5fd06d6 Compare April 3, 2019 17:07
@rfairley rfairley changed the title grub2: Generate config from pending deployment WIP: grub2: Generate config from pending deployment Apr 3, 2019
@rfairley rfairley force-pushed the rfairley-generate-config-pending-deployment branch from 98b47c4 to 5fd06d6 Compare April 3, 2019 17:27
@rfairley
Copy link
Member Author

rfairley commented Apr 3, 2019

Reworked the test so that it exercises the grub2-mkconfig path where the assertion failed in #1774. To test the grub2-mkconfig code path, I did export OSTREE_GRUB2_EXEC=grub2-mkconfig in the test script.

However, the test runs into error: Bootloader write config: grub2-mkconfig: Child process exited with code 1. Running sudo make check TESTS=tests/test-admin-deploy-grub2.sh on my machine gives a different result: error: Bootloader write config: Failed to execute child process “grub2-mkconfig” (No such file or directory). Applying the following patch allowed the test to pass with sudo on my machine (I think this makes the grub2-mkconfig binary on my host visible to the test):

diff --git a/src/libostree/ostree-bootloader-grub2.c b/src/libostree/ostree-bootloader-grub2.c
index 1e5791d65..7feba43a2 100644
--- a/src/libostree/ostree-bootloader-grub2.c
+++ b/src/libostree/ostree-bootloader-grub2.c
@@ -321,7 +321,7 @@ grub2_child_setup (gpointer user_data)
       _exit (1);
     }
 
-  if (chroot (".") != 0)
+  if (chroot ("/") != 0)
     {
       perror ("chroot");
       _exit (1);

Manually testing in Fedora Atomic Host 29 with mkdir sysroot && ostree admin init-fs sysroot && ostree pull-local --repo=sysroot/ostree/repo /sysroot/ostree/repo rpmostree/base/0 && ostree admin os-init osname --sysroot sysroot && ref=$(ostree refs --repo sysroot/ostree/repo) && mkdir -p sysroot/boot/grub2 && touch sysroot/boot/grub2/grub.cfg && ostree admin deploy "$ref" --sysroot sysroot --os osname -v 2>err.txt, the deploy is successful with:

Transaction complete; bootconfig swap: yes; deployment count change: 1

(previously the above command hit the assertion in #1774).

The tests in tests/admin-test.sh also pass.

To have the test run grub2-mkconfig without sudo and without the patch above, could bwrap be used for this? (seeing this comment

/* TODO: investigate replacing this with bwrap */
). Thinking it would work by binding in a grub2-mkconfig installed on the host running the test.

Considering manually testing the changes here works though, would the libostree changes be OK to merge and then the automated test can be dealt with separately?

Also see there is some history here: https://bugzilla.gnome.org/show_bug.cgi?id=761180

@rfairley rfairley force-pushed the rfairley-generate-config-pending-deployment branch from 5fd06d6 to f037b5e Compare April 17, 2019 15:41
@rfairley
Copy link
Member Author

For now I just removed the auto test - as it seems the grub2-mkconfig binary would need to be present in order to test the code path changed here (to make sure the assertion doesn't fail). Not sure of a way to run this in the test suite (needed the hacks 1) the patch in this comment, and 2) run the test suite as sudo, to get it to work on my machine).

This is the test trying to exercise grub2-mkconfig - in case we come back to this:

diff --git a/tests/test-admin-deploy-grub2.sh b/tests/test-admin-deploy-grub2.sh
index 231aa2f8..f3e2180a 100755
--- a/tests/test-admin-deploy-grub2.sh
+++ b/tests/test-admin-deploy-grub2.sh
@@ -26,6 +26,21 @@ set -euo pipefail
 # Exports OSTREE_SYSROOT so --sysroot not needed.
 setup_os_repository "archive" "grub2 ostree-grub-generator"
 
-extra_admin_tests=0
+extra_admin_tests=1
 
 . $(dirname $0)/admin-test.sh
+
+# Check that deploying a new tree with zero previous deployments works.
+# (see https://github.com/ostreedev/ostree/issues/1774).
+cd ${test_tmpdir}
+rm httpd osdata testos-repo sysroot -rf
+setup_os_repository "archive" "grub2"
+# Exercise the system grub2-mkconfig codepath.
+export OSTREE_GRUB2_EXEC=grub2-mkconfig
+${CMD_PREFIX} ostree pull-local --repo=sysroot/ostree/repo --remote testos testos-repo testos/buildmaster/x86_64-runtime
+${CMD_PREFIX} ostree admin deploy --karg=root=LABEL=MOO --karg=quiet --sysroot sysroot --os testos testos/buildmaster/x86_64-runtime > out.txt
+assert_file_has_content out.txt "Transaction complete.*"
+assert_file_has_content sysroot/boot/loader/entries/ostree-1-testos.conf 'options.* root=LABEL=MOO'
+assert_file_has_content sysroot/boot/ostree/testos-${bootcsum}/vmlinuz-3.6.0 'a kernel'
+assert_file_has_content sysroot/boot/ostree/testos-${bootcsum}/initramfs-3.6.0.img 'an initramfs'
+echo "ok run grub2 bootloader on first deployment"

@rfairley rfairley changed the title WIP: grub2: Generate config from pending deployment grub2: Generate config from pending deployment Apr 17, 2019
@jlebon jlebon mentioned this pull request Apr 24, 2019
Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! Just one super minor/optional nit.

src/libostree/ostree-bootloader-grub2.c Outdated Show resolved Hide resolved
Generate a grub2 config using the pending deployment, if a grub2
bootloader is detected in the sysroot. Allows grub2-mkconfig
to run if there are no previous deployments.

Fixes: ostreedev#1774
@rfairley rfairley force-pushed the rfairley-generate-config-pending-deployment branch from f037b5e to dc2f6c0 Compare April 24, 2019 20:40
@jlebon
Copy link
Member

jlebon commented Apr 24, 2019

Thanks!

@rh-atomic-bot r+ dc2f6c0

Re. tests, yeah I don't think there's an easy way to add this to the make check harness right now. Higher-level tests like f28-rpmostree would exercise this, though CI here is in need of an overhaul.

@rh-atomic-bot
Copy link

⚡ Test exempted: merge already tested.

rh-atomic-bot pushed a commit that referenced this pull request Apr 24, 2019
Split the creation of the directory containing grub.cfg, and the creation
of the file, so that a failure in the mkdir command will fail the test
and not attempt the touch command.

Closes: #1831
Approved by: jlebon
rh-atomic-bot pushed a commit that referenced this pull request Apr 24, 2019
Generate a grub2 config using the pending deployment, if a grub2
bootloader is detected in the sysroot. Allows grub2-mkconfig
to run if there are no previous deployments.

Fixes: #1774

Closes: #1831
Approved by: jlebon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants