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

Set virtual grain in Podman systemd container #67734

Open
wants to merge 3 commits into
base: 3006.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog/67733.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set correct virtual grain in systemd based Podman containers
4 changes: 4 additions & 0 deletions salt/grains/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,10 @@ def _virtual(osdata):
grains["virtual"] = "container"
grains["virtual_subtype"] = "LXC"
break
elif "podman" in output:
grains["virtual"] = "container"
grains["virtual_subtype"] = "Podman"
break
elif "amazon" in output:
grains["virtual"] = "Nitro"
grains["virtual_subtype"] = "Amazon EC2"
Expand Down
31 changes: 31 additions & 0 deletions tests/pytests/unit/grains/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1847,6 +1847,37 @@ def test_lxc_virtual_with_virt_what():
assert ret["virtual_subtype"] == "LXC"


@pytest.mark.skip_on_windows
def test_podman_virtual_with_systemd_detect_virt():
"""
Test if virtual grains are parsed correctly in Podman using systemd-detect-virt.
"""

def _which_side_effect(path):
if path == "systemd-detect-virt":
return "/usr/bin/systemd-detect-virt"
return None

with patch.object(
salt.utils.platform, "is_windows", MagicMock(return_value=False)
), patch.object(
salt.utils.path,
"which",
MagicMock(return_value=True, side_effect=_which_side_effect),
), patch.dict(
core.__salt__,
{
"cmd.run_all": MagicMock(
return_value={"pid": 78, "retcode": 0, "stderr": "", "stdout": "podman"}
)
},
):
osdata = {"kernel": "test"}
ret = core._virtual(osdata)
assert ret["virtual"] == "container"
assert ret["virtual_subtype"] == "Podman"


@pytest.mark.skip_on_windows
def test_container_inside_virtual_machine():
"""
Expand Down
Loading