Skip to content
Draft
10 changes: 8 additions & 2 deletions lisa/operating_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ def name_pattern(cls) -> Pattern[str]:

def __init__(self, node: Any) -> None:
super().__init__(node)
self._dnf_tool_name: str
self._dnf_tool_name: str = "dnf"
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting _dnf_tool_name default to "dnf" can cause CBLMariner to run dnf before _initialize_package_installation() has had a chance to detect whether only tdnf is available. Since RPMDistro._install_packages/_uninstall_packages call _dnf_tool() without first calling _initialize_package_installation(), consider ensuring tool selection is initialized before any package operation (e.g., lazy-init inside _dnf_tool() or overriding _install_packages/_uninstall_packages to gate on _first_time_installation).

Copilot uses AI. Check for mistakes.

def _initialize_package_installation(self) -> None:
self.set_kill_user_processes()
Expand Down Expand Up @@ -2136,9 +2136,15 @@ def _create_local_repo(self, source_tarball: Path) -> None:
# the SSH session is reset
def set_kill_user_processes(self) -> None:
sed = self._node.tools[Sed]
# Azure Linux 4.0 moved logind.conf to /usr/lib/systemd/
logind_conf = "/etc/systemd/logind.conf"
if not self._node.shell.exists(
self._node.get_pure_path(logind_conf)
):
logind_conf = "/usr/lib/systemd/logind.conf"
Comment on lines +2141 to +2144
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback to /usr/lib/systemd/logind.conf is not validated for existence. If neither /etc/systemd/logind.conf nor /usr/lib/systemd/logind.conf exists, sed -i will fail and this method will raise unexpectedly. Consider checking the fallback path too and either creating /etc/systemd/logind.conf (preferred) or raising a clear error/skip when systemd config is not present.

Suggested change
if not self._node.shell.exists(
self._node.get_pure_path(logind_conf)
):
logind_conf = "/usr/lib/systemd/logind.conf"
shell = self._node.shell
primary_path = self._node.get_pure_path(logind_conf)
if not shell.exists(primary_path):
fallback_logind_conf = "/usr/lib/systemd/logind.conf"
fallback_path = self._node.get_pure_path(fallback_logind_conf)
if shell.exists(fallback_path):
logind_conf = fallback_logind_conf
else:
# Neither primary nor fallback exist; create the primary config file
self._log.debug(
"Neither /etc/systemd/logind.conf nor /usr/lib/systemd/logind.conf "
"exists. Creating /etc/systemd/logind.conf."
)
self._node.execute(
"mkdir -p /etc/systemd && touch /etc/systemd/logind.conf",
sudo=True,
shell=True,
expected_exit_code=0,
expected_exit_code_failure_message=(
"Failed to create /etc/systemd/logind.conf"
),
)

Copilot uses AI. Check for mistakes.
sed.append(
text="KillUserProcesses=no",
file="/etc/systemd/logind.conf",
file=logind_conf,
Comment on lines +2139 to +2147
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Editing the vendor config at /usr/lib/systemd/logind.conf is brittle (package updates may overwrite it) and may not be the correct override location for systemd. Prefer writing the setting to /etc/systemd/logind.conf (create it if missing) or a drop-in under /etc/systemd/logind.conf.d/, and keep /usr/lib untouched.

Copilot uses AI. Check for mistakes.
sudo=True,
)
self._node.tools[Service].restart_service("systemd-logind")
Comment on lines 2145 to 2150
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_kill_user_processes() always uses sed.append(...) and restarts systemd-logind, so repeated calls will keep appending duplicate KillUserProcesses=no lines and repeatedly restart the service (this is also currently invoked from _initialize_package_installation). Making the change idempotent (e.g., replace existing KillUserProcesses= or check if the setting already exists before editing/restarting) would avoid config bloat and unnecessary service churn.

Copilot uses AI. Check for mistakes.
Expand Down
4 changes: 2 additions & 2 deletions lisa/tools/fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def create(cls, node: "Node", *args: Any, **kwargs: Any) -> Tool:
if isinstance(node.os, CBLMariner):
if node.os.information.release == "2.0":
return AzlV2Fips(node, args, kwargs)
if node.os.information.release == "3.0":
if node.os.information.release in ("3.0", "4.0"):
return AzlV3Fips(node, args, kwargs)

raise UnsupportedDistroException(
os=node.os, message="FIPS tool only supported on CBLMariner 2.0 and 3.0."
os=node.os, message="FIPS tool only supported on CBLMariner 2.0, 3.0 and 4.0."
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UnsupportedDistroException(...) call is now long enough to violate the repo's flake8 max-line-length = 88 setting, which will fail linting. Please wrap the arguments across multiple lines (similar to grub_config.py) so each line stays within 88 chars.

Suggested change
os=node.os, message="FIPS tool only supported on CBLMariner 2.0, 3.0 and 4.0."
os=node.os,
message="FIPS tool only supported on CBLMariner 2.0, 3.0 and 4.0.",

Copilot uses AI. Check for mistakes.
)

def __init__(self, node: "Node", *args: Any, **kwargs: Any) -> None:
Expand Down
4 changes: 2 additions & 2 deletions lisa/tools/grub_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create(cls, node: "Node", *args: Any, **kwargs: Any) -> Tool:
if isinstance(node.os, CBLMariner):
if node.os.information.release == "2.0":
return GrubConfigAzl2(node, args, kwargs)
if node.os.information.release == "3.0":
if node.os.information.release in ("3.0", "4.0"):
return GrubConfigAzl3(node, args, kwargs)
elif isinstance(node.os, Debian):
return GrubConfigDebian(node, args, kwargs)
Expand All @@ -31,7 +31,7 @@ def create(cls, node: "Node", *args: Any, **kwargs: Any) -> Tool:

raise UnsupportedDistroException(
os=node.os,
message="Grub tool only supported on CBLMariner 2.0/3.0, "
message="Grub tool only supported on CBLMariner 2.0, 3.0 and 4.0, "
"Debian-based distributions, and RHEL-based distributions.",
)

Expand Down
Loading