From 5a68cecb3a9da8edc4ebca15fe62345aa5c756d4 Mon Sep 17 00:00:00 2001 From: Kristian Amlie Date: Fri, 24 Feb 2023 14:34:03 +0100 Subject: [PATCH] test: Ignore some grub.cfg differences in `00_header` section. Ubuntu 22.04 Jammy can trigger differences in searching for the root device when running live as opposed to mender-convert's jailroot. Since we have grub scripts which later set root back to the value it should be, it is safe to ignore these differences. However, since it is dangerous to ignore these differences *outside* `00_header`, make the sed script fairly specific so that it is only ignored inside this section. Ticket: QA-554 Signed-off-by: Kristian Amlie --- tests/test_grub_integration.py | 68 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/tests/test_grub_integration.py b/tests/test_grub_integration.py index 22eef00..57d6831 100644 --- a/tests/test_grub_integration.py +++ b/tests/test_grub_integration.py @@ -152,12 +152,22 @@ class TestGrubIntegration: connection.run("rm -f /data/new-grub-efi-modified.cfg") # Another few differences we work around in the main grub files: + # # * `--hint` parameters are not generated in offline copy. + # # * `root` variable is not set in offline copy. + # # * `fwsetup` is added somewhat randomly depending on availability both # on build host and device. + # # * locale, lang and gettext settings and module may or may not be # present depending on test host. + # + # * Inside the `00_header` section, ignore the `search` functions which + # set the root variable. This is safe because we have a later script + # which sets the root again (`07_mender_choose_partitions_grub.cfg` at + # the time of writing). These are sometimes inside an if condition + # using `feature_platform_search_hint`, which we also need to ignore. try: connection.run("cp /data/grub-main.cfg /data/old-grub-modified.cfg") connection.run("cp /boot/grub/grub.cfg /data/new-grub-modified.cfg") @@ -169,7 +179,36 @@ class TestGrubIntegration: "-e p " "/data/old-grub-modified.cfg /data/new-grub-modified.cfg" ) - connection.run("diff -u /data/old-grub-modified.cfg /data/new-grub-modified.cfg") + connection.run( + "sed -i -En -e '" + r""" +\%BEGIN /etc/grub.d/00_header% { + :header_loop; + /if .*feature_platform_search_hint/ { + :hint_loop; + /^ *fi *$/ ! { + n; + b hint_loop; + }; + n; + }; + /^ *search .*--set=root/ { + n; + b header_loop; + }; + \%END /etc/grub.d/00_header% ! { + p; + n; + b header_loop; + }; +}; +p; +' """ + "/data/old-grub-modified.cfg /data/new-grub-modified.cfg" + ) + connection.run( + "diff -u /data/old-grub-modified.cfg /data/new-grub-modified.cfg" + ) finally: connection.run("rm -f /data/old-grub-modified.cfg /data/new-grub-modified.cfg") @@ -185,6 +224,33 @@ class TestGrubIntegration: "-e p " "/data/old-grub-mender-grubenv-modified.cfg /data/new-grub-mender-grubenv-modified.cfg" ) + connection.run( + "sed -i -En -e '" + r""" +\%BEGIN /etc/grub.d/00_header% { + :header_loop; + /if .*feature_platform_search_hint/ { + :hint_loop; + /^ *fi *$/ ! { + n; + b hint_loop; + }; + n; + }; + /^ *search .*--set=root/ { + n; + b header_loop; + }; + \%END /etc/grub.d/00_header% ! { + p; + n; + b header_loop; + }; +}; +p; +' """ + "/data/old-grub-mender-grubenv-modified.cfg /data/new-grub-mender-grubenv-modified.cfg" + ) connection.run( "diff -u /data/old-grub-mender-grubenv-modified.cfg /data/new-grub-mender-grubenv-modified.cfg" )