-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
Fix LXC virtualization facts #58881
Fix LXC virtualization facts #58881
Conversation
There's an option to add another check for existance of |
Decided to add the host role check as well. Testing against a Ubuntu 18.04 LXD node running various LXC guests showed it as
which is just wrong. Checking on the system, I see
|
Please create unit tests and a changelog fragment. See this fragment as an example. There are tests in |
Any pointers for writing tests which mock a remote file system and then assert the facts for those file systems? Do such tests exist yet? |
@silverwind I do not believe we have any tests that do this currently. Go ahead and add the changelog fragment and I'll see if I can come up with some tests. |
Will do. Maybe a rudimentary mock like this could suffice for some basic testing: {
"/proc/1/cgroup": "file content",
"/dev/lxd/sock": "", # no content
"/var/lib/lxd/devlxd": "" # no content
} Thought generally, I think the whole concept of ansible_virtualization_role/type is flawed because a system can host multiple virtualization techs, e.g. LXD, Docker and KVM can all co-exist on the same machine, but we can only return one. The thing with LXD is that if someone has it installed, it's rather likely that it's their virtualization of choice, so that's why I added the check near the top of the file. |
Did a small change to the host detection. Because LXD docs were apparently wrong, I did only check for the directory containing the socket, not the socket file itself. Filed https://github.com/lxc/lxd/pull/5941 to fix their docs. |
Force-pushed with changelog fragment and a new commit message. |
That's what I was thinking as well. Just patch things to behave like files exist.
Also true. We were discussing this today and it would make more sense for this to be a list since there can be a combination of virtualization going on. This has compatibility implications, but your point is valid. |
Yes, of course. One way I see it done could be:
|
That has mostly been my plan for a while, but we was waiting for a facility to 'deprecate specific variables' which we have not been able to add yet. Until that happens, we could just go with the alternate keys and document that these are 'more precise' than the old ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix is still applicable. Adding lxc to the new virtualization_tech_guest and virtualization_tech_host facts lists is good since systems may have multiple. LGTM besides a concern about backwards compatibility for the legacy singular facts.
# https://lxd.readthedocs.io/en/latest/dev-lxd/ | ||
if os.path.exists('/dev/lxd/sock'): | ||
guest_tech.add('lxc') | ||
if not found_virt: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To keep backwards compatibility for the virtualization_type and virtualization_role facts, this would need to occur at the end of the function. First found wins, so this would take precedence over any of the facts found later. Same for the /var/lib/lxd/devlxd/sock
section.
Co-authored-by: Sloane Hertel <19572925+s-hertel@users.noreply.github.com>
@s-hertel maybe you want to take this over and file a new PR? I'm not really using ansible any more, so my motivation to further work on it is pretty much nil. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
The branch is too old, the CI can't check it out, needs rebase. |
I don't really need this anymore so I have lost interest. Anyone still interested, feel free to raise a new PR based on this one. |
SUMMARY
LXD guests were wrongly detected when running as non-root (making the check for
/proc/1/environ fail
) and when systemd was absent (making the check for/run/systemd/container
fail).Fixed this by adding a check for the LXD host <-> guest communication socket
/dev/lxd/sock
which is almost guaranteed to exist, thought it can theoretically be disabled by configuration.Ref: https://github.com/lxc/lxd/issues/5923#issuecomment-509705074
Ref: https://lxd.readthedocs.io/en/latest/dev-lxd/
ISSUE TYPE
COMPONENT NAME
facts
ADDITIONAL INFORMATION
Before
After