After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761180 - Test suite doesn't cover grub2; grub2-mkconfig requires root
Test suite doesn't cover grub2; grub2-mkconfig requires root
Status: RESOLVED WONTFIX
Product: ostree
Classification: Infrastructure
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: OSTree maintainer(s)
OSTree maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2016-01-27 14:44 UTC by Gatis Paeglis
Modified: 2018-08-17 19:00 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Gatis Paeglis 2016-01-27 14:44:07 UTC
Steps to reproduce:

1) Apply the following 2 line patch to the ostree/tests/libtest.sh file.

         "uboot")
            setup_os_boot_uboot
             ;;
+        "grub2")
+            mkdir -p sysroot/boot/grub2/
+            touch sysroot/boot/grub2/grub.cfg
+            ;;
     esac
     

2) Run test-admin-deploy-grub2.sh

Expected outcome:

Sysroot with generated grub.cfg fike

Actual outcome:

ERROR:src/libostree/ostree-bootloader-grub2.c:312:_ostree_bootloader_grub2_write_config: assertion failed (deployments->len > 0): (0 > 0)
../admin-test.sh: line 34: 30249 Aborted                 (core dumped) ${CMD_PREFIX} ostree admin deploy --karg=root=LABEL=MOO --karg=quiet --os=testos testos:testos/buildmaster/x86_64-runtime
Comment 1 Colin Walters 2016-01-31 20:20:17 UTC
So here's the problem:

```
$ grub2-mkconfig 
grub2-mkconfig: You must run this as root
```

And I don't want to require running the test suite as root.  grub2-mkconfig is particularly insane as it scans all the block devices.

We could try to mock it though so at least there's some coverage.
Comment 2 Colin Walters 2016-01-31 20:28:57 UTC
WIP patch to pick up later:

diff --git a/Makefile-tests.am b/Makefile-tests.am
index 9f3feef..b18de38 100644
--- a/Makefile-tests.am
+++ b/Makefile-tests.am
@@ -47,6 +47,7 @@ testfiles = test-basic \
 	test-admin-deploy-switch \
 	test-admin-deploy-etcmerge-cornercases \
 	test-admin-deploy-uboot \
+	test-admin-deploy-grub2 \
 	test-admin-instutil-set-kargs \
 	test-admin-upgrade-not-backwards \
 	test-admin-pull-deploy-commit \
diff --git a/src/libostree/ostree-bootloader-grub2.c b/src/libostree/ostree-bootloader-grub2.c
index 42ed5ac..5e79292 100644
--- a/src/libostree/ostree-bootloader-grub2.c
+++ b/src/libostree/ostree-bootloader-grub2.c
@@ -300,8 +300,19 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader      *bootloader,
   g_autoptr(GFile) config_path_efi_dir = NULL;
   g_autofree char *grub2_mkconfig_chroot = NULL;
 
+  /* Sadly we have to execute code to generate the bootloader configuration.
+   * If we're in a booted deployment, we just don't chroot.
+   *
+   * In the case of an installer, use the first deployment root (which
+   * will most likely be the only one.
+   *
+   * However, we skip this if OSTREE_TEST_GRUB2 is set; for the test suite
+   * we'll run grub2-mkconfig from the host, which is potentially a bad
+   * idea, but at least it's as non-root...
+   */
   if (ostree_sysroot_get_booted_deployment (self->sysroot) == NULL
-      && g_file_has_parent (self->sysroot->path, NULL))
+      && g_file_has_parent (self->sysroot->path, NULL)
+      && g_getenv ("OSTREE_TEST_GRUB2") == NULL)
     {
       g_autoptr(GPtrArray) deployments = NULL;
       OstreeDeployment *tool_deployment;
@@ -313,12 +324,6 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader      *bootloader,
 
       tool_deployment = deployments->pdata[0];
 
-      /* Sadly we have to execute code to generate the bootloader configuration.
-       * If we're in a booted deployment, we just don't chroot.
-       *
-       * In the case of an installer, use the first deployment root (which
-       * will most likely be the only one.
-       */
       tool_deployment_root = ostree_sysroot_get_deployment_directory (self->sysroot, tool_deployment);
       grub2_mkconfig_chroot = g_file_get_path (tool_deployment_root);
     }
diff --git a/tests/libtest.sh b/tests/libtest.sh
index bd806f6..bc2dc74 100644
--- a/tests/libtest.sh
+++ b/tests/libtest.sh
@@ -266,6 +266,10 @@ EOF
         "uboot")
 	    setup_os_boot_uboot
             ;;
+	"grub2")
+            mkdir -p sysroot/boot/grub2/
+            touch sysroot/boot/grub2/grub.cfg
+            ;;
     esac
     
     cd ${test_tmpdir}
diff --git a/tests/test-admin-deploy-grub2.sh b/tests/test-admin-deploy-grub2.sh
index 8da294d..c16fb1e 100755
--- a/tests/test-admin-deploy-grub2.sh
+++ b/tests/test-admin-deploy-grub2.sh
@@ -23,6 +23,9 @@ set -euo pipefail
 
 echo "1..1"
 
+# See comment in ostree-bootloader-grub2.c
+export OSTREE_TEST_GRUB2=1
+
 # Exports OSTREE_SYSROOT so --sysroot not needed.
 setup_os_repository "archive-z2" "grub2"
Comment 3 Gatis Paeglis 2016-02-02 14:13:41 UTC
> So here's the problem:
>
>```
>$ grub2-mkconfig 
>grub2-mkconfig: You must run this as root
>```

I don't see how this is related to the assert. Assert happens in the beginning of the _ostree_bootloader_grub2_write_config function and the grub2-mkconfig call is never reached because it is lower in the same function.
Comment 4 Colin Walters 2016-02-02 15:10:18 UTC
(In reply to gatis.paeglis@theqtcompany.com from comment #3)

> I don't see how this is related to the assert. Assert happens in the
> beginning of the _ostree_bootloader_grub2_write_config function and the
> grub2-mkconfig call is never reached because it is lower in the same
> function.

The first hunk of my patch "fixes" the assertion, but as above we need more work to sanely run grub2-mkconfig as non-root in the test suite.
Comment 5 André Klapper 2018-08-17 19:00:31 UTC
OSTree has moved to Github a while ago.
Furthermore, GNOME Bugzilla will be shut down and replaced by gitlab.gnome.org.

If the problem reported in this Bugzilla ticket is still valid, please report it to https://github.com/ostreedev/ostree/issues instead. Thank you!

Closing this report as WONTFIX as part of Bugzilla Housekeeping.