From bfcbdeca3b3c1434dc919ee3e6bc282998672143 Mon Sep 17 00:00:00 2001 From: twangboy Date: Fri, 13 Jul 2018 15:43:57 -0600 Subject: [PATCH 01/14] Fix lgpo issue on Py3 Open the gpt ini file in normal mode (not binary) Use log.exception so you can see where the actual problems are Add TODOs to make the exceptions more specific --- salt/modules/win_lgpo.py | 60 +++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/salt/modules/win_lgpo.py b/salt/modules/win_lgpo.py index 3690640e98..908f561fd9 100644 --- a/salt/modules/win_lgpo.py +++ b/salt/modules/win_lgpo.py @@ -2588,7 +2588,9 @@ class _policy_info(object): userSid = '{1}\\{0}'.format(userSid[0], userSid[1]) else: userSid = '{0}'.format(userSid[0]) + # TODO: This needs to be more specific except Exception: + log.exception('Handle this explicitly') userSid = win32security.ConvertSidToStringSid(_sid) usernames.append(userSid) return usernames @@ -2607,7 +2609,9 @@ class _policy_info(object): try: sid = win32security.LookupAccountName('', _user)[0] sids.append(sid) + # This needs to be more specific except Exception as e: + log.exception('Handle this explicitly') raise CommandExecutionError(( 'There was an error obtaining the SID of user "{0}". Error ' 'returned: {1}' @@ -2760,7 +2764,9 @@ def _processPolicyDefinitions(policy_def_path='c:\\Windows\\PolicyDefinitions', except lxml.etree.XMLSyntaxError: try: xmltree = _remove_unicode_encoding(admfile) + # TODO: This needs to be more specific except Exception: + log.exception('Handle this explicitly') log.error('A error was found while processing admx ' 'file %s, all policies from this file will ' 'be unavailable via this module', admfile) @@ -2845,7 +2851,9 @@ def _processPolicyDefinitions(policy_def_path='c:\\Windows\\PolicyDefinitions', # see issue #38100 try: xmltree = _remove_unicode_encoding(adml_file) + # TODO: This needs to be more specific except Exception: + log.exception('Handle this explicitly') log.error('An error was found while processing ' 'adml file %s, all policy ' 'language data from this file will be ' @@ -2901,8 +2909,9 @@ def _findOptionValueInSeceditFile(option): if _line.startswith(option): return True, _line.split('=')[1].strip() return True, 'Not Defined' - except Exception as e: - log.debug('error occurred while trying to get secedit data') + # TODO: This needs to be more specific + except Exception: + log.exception('error occurred while trying to get secedit data') return False, None @@ -2932,8 +2941,9 @@ def _importSeceditConfig(infdata): if __salt__['file.file_exists'](_tInfFile): _ret = __salt__['file.remove'](_tInfFile) return True + # TODO: This needs to be more specific except Exception as e: - log.debug('error occurred while trying to import secedit data') + log.exception('error occurred while trying to import secedit data') return False @@ -2995,9 +3005,10 @@ def _addAccountRights(sidObject, user_right): user_rights_list = [user_right] _ret = win32security.LsaAddAccountRights(_polHandle, sidObject, user_rights_list) return True + # TODO: This needs to be more specific except Exception as e: - log.error('Error attempting to add account right, exception was %s', - e) + log.exception('Error attempting to add account right, exception was %s', + e) return False @@ -3011,8 +3022,7 @@ def _delAccountRights(sidObject, user_right): _ret = win32security.LsaRemoveAccountRights(_polHandle, sidObject, False, user_rights_list) return True except Exception as e: - log.error('Error attempting to delete account right, ' - 'exception was %s', e) + log.exception('Error attempting to delete account right') return False @@ -4180,7 +4190,7 @@ def _write_regpol_data(data_to_write, try: reg_pol_header = u'\u5250\u6765\x01\x00' if not os.path.exists(policy_file_path): - ret = __salt__['file.makedirs'](policy_file_path) + __salt__['file.makedirs'](policy_file_path) with salt.utils.files.fopen(policy_file_path, 'wb') as pol_file: if not data_to_write.startswith(reg_pol_header.encode('utf-16-le')): pol_file.write(reg_pol_header.encode('utf-16-le')) @@ -4188,11 +4198,12 @@ def _write_regpol_data(data_to_write, try: gpt_ini_data = '' if os.path.exists(gpt_ini_path): - with salt.utils.files.fopen(gpt_ini_path, 'rb') as gpt_file: + with salt.utils.files.fopen(gpt_ini_path, 'r') as gpt_file: gpt_ini_data = gpt_file.read() if not _regexSearchRegPolData(r'\[General\]\r\n', gpt_ini_data): gpt_ini_data = '[General]\r\n' + gpt_ini_data - if _regexSearchRegPolData(r'{0}='.format(re.escape(gpt_extension)), gpt_ini_data): + if _regexSearchRegPolData(r'{0}='.format(re.escape(gpt_extension)), + gpt_ini_data): # ensure the line contains the ADM guid gpt_ext_loc = re.search(r'^{0}=.*\r\n'.format(re.escape(gpt_extension)), gpt_ini_data, @@ -4208,9 +4219,10 @@ def _write_regpol_data(data_to_write, general_location = re.search(r'^\[General\]\r\n', gpt_ini_data, re.IGNORECASE | re.MULTILINE) - gpt_ini_data = "{0}{1}={2}\r\n{3}".format( + gpt_ini_data = '{0}{1}={2}\r\n{3}'.format( gpt_ini_data[general_location.start():general_location.end()], - gpt_extension, gpt_extension_guid, + gpt_extension, + gpt_extension_guid, gpt_ini_data[general_location.end():]) # https://technet.microsoft.com/en-us/library/cc978247.aspx if _regexSearchRegPolData(r'Version=', gpt_ini_data): @@ -4225,9 +4237,10 @@ def _write_regpol_data(data_to_write, elif gpt_extension.lower() == 'gPCUserExtensionNames'.lower(): version_nums = (version_nums[0] + 1, version_nums[1]) version_num = struct.unpack(b'>I', struct.pack(b'>2H', *version_nums))[0] - gpt_ini_data = "{0}{1}={2}\r\n{3}".format( + gpt_ini_data = '{0}{1}={2}\r\n{3}'.format( gpt_ini_data[0:version_loc.start()], - 'Version', version_num, + 'Version', + version_num, gpt_ini_data[version_loc.end():]) else: general_location = re.search(r'^\[General\]\r\n', @@ -4237,20 +4250,26 @@ def _write_regpol_data(data_to_write, version_nums = (0, 1) elif gpt_extension.lower() == 'gPCUserExtensionNames'.lower(): version_nums = (1, 0) - gpt_ini_data = "{0}{1}={2}\r\n{3}".format( + gpt_ini_data = '{0}{1}={2}\r\n{3}'.format( gpt_ini_data[general_location.start():general_location.end()], 'Version', - int("{0}{1}".format(six.text_type(version_nums[0]).zfill(4), six.text_type(version_nums[1]).zfill(4)), 16), + int("{0}{1}".format(six.text_type(version_nums[0]).zfill(4), + six.text_type(version_nums[1]).zfill(4)), + 16), gpt_ini_data[general_location.end():]) if gpt_ini_data: with salt.utils.files.fopen(gpt_ini_path, 'wb') as gpt_file: gpt_file.write(salt.utils.stringutils.to_bytes(gpt_ini_data)) + # TODO: This needs to be more specific except Exception as e: msg = 'An error occurred attempting to write to {0}, the exception was {1}'.format( gpt_ini_path, e) + log.exception(msg) raise CommandExecutionError(msg) + # TODO: This needs to be more specific except Exception as e: msg = 'An error occurred attempting to write to {0}, the exception was {1}'.format(policy_file_path, e) + log.exception(msg) raise CommandExecutionError(msg) @@ -4648,8 +4667,9 @@ def _writeAdminTemplateRegPolFile(admtemplate_data, policy_data.gpt_ini_path, policy_data.admx_registry_classes[registry_class]['gpt_extension_location'], policy_data.admx_registry_classes[registry_class]['gpt_extension_guid']) + # TODO: This needs to be more specific or removed except Exception: - log.error('Unhandled exception %s occurred while attempting to write Adm Template Policy File') + log.exception('Unhandled exception %s occurred while attempting to write Adm Template Policy File') return False return True @@ -4671,7 +4691,7 @@ def _getScriptSettingsFromIniFile(policy_info): _existingData = deserialize(_existingData.decode('utf-16-le').lstrip('\ufeff')) log.debug('Have deserialized data %s', _existingData) except Exception as error: - log.error('An error occurred attempting to deserialize data for %s', policy_info['Policy']) + log.exception('An error occurred attempting to deserialize data for %s', policy_info['Policy']) raise CommandExecutionError(error) if 'Section' in policy_info['ScriptIni'] and policy_info['ScriptIni']['Section'].lower() in [z.lower() for z in _existingData.keys()]: if 'SettingName' in policy_info['ScriptIni']: @@ -5540,8 +5560,10 @@ def set_(computer_policy=None, user_policy=None, _newModalSetData = dictupdate.update(_existingModalData, _modal_sets[_modal_set]) log.debug('NEW MODAL SET = %s', _newModalSetData) _ret = win32net.NetUserModalsSet(None, _modal_set, _newModalSetData) - except: + # TODO: This needs to be more specific + except Exception: msg = 'An unhandled exception occurred while attempting to set policy via NetUserModalSet' + log.exception(msg) raise CommandExecutionError(msg) if _admTemplateData: _ret = False From a42621c81721773df6d18ca24b6656122601cdd3 Mon Sep 17 00:00:00 2001 From: twangboy Date: Tue, 17 Jul 2018 14:59:36 -0600 Subject: [PATCH 02/14] Write file in normal mode --- salt/modules/win_lgpo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/modules/win_lgpo.py b/salt/modules/win_lgpo.py index 908f561fd9..c8b27bafdf 100644 --- a/salt/modules/win_lgpo.py +++ b/salt/modules/win_lgpo.py @@ -4258,8 +4258,8 @@ def _write_regpol_data(data_to_write, 16), gpt_ini_data[general_location.end():]) if gpt_ini_data: - with salt.utils.files.fopen(gpt_ini_path, 'wb') as gpt_file: - gpt_file.write(salt.utils.stringutils.to_bytes(gpt_ini_data)) + with salt.utils.files.fopen(gpt_ini_path, 'w') as gpt_file: + gpt_file.write(gpt_ini_data) # TODO: This needs to be more specific except Exception as e: msg = 'An error occurred attempting to write to {0}, the exception was {1}'.format( From b0157c215bbe1c2e7f0ef056276326e8d2d444c5 Mon Sep 17 00:00:00 2001 From: Lino Carrillo Date: Thu, 19 Jul 2018 22:01:13 -0400 Subject: [PATCH 03/14] Fix ext_pillar remote checkout using tag (pygit2) Fixes #38310 --- salt/utils/gitfs.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/salt/utils/gitfs.py b/salt/utils/gitfs.py index caf539080f..286657c72c 100644 --- a/salt/utils/gitfs.py +++ b/salt/utils/gitfs.py @@ -1534,9 +1534,9 @@ class Pygit2(GitProvider): elif tag_ref in refs: tag_obj = self.repo.revparse_single(tag_ref) - if not isinstance(tag_obj, pygit2.Tag): + if not isinstance(tag_obj, pygit2.Commit): log.error( - '%s does not correspond to pygit2.Tag object', + '%s does not correspond to pygit2.Commit object', tag_ref ) else: @@ -1556,9 +1556,10 @@ class Pygit2(GitProvider): exc_info=True ) return None + log.debug('SHA of tag %s: %s', tgt_ref, tag_sha) - if head_sha != target_sha: - if not _perform_checkout(local_ref, branch=False): + if head_sha != tag_sha: + if not _perform_checkout(tag_ref, branch=False): return None # Return the relative root, if present From d3b7f2cb18359b039374c8073749a5930239e592 Mon Sep 17 00:00:00 2001 From: Ch3LL Date: Fri, 27 Jul 2018 09:36:23 -0400 Subject: [PATCH 04/14] Remove fake su used in integration tests --- tests/integration/mockbin/su | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100755 tests/integration/mockbin/su diff --git a/tests/integration/mockbin/su b/tests/integration/mockbin/su deleted file mode 100755 index b442c1baab..0000000000 --- a/tests/integration/mockbin/su +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# "Fake" su command -# -# Just executes the command without changing effective uid. Used in integration -# tests. -while true; do - shift - test "x$1" == "x-c" && break - test "x$1" == "x" && break -done -shift -exec /bin/bash -c "$@" From 41e3d17f29dc7ca962bdb8d436691d07a86a9254 Mon Sep 17 00:00:00 2001 From: Ch3LL Date: Fri, 27 Jul 2018 15:21:52 -0400 Subject: [PATCH 05/14] Use brew path from which cmd in mac_brew module --- salt/modules/mac_brew.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/salt/modules/mac_brew.py b/salt/modules/mac_brew.py index aa2aa3b8a3..7dcaf9c633 100644 --- a/salt/modules/mac_brew.py +++ b/salt/modules/mac_brew.py @@ -48,7 +48,7 @@ def _list_taps(): ''' List currently installed brew taps ''' - cmd = 'brew tap' + cmd = 'tap' return _call_brew(cmd)['stdout'].splitlines() @@ -60,7 +60,7 @@ def _tap(tap, runas=None): if tap in _list_taps(): return True - cmd = 'brew tap {0}'.format(tap) + cmd = 'tap {0}'.format(tap) try: _call_brew(cmd) except CommandExecutionError: @@ -85,6 +85,7 @@ def _call_brew(cmd, failhard=True): ''' user = __salt__['file.get_user'](_homebrew_bin()) runas = user if user != __opts__['user'] else None + cmd = '{} {}'.format(salt.utils.path.which('brew'), cmd) result = __salt__['cmd.run_all'](cmd, runas=runas, output_loglevel='trace', @@ -121,7 +122,7 @@ def list_pkgs(versions_as_list=False, **kwargs): __salt__['pkg_resource.stringify'](ret) return ret - cmd = 'brew list --versions' + cmd = 'list --versions' ret = {} out = _call_brew(cmd)['stdout'] for line in out.splitlines(): @@ -230,7 +231,7 @@ def remove(name=None, pkgs=None, **kwargs): targets = [x for x in pkg_params if x in old] if not targets: return {} - cmd = 'brew uninstall {0}'.format(' '.join(targets)) + cmd = 'uninstall {0}'.format(' '.join(targets)) out = _call_brew(cmd) if out['retcode'] != 0 and out['stderr']: @@ -263,7 +264,7 @@ def refresh_db(): ''' # Remove rtag file to keep multiple refreshes from happening in pkg states salt.utils.pkg.clear_rtag(__opts__) - cmd = 'brew update' + cmd = 'update' if _call_brew(cmd)['retcode']: log.error('Failed to update') return False @@ -286,7 +287,7 @@ def _info(*pkgs): Caveat: If one of the packages does not exist, no packages will be included in the output. ''' - cmd = 'brew info --json=v1 {0}'.format(' '.join(pkgs)) + cmd = 'info --json=v1 {0}'.format(' '.join(pkgs)) brew_result = _call_brew(cmd) if brew_result['retcode']: log.error('Failed to get info about packages: %s', @@ -382,9 +383,9 @@ def install(name=None, pkgs=None, taps=None, options=None, **kwargs): _tap(tap) if options: - cmd = 'brew install {0} {1}'.format(formulas, ' '.join(options)) + cmd = 'install {0} {1}'.format(formulas, ' '.join(options)) else: - cmd = 'brew install {0}'.format(formulas) + cmd = 'install {0}'.format(formulas) out = _call_brew(cmd) if out['retcode'] != 0 and out['stderr']: @@ -418,7 +419,7 @@ def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613 if refresh: refresh_db() - res = _call_brew(['brew', 'outdated', '--json=v1']) + res = _call_brew('outdated --json=v1') ret = {} try: @@ -478,7 +479,7 @@ def upgrade(refresh=True): if salt.utils.data.is_true(refresh): refresh_db() - result = _call_brew('brew upgrade', failhard=False) + result = _call_brew('upgrade', failhard=False) __context__.pop('pkg.list_pkgs', None) new = list_pkgs() ret = salt.utils.data.compare_dicts(old, new) From c379b7e4edb5c4de1e3eccac2edd6b5fbcceab8a Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Sun, 29 Jul 2018 21:44:46 +0200 Subject: [PATCH 06/14] Get rid of global variable --- salt/modules/smbios.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/salt/modules/smbios.py b/salt/modules/smbios.py index c8a0e54a5c..cc305399e7 100644 --- a/salt/modules/smbios.py +++ b/salt/modules/smbios.py @@ -327,7 +327,11 @@ def _dmidecoder(args=None): ''' Call DMIdecode ''' - if args is None: - return salt.modules.cmdmod._run_quiet(DMIDECODER) + dmidecoder = salt.utils.path.which_bin(['dmidecode', 'smbios']) + + if not args: + out = salt.modules.cmdmod._run_quiet(dmidecoder) else: - return salt.modules.cmdmod._run_quiet('{0} {1}'.format(DMIDECODER, args)) + out = salt.modules.cmdmod._run_quiet('{0} {1}'.format(dmidecoder, args)) + + return out From 1031e0644355da4fe05d065feb7eefc31a9c1321 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Sun, 29 Jul 2018 21:45:08 +0200 Subject: [PATCH 07/14] Remove unnecessary code --- salt/modules/smbios.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/salt/modules/smbios.py b/salt/modules/smbios.py index cc305399e7..5ee64ebfb4 100644 --- a/salt/modules/smbios.py +++ b/salt/modules/smbios.py @@ -29,18 +29,13 @@ from salt.ext.six.moves import zip # pylint: disable=import-error,redefined-bui log = logging.getLogger(__name__) -DMIDECODER = salt.utils.path.which_bin(['dmidecode', 'smbios']) - def __virtual__(): ''' Only work when dmidecode is installed. ''' - if DMIDECODER is None: - log.debug('SMBIOS: neither dmidecode nor smbios found!') - return (False, 'The smbios execution module failed to load: neither dmidecode nor smbios in the path.') - else: - return True + return (bool(salt.utils.path.which_bin(['dmidecode', 'smbios'])), + 'The smbios execution module failed to load: neither dmidecode nor smbios in the path.') def get(string, clean=True): From fd77f760ee372a5949c05c712d06a975f79a7763 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Sun, 29 Jul 2018 21:45:40 +0200 Subject: [PATCH 08/14] Rephrase explanatory comment --- salt/modules/smbios.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/salt/modules/smbios.py b/salt/modules/smbios.py index 5ee64ebfb4..1c9de30d6d 100644 --- a/salt/modules/smbios.py +++ b/salt/modules/smbios.py @@ -81,8 +81,7 @@ def get(string, clean=True): val = _dmidecoder('-s {0}'.format(string)).strip() - # Sometimes dmidecode delivers comments in strings. - # Don't. + # Cleanup possible comments in strings. val = '\n'.join([v for v in val.split('\n') if not v.startswith('#')]) # handle missing /dev/mem From b1b2e9c222edbe0c32bec8a1e6456cc2ba5d8060 Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Sun, 29 Jul 2018 21:46:21 +0200 Subject: [PATCH 09/14] Remove multiple returns and combine logic to just one clause --- salt/modules/smbios.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/salt/modules/smbios.py b/salt/modules/smbios.py index 1c9de30d6d..fa01980d63 100644 --- a/salt/modules/smbios.py +++ b/salt/modules/smbios.py @@ -83,13 +83,10 @@ def get(string, clean=True): # Cleanup possible comments in strings. val = '\n'.join([v for v in val.split('\n') if not v.startswith('#')]) + if clean or val.startswith('/dev/mem') or not _dmi_isclean(string, val): + val = None - # handle missing /dev/mem - if val.startswith('/dev/mem'): - return None - - if not clean or _dmi_isclean(string, val): - return val + return val def records(rec_type=None, fields=None, clean=True): From b00ee5feef0567b78e1eeb8ee47fb7931fb134ca Mon Sep 17 00:00:00 2001 From: Bo Maryniuk Date: Sun, 29 Jul 2018 22:06:32 +0200 Subject: [PATCH 10/14] Update clean clause --- salt/modules/smbios.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/smbios.py b/salt/modules/smbios.py index fa01980d63..ec7d6497c6 100644 --- a/salt/modules/smbios.py +++ b/salt/modules/smbios.py @@ -83,7 +83,7 @@ def get(string, clean=True): # Cleanup possible comments in strings. val = '\n'.join([v for v in val.split('\n') if not v.startswith('#')]) - if clean or val.startswith('/dev/mem') or not _dmi_isclean(string, val): + if val.startswith('/dev/mem') or clean and not _dmi_isclean(string, val): val = None return val From 9b462394b2a96d3b514460e01f0ccc8ee87ba6f8 Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Tue, 31 Jul 2018 01:52:24 +0000 Subject: [PATCH 11/14] Fix unicode directory listing on py2 --- salt/utils/path.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/salt/utils/path.py b/salt/utils/path.py index 725fe5c828..ed2ebe152a 100644 --- a/salt/utils/path.py +++ b/salt/utils/path.py @@ -406,5 +406,8 @@ def os_walk(top, *args, **kwargs): This is a helper than ensures that all paths returned from os.walk are unicode. ''' - for item in os.walk(salt.utils.stringutils.to_str(top), *args, **kwargs): + top_query = salt.utils.stringutils.to_str(top) + if salt.utils.platform.is_windows() and six.PY2: + top_query = top + for item in os.walk(top_query, *args, **kwargs): yield salt.utils.data.decode(item, preserve_tuples=True) From 02d09c6281d9d98602939d6ceb997a5f9e1f206e Mon Sep 17 00:00:00 2001 From: sizgiyaev Date: Tue, 31 Jul 2018 10:34:22 +0300 Subject: [PATCH 12/14] Fixed: added additional return code 200 for succeeded api request --- salt/states/vault.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/states/vault.py b/salt/states/vault.py index 238bbe685c..dd28957c7f 100644 --- a/salt/states/vault.py +++ b/salt/states/vault.py @@ -73,7 +73,7 @@ def _create_new_policy(name, rules): payload = {'rules': rules} url = "v1/sys/policy/{0}".format(name) response = __utils__['vault.make_request']('PUT', url, json=payload) - if response.status_code != 204: + if response.status_code not in [200, 204]: return { 'name': name, 'changes': {}, @@ -108,7 +108,7 @@ def _handle_existing_policy(name, new_rules, existing_rules): url = "v1/sys/policy/{0}".format(name) response = __utils__['vault.make_request']('PUT', url, json=payload) - if response.status_code != 204: + if response.status_code not in [200, 204]: return { 'name': name, 'changes': {}, From 47e158b9f0c5ac88ca355d8c462986c0f5d39022 Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Tue, 31 Jul 2018 09:14:27 -0700 Subject: [PATCH 13/14] Optomize if statement --- salt/utils/path.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/salt/utils/path.py b/salt/utils/path.py index ed2ebe152a..b1d601e464 100644 --- a/salt/utils/path.py +++ b/salt/utils/path.py @@ -406,8 +406,9 @@ def os_walk(top, *args, **kwargs): This is a helper than ensures that all paths returned from os.walk are unicode. ''' - top_query = salt.utils.stringutils.to_str(top) - if salt.utils.platform.is_windows() and six.PY2: + if six.PY2 and salt.utils.platform.is_windows(): top_query = top + else: + top_query = salt.utils.stringutils.to_str(top) for item in os.walk(top_query, *args, **kwargs): yield salt.utils.data.decode(item, preserve_tuples=True) From e2bdf7fb92846373b75f6665b77c38cc7b047840 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Tue, 31 Jul 2018 12:50:28 -0500 Subject: [PATCH 14/14] Update file.blockreplace docs to reflect changed functionality See https://github.com/saltstack/salt/issues/48695#issuecomment-407414810 --- salt/modules/file.py | 8 ++++---- salt/states/file.py | 22 +++++++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/salt/modules/file.py b/salt/modules/file.py index 7e85907cbb..ddab2cbe27 100644 --- a/salt/modules/file.py +++ b/salt/modules/file.py @@ -2477,10 +2477,10 @@ def blockreplace(path, final output marker_end - The line content identifying a line as the end of the content block. - Note that the whole line containing this marker will be considered, so - whitespace or extra content before or after the marker is included in - final output + The line content identifying the end of the content block. As of + versions 2017.7.5 and 2018.3.1, everything up to the text matching the + marker will be replaced, so it's important to ensure that your marker + includes the beginning of the text you wish to replace. content The content to be used between the two lines identified by marker_start diff --git a/salt/states/file.py b/salt/states/file.py index 78f1cfbd2b..0bae0b6507 100644 --- a/salt/states/file.py +++ b/salt/states/file.py @@ -4346,9 +4346,15 @@ def blockreplace( A block of content delimited by comments can help you manage several lines entries without worrying about old entries removal. This can help you maintaining an un-managed file containing manual edits. - Note: this function will store two copies of the file in-memory - (the original version and the edited version) in order to detect changes - and only edit the targeted file if necessary. + + .. note:: + This function will store two copies of the file in-memory (the original + version and the edited version) in order to detect changes and only + edit the targeted file if necessary. + + Additionally, you can use :py:func:`file.accumulated + ` and target this state. All accumulated + data dictionaries' content will be added in the content block. name Filesystem path to the file to be edited @@ -4360,12 +4366,10 @@ def blockreplace( final output marker_end - The line content identifying a line as the end of the content block. - Note that the whole line containing this marker will be considered, so - whitespace or extra content before or after the marker is included in - final output. Note: you can use file.accumulated and target this state. - All accumulated data dictionaries content will be added as new lines in - the content + The line content identifying the end of the content block. As of + versions 2017.7.5 and 2018.3.1, everything up to the text matching the + marker will be replaced, so it's important to ensure that your marker + includes the beginning of the text you wish to replace. content The content to be used between the two lines identified by