From 60724980ec9622c55b4fdf9ccc7fd4381482d7e6 Mon Sep 17 00:00:00 2001 From: Ch3LL Date: Thu, 13 Apr 2017 12:04:20 -0400 Subject: [PATCH 01/12] fix test_fstype test for mac --- tests/unit/modules/disk_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/modules/disk_test.py b/tests/unit/modules/disk_test.py index ec162f7459..dff8194781 100644 --- a/tests/unit/modules/disk_test.py +++ b/tests/unit/modules/disk_test.py @@ -149,8 +149,9 @@ class DiskTestCase(TestCase): device = '/dev/sdX1' fs_type = 'ext4' mock = MagicMock(return_value='FSTYPE\n{0}'.format(fs_type)) - with patch.dict(disk.__salt__, {'cmd.run': mock}): - self.assertEqual(disk.fstype(device), fs_type) + with patch.dict(disk.__grains__, {'kernel': 'Linux'}): + with patch.dict(disk.__salt__, {'cmd.run': mock}): + self.assertEqual(disk.fstype(device), fs_type) @skipIf(not salt.utils.which('resize2fs'), 'resize2fs not found') def test_resize2fs(self): From 5fb8190d44a115660bb85369dc1f0dd2e7f54b4d Mon Sep 17 00:00:00 2001 From: Christian McHugh Date: Sun, 9 Apr 2017 09:23:06 +0100 Subject: [PATCH 02/12] Ensure batch uses passed eauth token or credentials --- salt/client/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/salt/client/__init__.py b/salt/client/__init__.py index c28126ec63..7276a4d4e8 100644 --- a/salt/client/__init__.py +++ b/salt/client/__init__.py @@ -516,10 +516,14 @@ class LocalClient(object): if 'gather_job_timeout' in kwargs: opts['gather_job_timeout'] = kwargs['gather_job_timeout'] + eauth=kwargs.get('eauth', {}) + if 'token' in kwargs: + eauth['token'] = kwargs['token'] + for key, val in six.iteritems(self.opts): if key not in opts: opts[key] = val - batch = salt.cli.batch.Batch(opts, quiet=True) + batch = salt.cli.batch.Batch(opts, eauth=eauth, quiet=True) for ret in batch.run(): yield ret From 260dd8475825c3afd68c5f3843c5a0866a7bb8c2 Mon Sep 17 00:00:00 2001 From: Christian McHugh Date: Wed, 12 Apr 2017 06:51:18 +0100 Subject: [PATCH 03/12] Create eauth dict for passing into batch class --- salt/client/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/salt/client/__init__.py b/salt/client/__init__.py index 7276a4d4e8..2220beb339 100644 --- a/salt/client/__init__.py +++ b/salt/client/__init__.py @@ -517,6 +517,10 @@ class LocalClient(object): opts['gather_job_timeout'] = kwargs['gather_job_timeout'] eauth=kwargs.get('eauth', {}) + if 'username' in kwargs: + eauth['username'] = kwargs['username'] + if 'password' in kwargs: + eauth['password'] = kwargs['password'] if 'token' in kwargs: eauth['token'] = kwargs['token'] From 6eec04b2db45a35af9d489d7f94f6db25dc1d617 Mon Sep 17 00:00:00 2001 From: Christian McHugh Date: Wed, 12 Apr 2017 18:09:51 +0100 Subject: [PATCH 04/12] pop out of kwargs --- salt/client/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/salt/client/__init__.py b/salt/client/__init__.py index 2220beb339..79715c9d3a 100644 --- a/salt/client/__init__.py +++ b/salt/client/__init__.py @@ -516,13 +516,15 @@ class LocalClient(object): if 'gather_job_timeout' in kwargs: opts['gather_job_timeout'] = kwargs['gather_job_timeout'] - eauth=kwargs.get('eauth', {}) + eauth = {} + if 'eauth' in kwargs: + eauth['eauth'] = kwargs.pop('eauth') if 'username' in kwargs: - eauth['username'] = kwargs['username'] + eauth['username'] = kwargs.pop('username') if 'password' in kwargs: - eauth['password'] = kwargs['password'] + eauth['password'] = kwargs.pop('password') if 'token' in kwargs: - eauth['token'] = kwargs['token'] + eauth['token'] = kwargs.pop('token') for key, val in six.iteritems(self.opts): if key not in opts: From e790930f5ab0628698bf9b7a614317ac234c3d06 Mon Sep 17 00:00:00 2001 From: Christian McHugh Date: Wed, 12 Apr 2017 22:07:15 +0100 Subject: [PATCH 05/12] re-add batch support to cherrypy saltapi --- salt/netapi/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/salt/netapi/__init__.py b/salt/netapi/__init__.py index d9f91726c4..6f4ae9ee13 100644 --- a/salt/netapi/__init__.py +++ b/salt/netapi/__init__.py @@ -109,6 +109,20 @@ class NetapiClient(object): local = salt.client.get_local_client(mopts=self.opts) return local.cmd_subset(*args, **kwargs) + def local_batch(self, *args, **kwargs): + ''' + Run :ref:`execution modules ` against batches of minions + + .. versionadded:: 0.8.4 + + Wraps :py:meth:`salt.client.LocalClient.cmd_batch` + + :return: Returns the result from the exeuction module for each batch of + returns + ''' + local = salt.client.get_local_client(mopts=self.opts) + return local.cmd_batch(*args, **kwargs) + def ssh(self, *args, **kwargs): ''' Run salt-ssh commands synchronously From ecbb0d186f3f7fe4dfb11057131b2b565705a172 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 13 Apr 2017 10:32:25 -0600 Subject: [PATCH 06/12] Allow status beacon to run on all operating systems --- salt/beacons/status.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/salt/beacons/status.py b/salt/beacons/status.py index 951f46e673..b338e68445 100644 --- a/salt/beacons/status.py +++ b/salt/beacons/status.py @@ -81,6 +81,12 @@ markers for specific list items: - 0 - 1 - 2 + + +.. warning:: + Not all status functions are supported for every operating system. Be certain + to check the minion log for errors after configuring this beacon. + ''' # Import python libs @@ -91,6 +97,8 @@ import salt.exceptions log = logging.getLogger(__name__) +__virtualname__ = 'status' + def __validate__(config): ''' @@ -102,11 +110,7 @@ def __validate__(config): def __virtual__(): - # TODO Find a way to check the existence of the module itself, not just a single func - if 'status.w' not in __salt__: - return (False, 'The \'status\' execution module is not available on this system') - else: - return True + return __virtualname__ def beacon(config): From cc1643eb1f9ae296c8e7a6b327bf6dc5aba23fa8 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 13 Apr 2017 11:33:12 -0600 Subject: [PATCH 07/12] Fix netapi lint --- salt/netapi/__init__.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/salt/netapi/__init__.py b/salt/netapi/__init__.py index 6f4ae9ee13..9821d5bb1d 100644 --- a/salt/netapi/__init__.py +++ b/salt/netapi/__init__.py @@ -110,18 +110,18 @@ class NetapiClient(object): return local.cmd_subset(*args, **kwargs) def local_batch(self, *args, **kwargs): - ''' - Run :ref:`execution modules ` against batches of minions - - .. versionadded:: 0.8.4 - - Wraps :py:meth:`salt.client.LocalClient.cmd_batch` - - :return: Returns the result from the exeuction module for each batch of - returns - ''' - local = salt.client.get_local_client(mopts=self.opts) - return local.cmd_batch(*args, **kwargs) + ''' + Run :ref:`execution modules ` against batches of minions + + .. versionadded:: 0.8.4 + + Wraps :py:meth:`salt.client.LocalClient.cmd_batch` + + :return: Returns the result from the exeuction module for each batch of + returns + ''' + local = salt.client.get_local_client(mopts=self.opts) + return local.cmd_batch(*args, **kwargs) def ssh(self, *args, **kwargs): ''' From a61fc824c476281bf10f4f88e2e0f741191ec17d Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Thu, 13 Apr 2017 09:14:52 -0600 Subject: [PATCH 08/12] use loader for war extraction Also set the version added in the docs --- salt/modules/tomcat.py | 4 ++-- salt/states/tomcat.py | 7 ++----- tests/unit/states/tomcat_test.py | 3 ++- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/salt/modules/tomcat.py b/salt/modules/tomcat.py index a21b16a746..b30033648f 100644 --- a/salt/modules/tomcat.py +++ b/salt/modules/tomcat.py @@ -176,7 +176,7 @@ def _auth(uri): return _build_opener(basic, digest) -def _extract_war_version(war): +def extract_war_version(war): ''' Extract the version from the war file name. There does not seem to be a standard for encoding the version into the `war file name @@ -609,7 +609,7 @@ def deploy_war(war, # If parallel versions are desired or not disabled if version is True: # Set it to defined version or attempt extract - version = version or _extract_war_version(war) + version = version or extract_war_version(war) if version != ('' or None): # Only pass version to Tomcat if not undefined diff --git a/salt/states/tomcat.py b/salt/states/tomcat.py index 99dfc387e2..99dd26243e 100644 --- a/salt/states/tomcat.py +++ b/salt/states/tomcat.py @@ -57,9 +57,6 @@ Notes from __future__ import absolute_import -# import salt libs -from salt.modules.tomcat import _extract_war_version - # Private def __virtual__(): @@ -110,7 +107,7 @@ def war_deployed(name, Use ``False`` to prevent guessing the version and keeping it blank. - .. versionadded:: 2016.PLEASE_LET_ME_KNOW + .. versionadded:: 2016.11.0 Example: @@ -138,7 +135,7 @@ def war_deployed(name, # if version is defined or False, we don't want to overwrite if version == '': - version = _extract_war_version(war) or "" + version = __salt__['tomcat.extract_war_version'](war) or '' elif not version: version = '' else: diff --git a/tests/unit/states/tomcat_test.py b/tests/unit/states/tomcat_test.py index a2643c16f3..f4a9c453e9 100644 --- a/tests/unit/states/tomcat_test.py +++ b/tests/unit/states/tomcat_test.py @@ -8,6 +8,7 @@ from __future__ import absolute_import # Import Salt Libs from salt.states import tomcat +from salt.modules import tomcat as tomcatmod # Import Salt Testing Libs from salttesting import TestCase, skipIf @@ -22,7 +23,7 @@ from salttesting.mock import ( ensure_in_syspath('../../') # Globals -tomcat.__salt__ = {} +tomcat.__salt__ = {'tomcat.extract_war_version': tomcatmod.extract_war_version} tomcat.__opts__ = {} tomcat.__env__ = {} From b6ac4aa86dd6da85304efa1abe7d992a530092c5 Mon Sep 17 00:00:00 2001 From: twangboy Date: Thu, 13 Apr 2017 13:51:15 -0600 Subject: [PATCH 09/12] Fix service for win10 update --- pkg/windows/installer/Salt-Minion-Setup.nsi | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/windows/installer/Salt-Minion-Setup.nsi b/pkg/windows/installer/Salt-Minion-Setup.nsi index f076bd7a53..af809c23bb 100644 --- a/pkg/windows/installer/Salt-Minion-Setup.nsi +++ b/pkg/windows/installer/Salt-Minion-Setup.nsi @@ -337,6 +337,7 @@ Section -Post nsExec::Exec "nssm.exe install salt-minion $INSTDIR\bin\python.exe $INSTDIR\bin\Scripts\salt-minion -c $INSTDIR\conf -l quiet" nsExec::Exec "nssm.exe set salt-minion AppEnvironmentExtra PYTHONHOME=" nsExec::Exec "nssm.exe set salt-minion Description Salt Minion from saltstack.com" + nsExec::Exec "nssm.exe set salt-minion AppNoConsole 1" RMDir /R "$INSTDIR\var\cache\salt" ; removing cache from old version From e5a3a7d21701ec504fc1be7d5a49794717d55320 Mon Sep 17 00:00:00 2001 From: Jim Adson Date: Thu, 13 Apr 2017 15:33:54 -0600 Subject: [PATCH 10/12] Fixes bug that prevents syslog returner from working under Python 2.6 Fixes #40688 --- salt/returners/syslog_return.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/salt/returners/syslog_return.py b/salt/returners/syslog_return.py index 079fc67da3..67adbaa509 100644 --- a/salt/returners/syslog_return.py +++ b/salt/returners/syslog_return.py @@ -192,10 +192,14 @@ def returner(ret): logoption = logoption | getattr(syslog, opt) # Open syslog correctly based on options and tag - if 'tag' in _options: - syslog.openlog(ident=_options['tag'], logoption=logoption) - else: - syslog.openlog(logoption=logoption) + try: + if 'tag' in _options: + syslog.openlog(ident=_options['tag'], logoption=logoption) + else: + syslog.openlog(logoption=logoption) + except TypeError: + # Python 2.6 syslog.openlog does not accept keyword args + syslog.openlog(_options.get('tag', 'salt-minion'), logoption) # Send log of given level and facility syslog.syslog(facility | level, '{0}'.format(json.dumps(ret))) From b78fc46b91afebefd6e7d211221f472021923dde Mon Sep 17 00:00:00 2001 From: "Thor K. H" Date: Thu, 13 Apr 2017 22:56:09 +0100 Subject: [PATCH 11/12] Fixes #40658: clearer version handling A few minor improvements/fixes to the clarity of version handling from both the states view, and the module. Firstly, the main culprit: the module's check for the passed version parameter was too strict, and would only work when the version was explicitly True. This would never work for a string. This has been changed to simply check if it's "true"-ish: if no parameter is passed, the default is True, and it'll try to guess a version number. If you pass a specific version, then it'll use that. Should you pass False, or an empty string, it'll be viewed as blank, which was the initial intent. It's not that *that* didn't work, it's just that the other part didn't, which means no version at all did. *cough* Besides that, it's a bit clearer with different default named parameter values for 'version', that doesn't otherwise change the behaviour in any reasonable backwards way. A blank version for a Tomcat version is nonsensical, per Apache's documentation. https://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Naming Otherwise, it's all minor with an actual type checker before sending it along in the module. Plus, there was a minor mistake in the documentation for the state. --- salt/modules/tomcat.py | 9 +++++---- salt/states/tomcat.py | 14 ++++++-------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/salt/modules/tomcat.py b/salt/modules/tomcat.py index b30033648f..41c4e8e577 100644 --- a/salt/modules/tomcat.py +++ b/salt/modules/tomcat.py @@ -72,6 +72,7 @@ import logging # Import 3rd-party libs # pylint: disable=no-name-in-module,import-error +from salt.ext.six import string_types as _string_types from salt.ext.six.moves.urllib.parse import urlencode as _urlencode from salt.ext.six.moves.urllib.request import ( urlopen as _urlopen, @@ -526,7 +527,7 @@ def deploy_war(war, saltenv='base', timeout=180, temp_war_location=None, - version=''): + version=True): ''' Deploy a WAR file @@ -607,11 +608,11 @@ def deploy_war(war, } # If parallel versions are desired or not disabled - if version is True: + if version: # Set it to defined version or attempt extract - version = version or extract_war_version(war) + version = extract_war_version(war) if version is True else version - if version != ('' or None): + if isinstance(version, _string_types): # Only pass version to Tomcat if not undefined opts['version'] = version diff --git a/salt/states/tomcat.py b/salt/states/tomcat.py index 99dd26243e..a467ce03c7 100644 --- a/salt/states/tomcat.py +++ b/salt/states/tomcat.py @@ -74,7 +74,7 @@ def war_deployed(name, url='http://localhost:8080/manager', timeout=180, temp_war_location=None, - version=''): + version=True): ''' Enforce that the WAR will be deployed and started in the context path, while making use of WAR versions in the filename. @@ -105,7 +105,7 @@ def war_deployed(name, .. versionadded:: 2015.8.6 - Use ``False`` to prevent guessing the version and keeping it blank. + Use ``False`` or blank value to prevent guessing the version and keeping it blank. .. versionadded:: 2016.11.0 @@ -115,7 +115,7 @@ def war_deployed(name, jenkins: tomcat.war_deployed: - - name: /ran + - name: /salt-powered-jenkins - war: salt://jenkins-1.2.4.war - require: - service: application-service @@ -123,7 +123,7 @@ def war_deployed(name, .. note:: Be aware that in the above example the WAR ``jenkins-1.2.4.war`` will - be deployed to the context path ``jenkins##1.2.4``. To avoid this + be deployed to the context path ``salt-powered-jenkins##1.2.4``. To avoid this either specify a version yourself, or set version to ``False``. ''' @@ -134,12 +134,10 @@ def war_deployed(name, 'comment': ''} # if version is defined or False, we don't want to overwrite - if version == '': + if version is True: version = __salt__['tomcat.extract_war_version'](war) or '' elif not version: version = '' - else: - version = str(version) webapps = __salt__['tomcat.ls'](url, timeout) deploy = False @@ -147,7 +145,7 @@ def war_deployed(name, status = True # Gathered/specified new WAR version string - specified_ver = 'version ' + version if version else 'no version' + specified_ver = 'version {}'.format(version) if version else 'no version' # Determine what to do try: From 09145ea1a50010e1adfef6486ab9bdfbd99ea986 Mon Sep 17 00:00:00 2001 From: "Thor K. H" Date: Fri, 14 Apr 2017 08:51:16 +0100 Subject: [PATCH 12/12] Fixes unindexed strfmt curly braces for python 2.6 --- salt/states/tomcat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/states/tomcat.py b/salt/states/tomcat.py index a467ce03c7..acee0e2fd5 100644 --- a/salt/states/tomcat.py +++ b/salt/states/tomcat.py @@ -145,7 +145,7 @@ def war_deployed(name, status = True # Gathered/specified new WAR version string - specified_ver = 'version {}'.format(version) if version else 'no version' + specified_ver = 'version {0}'.format(version) if version else 'no version' # Determine what to do try: