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

Adding check if secureboot is enabled or not #5929

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion avocado/utils/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@

import os

from avocado.utils import genio
from avocado.utils import genio, process


class UnsupportedMachineError(Exception):
"""
Exception class for unsupported hardware
"""


def get_proc_sys(key):
Expand Down Expand Up @@ -72,3 +78,21 @@ def enable_selinux_enforcing():
if is_selinux_enforcing():
return True
return False


def is_os_secureboot_enabled():
"""
Check whether the secure-boot is enabled at os level.
Check for "00000002" in "/proc/device-tree/ibm,secure-boot" file
If found, then secure-boot is enabled.

:return: True if secureboot is enabled, False if otherwise
"""
try:
cmd = "lsprop /proc/device-tree/ibm,secure-boot"
for line in process.system_output(cmd).decode("utf-8").splitlines():
if "00000002" in line:
return True
except FileNotFoundError:
raise UnsupportedMachineError("lsprop not a supported command")
return False
Loading