mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
commit
f02b02032d
@ -696,13 +696,14 @@ def _virtual(osdata):
|
|||||||
pass
|
pass
|
||||||
if os.path.isfile('/proc/1/cgroup'):
|
if os.path.isfile('/proc/1/cgroup'):
|
||||||
try:
|
try:
|
||||||
with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr:
|
|
||||||
if ':/lxc/' in fhr.read():
|
|
||||||
grains['virtual_subtype'] = 'LXC'
|
|
||||||
dstrings = (':/system.slice/docker', ':/docker/', ':/docker-ce/')
|
|
||||||
with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr:
|
with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr:
|
||||||
fhr_contents = fhr.read()
|
fhr_contents = fhr.read()
|
||||||
if any(dstring in fhr_contents for dstring in dstrings):
|
if ':/lxc/' in fhr_contents:
|
||||||
|
grains['virtual_subtype'] = 'LXC'
|
||||||
|
else:
|
||||||
|
if any(x in fhr_contents
|
||||||
|
for x in (':/system.slice/docker', ':/docker/',
|
||||||
|
':/docker-ce/')):
|
||||||
grains['virtual_subtype'] = 'Docker'
|
grains['virtual_subtype'] = 'Docker'
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
# Import Python libs
|
# Import Python libs
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
@ -28,6 +29,8 @@ from salt.grains import core
|
|||||||
|
|
||||||
# Globals
|
# Globals
|
||||||
core.__salt__ = {}
|
core.__salt__ = {}
|
||||||
|
core.__opts__ = {}
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||||
@ -459,6 +462,27 @@ PATCHLEVEL = 3
|
|||||||
self.assertListEqual(list(os_grains.get('osrelease_info')), os_release_map['osrelease_info'])
|
self.assertListEqual(list(os_grains.get('osrelease_info')), os_release_map['osrelease_info'])
|
||||||
self.assertEqual(os_grains.get('osmajorrelease'), os_release_map['osmajorrelease'])
|
self.assertEqual(os_grains.get('osmajorrelease'), os_release_map['osmajorrelease'])
|
||||||
|
|
||||||
|
def test_docker_virtual(self):
|
||||||
|
'''
|
||||||
|
Test if OS grains are parsed correctly in Ubuntu Xenial Xerus
|
||||||
|
'''
|
||||||
|
with patch.object(os.path, 'isdir', MagicMock(return_value=False)), \
|
||||||
|
patch.object(os.path,
|
||||||
|
'isfile',
|
||||||
|
MagicMock(side_effect=lambda x: True
|
||||||
|
if x == '/proc/1/cgroup' else False)):
|
||||||
|
for cgroup_substr in (':/system.slice/docker', ':/docker/',
|
||||||
|
':/docker-ce/'):
|
||||||
|
cgroup_data = \
|
||||||
|
'10:memory{0}a_long_sha256sum'.format(cgroup_substr)
|
||||||
|
log.debug(
|
||||||
|
'Testing Docker cgroup substring \'%s\'', cgroup_substr)
|
||||||
|
with patch('salt.utils.fopen', mock_open(read_data=cgroup_data)):
|
||||||
|
self.assertEqual(
|
||||||
|
core._virtual({'kernel': 'Linux'}).get('virtual_subtype'),
|
||||||
|
'Docker'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from integration import run_tests
|
from integration import run_tests
|
||||||
|
Loading…
Reference in New Issue
Block a user