Fix value of virtual grain when using virt-what

`virt-what` might return multiple lines, depending on what it detected (e.g. `lxc` inside a `HyperV` VM), where the last line corresponds to the most likely match.

Until now, Salt evaluated the whole multi-line output as a single string, which caused quite inaccurate matches. This commit changes this behavior to only evaluate the last line of the `virt-what` output.

A similar issue is described in #25697, but might actually have a different root cause.
This commit is contained in:
Elias Probst 2018-10-08 17:38:40 +02:00
parent f7f8cb533f
commit 4b5421a0f5
No known key found for this signature in database
GPG Key ID: A4096F8C18F883D9

View File

@ -781,6 +781,7 @@ def _virtual(osdata):
grains['virtual'] = 'LXC' grains['virtual'] = 'LXC'
break break
elif command == 'virt-what': elif command == 'virt-what':
output = output.splitlines()[-1]
if output in ('kvm', 'qemu', 'uml', 'xen', 'lxc'): if output in ('kvm', 'qemu', 'uml', 'xen', 'lxc'):
grains['virtual'] = output grains['virtual'] = output
break break