Merge pull request #44335 from gtmanfred/2016.11

add docker-ce to docker subtype grains check
This commit is contained in:
Nicole Thomas 2017-12-10 12:17:49 -05:00 committed by GitHub
commit d4ab55ec47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

View File

@ -696,12 +696,14 @@ def _virtual(osdata):
pass
if os.path.isfile('/proc/1/cgroup'):
try:
with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr:
if ':/lxc/' in fhr.read():
grains['virtual_subtype'] = 'LXC'
with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr:
fhr_contents = fhr.read()
if ':/docker/' in fhr_contents or ':/system.slice/docker' in fhr_contents:
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'
except IOError:
pass

View File

@ -5,6 +5,7 @@
# Import Python libs
from __future__ import absolute_import
import logging
import os
import platform
@ -29,6 +30,7 @@ from salt.grains import core
# Globals
core.__salt__ = {}
core.__opts__ = {}
log = logging.getLogger(__name__)
IPv4Address = salt.ext.ipaddress.IPv4Address
IPv6Address = salt.ext.ipaddress.IPv6Address
IP4_LOCAL = '127.0.0.1'
@ -468,6 +470,26 @@ PATCHLEVEL = 3
self.assertListEqual(list(os_grains.get('osrelease_info')), os_release_map['osrelease_info'])
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)):
with 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'
)
def _check_ipaddress(self, value, ip_v):
'''
check if ip address in a list is valid