Skip to content

Commit

Permalink
Add fixture modifying grub config
Browse files Browse the repository at this point in the history
* some systems are unable to boot to an older kernel due to missing
  setting in the grub config
* add a fixture fixing this

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway committed May 29, 2024
1 parent 8fad490 commit a8eced6
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,53 @@ def _create_old_repo(distro: str, repo_name: str):
f.write("gpgcheck=0\n")


@pytest.fixture()
def grub_kernel_settings(backup_directory, shell):
"""
Fixture.
Set the grub config to be able to boot to different kernel.
"""
grub_config = "/etc/default/grub"
grub_default_opt = "GRUB_DEFAULT"
grub_savedefault_opt = "GRUB_SAVEDEFAULT"
grub_default = f"{grub_default_opt}=saved"
grub_savedefault = f"{grub_savedefault_opt}=true"

# Read the current content of the grub config
with open(grub_config, "r") as file:
lines = file.readlines()
print(lines)

print(lines)

# Initialize flags to track if we need to add the settings
grub_default_set = False
grub_savedefault_set = False

# Modify the lines if the options are present
for i, line in enumerate(lines):
if line.startswith(grub_default_opt):
lines[i] = grub_default + "\n"
grub_default_set = True
if line.startswith(grub_savedefault_opt):
lines[i] = grub_savedefault + "\n"
grub_savedefault_set = True

# Append the options if they are not present
if not grub_default_set:
lines.append(f"\n{grub_default}\n")
if not grub_savedefault_set:
lines.append(f"\n{grub_savedefault}\n")

# Write the modified content back to the grub config
with open(grub_config, "w") as file:
file.writelines(lines)

yield


@pytest.fixture(scope="function")
def kernel(shell):
def kernel(shell, grub_kernel_settings):
"""
Install specific kernel version and configure
the system to boot to it. The kernel version is not the
Expand Down

0 comments on commit a8eced6

Please sign in to comment.