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

[2018.3] Fix to virtual core grain #50519

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions salt/grains/core.py
Expand Up @@ -909,7 +909,7 @@ def _virtual(osdata):
# Tested on CentOS 5.4 / 2.6.18-164.15.1.el5xen
grains['virtual_subtype'] = 'Xen Dom0'
else:
if grains.get('productname', '') == 'HVM domU':
if osdata.get('productname', '') == 'HVM domU':
# Requires dmidecode!
grains['virtual_subtype'] = 'Xen HVM DomU'
elif os.path.isfile('/proc/xen/capabilities') and \
Expand All @@ -926,9 +926,8 @@ def _virtual(osdata):
elif isdir('/sys/bus/xen'):
if 'xen:' in __salt__['cmd.run']('dmesg').lower():
grains['virtual_subtype'] = 'Xen PV DomU'
elif os.listdir('/sys/bus/xen/drivers'):
# An actual DomU will have several drivers
# whereas a paravirt ops kernel will not.
elif os.path.isfile('/sys/bus/xen/drivers/xenconsole'):
# An actual DomU will have the xenconsole driver
grains['virtual_subtype'] = 'Xen PV DomU'
# If a Dom0 or DomU was detected, obviously this is xen
if 'dom' in grains.get('virtual_subtype', '').lower():
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/grains/test_core.py
Expand Up @@ -685,6 +685,22 @@ def test_docker_virtual(self):
'Docker'
)

@skipIf(salt.utils.platform.is_windows(), 'System is Windows')
def test_xen_virtual(self):
'''
Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
'''
with patch.object(os.path, 'isfile', MagicMock(return_value=False)):
with patch.dict(core.__salt__, {'cmd.run': MagicMock(return_value='')}), \
patch.object(os.path,
'isfile',
MagicMock(side_effect=lambda x: True if x == '/sys/bus/xen/drivers/xenconsole' else False)):
log.debug('Testing Xen')
self.assertEqual(
core._virtual({'kernel': 'Linux'}).get('virtual_subtype'),
'Xen PV DomU'
)

def _check_ipaddress(self, value, ip_v):
'''
check if ip address in a list is valid
Expand Down