From a30af3252e53900a498949024b96ae4f3b694ce5 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Mon, 30 Oct 2017 09:22:08 -0600 Subject: [PATCH 1/4] add docker-ce to docker subtype grains check Fixes #44292 --- salt/grains/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/grains/core.py b/salt/grains/core.py index bb1696304a9..08edfb3cc8f 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -699,9 +699,10 @@ def _virtual(osdata): 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: fhr_contents = fhr.read() - if ':/docker/' in fhr_contents or ':/system.slice/docker' in fhr_contents: + if any(dstring in fhr_contents for dstring in dstrings): grains['virtual_subtype'] = 'Docker' except IOError: pass From b4eb1527a6bc3d509ffb0a9dae25b494cd60f138 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Sat, 25 Nov 2017 14:32:43 -0600 Subject: [PATCH 2/4] Add test for PR 44335 This also modifies the virtual_subtype code slightly, due to an issue I noticed in testing. We were reading from `/proc/1/cgroup` twice (once for LXC, and then again for Docker). --- salt/grains/core.py | 11 ++++++----- tests/unit/grains/core_test.py | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/salt/grains/core.py b/salt/grains/core.py index 08edfb3cc8f..6ab4d099e67 100644 --- a/salt/grains/core.py +++ b/salt/grains/core.py @@ -696,13 +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' - dstrings = (':/system.slice/docker', ':/docker/', ':/docker-ce/') with salt.utils.fopen('/proc/1/cgroup', 'r') as fhr: 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' except IOError: pass diff --git a/tests/unit/grains/core_test.py b/tests/unit/grains/core_test.py index 7f5430c233c..0249ca1aa17 100644 --- a/tests/unit/grains/core_test.py +++ b/tests/unit/grains/core_test.py @@ -5,6 +5,7 @@ # Import Python libs from __future__ import absolute_import +import logging import os import platform @@ -28,6 +29,8 @@ from salt.grains import core # Globals core.__salt__ = {} +core.__opts__ = {} +log = logging.getLogger(__name__) @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.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__': from integration import run_tests From e2682bf4410388b21837688acb4282e91e02f21f Mon Sep 17 00:00:00 2001 From: chris ruscio Date: Thu, 30 Nov 2017 13:56:10 -0500 Subject: [PATCH 3/4] Fix minion ping_interval documentation --- conf/minion | 4 ++-- doc/ref/configuration/minion.rst | 2 +- salt/config/__init__.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/conf/minion b/conf/minion index 34a6abeda40..6d559bf5dac 100644 --- a/conf/minion +++ b/conf/minion @@ -235,13 +235,13 @@ # cause sub minion process to restart. #auth_safemode: False -# Ping Master to ensure connection is alive (seconds). +# Ping Master to ensure connection is alive (minutes). #ping_interval: 0 # To auto recover minions if master changes IP address (DDNS) # auth_tries: 10 # auth_safemode: False -# ping_interval: 90 +# ping_interval: 2 # # Minions won't know master is missing until a ping fails. After the ping fail, # the minion will attempt authentication and likely fails out and cause a restart. diff --git a/doc/ref/configuration/minion.rst b/doc/ref/configuration/minion.rst index b3077fe0a44..d0d9977c56b 100644 --- a/doc/ref/configuration/minion.rst +++ b/doc/ref/configuration/minion.rst @@ -883,7 +883,7 @@ restart. Default: ``0`` -Instructs the minion to ping its master(s) every n number of seconds. Used +Instructs the minion to ping its master(s) every n number of minutes. Used primarily as a mitigation technique against minion disconnects. .. code-block:: yaml diff --git a/salt/config/__init__.py b/salt/config/__init__.py index 39898a711d5..a2893548e3f 100644 --- a/salt/config/__init__.py +++ b/salt/config/__init__.py @@ -855,7 +855,7 @@ VALID_OPTS = { 'queue_dirs': list, - # Instructs the minion to ping its master(s) every n number of seconds. Used + # Instructs the minion to ping its master(s) every n number of minutes. Used # primarily as a mitigation technique against minion disconnects. 'ping_interval': int, From 3f1268d67f1714fba0521aa2bb7a63b8a7bba37a Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Thu, 7 Dec 2017 08:25:26 -0700 Subject: [PATCH 4/4] fix patching for python 2.6 --- tests/unit/grains/core_test.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/unit/grains/core_test.py b/tests/unit/grains/core_test.py index 1d05cc90907..ee7fe36386e 100644 --- a/tests/unit/grains/core_test.py +++ b/tests/unit/grains/core_test.py @@ -474,22 +474,21 @@ PATCHLEVEL = 3 ''' 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' - ) + 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): '''