|
@ -1,5 +1,5 @@ |
|
|
#!/usr/bin/python |
|
|
#!/usr/bin/python |
|
|
# Copyright 2022 Northern.tech AS |
|
|
# Copyright 2023 Northern.tech AS |
|
|
# |
|
|
# |
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
# you may not use this file except in compliance with the License. |
|
|
# you may not use this file except in compliance with the License. |
|
@ -21,6 +21,7 @@ import subprocess |
|
|
from utils.common import ( |
|
|
from utils.common import ( |
|
|
extract_partition, |
|
|
extract_partition, |
|
|
get_no_sftp, |
|
|
get_no_sftp, |
|
|
|
|
|
make_tempdir, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -93,57 +94,40 @@ class TestGrubIntegration: |
|
|
partition.""" |
|
|
partition.""" |
|
|
|
|
|
|
|
|
# First, check that the offline generated scripts don't have any. |
|
|
# First, check that the offline generated scripts don't have any. |
|
|
extract_partition(latest_part_image, 1) |
|
|
with make_tempdir() as tmpdir: |
|
|
try: |
|
|
extract_partition(latest_part_image, 1, tmpdir) |
|
|
subprocess.check_call( |
|
|
subprocess.check_call( |
|
|
["mcopy", "-i", "img1.fs", "::/grub-mender-grubenv/grub.cfg", "."] |
|
|
["mcopy", "-i", f"{tmpdir}/img1.fs", "::/grub-mender-grubenv/grub.cfg", tmpdir] |
|
|
) |
|
|
) |
|
|
check_all_root_occurrences_valid("grub.cfg") |
|
|
check_all_root_occurrences_valid(f"{tmpdir}/grub.cfg") |
|
|
finally: |
|
|
|
|
|
os.remove("img1.fs") |
|
|
|
|
|
os.remove("grub.cfg") |
|
|
|
|
|
|
|
|
|
|
|
extract_partition(latest_part_image, 2) |
|
|
extract_partition(latest_part_image, 2, tmpdir) |
|
|
try: |
|
|
|
|
|
subprocess.check_call( |
|
|
subprocess.check_call( |
|
|
[ |
|
|
[ |
|
|
"debugfs", |
|
|
"debugfs", |
|
|
"-R", |
|
|
"-R", |
|
|
"dump -p /boot/grub-mender-grubenv.cfg grub-mender-grubenv.cfg", |
|
|
f"dump -p /boot/grub-mender-grubenv.cfg {tmpdir}/grub-mender-grubenv.cfg", |
|
|
"img2.fs", |
|
|
f"{tmpdir}/img2.fs", |
|
|
] |
|
|
] |
|
|
) |
|
|
) |
|
|
check_all_root_occurrences_valid("grub-mender-grubenv.cfg") |
|
|
check_all_root_occurrences_valid(f"{tmpdir}/grub-mender-grubenv.cfg") |
|
|
finally: |
|
|
|
|
|
os.remove("img2.fs") |
|
|
|
|
|
os.remove("grub-mender-grubenv.cfg") |
|
|
|
|
|
|
|
|
|
|
|
# Then, check that the runtime generated scripts don't have any. |
|
|
# Then, check that the runtime generated scripts don't have any. |
|
|
get_no_sftp("/boot/grub/grub.cfg", connection) |
|
|
with make_tempdir() as tmpdir: |
|
|
try: |
|
|
get_no_sftp("/boot/grub/grub.cfg", connection, local=tmpdir) |
|
|
check_all_root_occurrences_valid("grub.cfg") |
|
|
check_all_root_occurrences_valid(f"{tmpdir}/grub.cfg") |
|
|
finally: |
|
|
|
|
|
os.remove("grub.cfg") |
|
|
|
|
|
|
|
|
|
|
|
get_no_sftp("/boot/grub-mender-grubenv.cfg", connection) |
|
|
get_no_sftp("/boot/grub-mender-grubenv.cfg", connection, local=tmpdir) |
|
|
try: |
|
|
check_all_root_occurrences_valid(f"{tmpdir}/grub-mender-grubenv.cfg") |
|
|
check_all_root_occurrences_valid("grub-mender-grubenv.cfg") |
|
|
|
|
|
finally: |
|
|
|
|
|
os.remove("grub-mender-grubenv.cfg") |
|
|
|
|
|
|
|
|
|
|
|
# Check again after running `update-grub`. |
|
|
# Check again after running `update-grub`. |
|
|
connection.run("grub-install && update-grub") |
|
|
connection.run("grub-install && update-grub") |
|
|
get_no_sftp("/boot/grub/grub.cfg", connection) |
|
|
with make_tempdir() as tmpdir: |
|
|
try: |
|
|
get_no_sftp("/boot/grub/grub.cfg", connection, local=tmpdir) |
|
|
check_all_root_occurrences_valid("grub.cfg") |
|
|
check_all_root_occurrences_valid(f"{tmpdir}/grub.cfg") |
|
|
finally: |
|
|
|
|
|
os.remove("grub.cfg") |
|
|
|
|
|
|
|
|
|
|
|
get_no_sftp("/boot/grub-mender-grubenv.cfg", connection) |
|
|
get_no_sftp("/boot/grub-mender-grubenv.cfg", connection, local=tmpdir) |
|
|
try: |
|
|
check_all_root_occurrences_valid(f"{tmpdir}/grub-mender-grubenv.cfg") |
|
|
check_all_root_occurrences_valid("grub-mender-grubenv.cfg") |
|
|
|
|
|
finally: |
|
|
|
|
|
os.remove("grub-mender-grubenv.cfg") |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.min_mender_version("1.0.0") |
|
|
@pytest.mark.min_mender_version("1.0.0") |
|
|
def test_offline_and_runtime_boot_scripts_identical(self, connection): |
|
|
def test_offline_and_runtime_boot_scripts_identical(self, connection): |
|
@ -172,13 +156,16 @@ class TestGrubIntegration: |
|
|
# * `root` variable is not set in offline copy. |
|
|
# * `root` variable is not set in offline copy. |
|
|
# * `fwsetup` is added somewhat randomly depending on availability both |
|
|
# * `fwsetup` is added somewhat randomly depending on availability both |
|
|
# on build host and device. |
|
|
# on build host and device. |
|
|
|
|
|
# * locale, lang and gettext settings and module may or may not be |
|
|
|
|
|
# present depending on test host. |
|
|
try: |
|
|
try: |
|
|
connection.run("cp /data/grub-main.cfg /data/old-grub-modified.cfg") |
|
|
connection.run("cp /data/grub-main.cfg /data/old-grub-modified.cfg") |
|
|
connection.run("cp /boot/grub/grub.cfg /data/new-grub-modified.cfg") |
|
|
connection.run("cp /boot/grub/grub.cfg /data/new-grub-modified.cfg") |
|
|
connection.run( |
|
|
connection.run( |
|
|
r"sed -i -En -e '/\bsearch\b/{s/ --hint[^ ]*//g;}' " |
|
|
r"sed -i -En -e '/\bsearch\b/{s/ --hint[^ ]*//g;}' " |
|
|
"-e \"/^set root='hd0,gpt1'$/d\" " |
|
|
"-e \"/^set root='hd0,gpt1'$/d\" " |
|
|
r"-e '\,### BEGIN /etc/grub.d/30_uefi-firmware ###,{p; n; :loop; \,### END /etc/grub.d/30_uefi-firmware ###,b end; n; b loop; :end;}' " |
|
|
r"-e '\,### BEGIN /etc/grub.d/30_uefi-firmware ###,{p; n; :uefi_loop; \,### END /etc/grub.d/30_uefi-firmware ###,b uefi_end; n; b uefi_loop; :uefi_end;}' " |
|
|
|
|
|
r"-e ':locale_loop; /^\s*(set (locale_dir|lang)=|insmod gettext)/{n; b locale_loop;}' " |
|
|
"-e p " |
|
|
"-e p " |
|
|
"/data/old-grub-modified.cfg /data/new-grub-modified.cfg" |
|
|
"/data/old-grub-modified.cfg /data/new-grub-modified.cfg" |
|
|
) |
|
|
) |
|
@ -193,7 +180,8 @@ class TestGrubIntegration: |
|
|
connection.run( |
|
|
connection.run( |
|
|
r"sed -i -En -e '/\bsearch\b/{s/ --hint[^ ]*//g;}' " |
|
|
r"sed -i -En -e '/\bsearch\b/{s/ --hint[^ ]*//g;}' " |
|
|
"-e \"/^set root='hd0,gpt1'$/d\" " |
|
|
"-e \"/^set root='hd0,gpt1'$/d\" " |
|
|
r"-e '\,### BEGIN /etc/grub.d/30_uefi-firmware ###,{p; n; :loop; \,### END /etc/grub.d/30_uefi-firmware ###,b end; n; b loop; :end;}' " |
|
|
r"-e '\,### BEGIN /etc/grub.d/30_uefi-firmware ###,{p; n; :uefi_loop; \,### END /etc/grub.d/30_uefi-firmware ###,b uefi_end; n; b uefi_loop; :uefi_end;}' " |
|
|
|
|
|
r"-e ':locale_loop; /^\s*(set (locale_dir|lang)=|insmod gettext)/{n; b locale_loop;}' " |
|
|
"-e p " |
|
|
"-e p " |
|
|
"/data/old-grub-mender-grubenv-modified.cfg /data/new-grub-mender-grubenv-modified.cfg" |
|
|
"/data/old-grub-mender-grubenv-modified.cfg /data/new-grub-mender-grubenv-modified.cfg" |
|
|
) |
|
|
) |
|
|