Normalize virtual grain for LXC#60196
Conversation
- Consistently report grains["virtual"] = "container" and grains["virtual_subtype"] = "LXC" - Makes virt-what parsing to stop after the first match - Adds an additional verification for new LXC versions - Moves the probing for containers to the end of detection routine, so the results wasn't overwrite by the hypervisor detection.
|
@piterpunk |
|
re-run pr-debian-9-amd64-py3-pytest |
waynew
left a comment
There was a problem hiding this comment.
I don't think it /needs/ changing, but a couple of comments around the tests.
Looks good 👍
| grains.get("virtual"), "container", | ||
| ) | ||
|
|
||
| with patch.object(os.path, "isdir", MagicMock(return_value=False)): |
There was a problem hiding this comment.
suggestion (non-blocking) patch actually creates a MagicMock already. Also it's typically a good idea to create_autospec. Also in this case, patching object is probably less-desirable. All-in-all, this could be written like so:
with patch("os.path.isdir", autospec=True, return_value=False):
with patch("os.path.isfile", autospec=True, side_effect=lambda x: x in (...)):
(note, no need to True if <something> else False - just <something> or bool(something) [but, thing in stuff produces a bool value anyway)
There was a problem hiding this comment.
Hi @waynew ,
I just used the test_lxc_virtual as basis to create the new tests, that's why the code looks this way. Take a look in lines 1218 to 1223.
What does this PR do?
Fixes the virtual grains in LXC containers. Now it always set
grains["virtual"] = "container"andgrains["virtual_subtype"] = "LXC", independent of the command used for detection and even running inside another virtual machine.What issues does this PR fix or reference?
Fixes #53868
Fixes #59573
Previous Behavior
The
grains["virtual"]is inconsistent depending with the available commands for probing:New Behavior
The
grains["virtual"]andgrains["virtual_subtype"]shows always the same output regardless the probe command.Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
No