mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge branch '2018.3' into isbm-log-level-names-fix-2
This commit is contained in:
commit
a63686180d
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
@ -86,16 +81,12 @@ 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('#')])
|
||||
if val.startswith('/dev/mem') or clean and 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):
|
||||
@ -327,7 +318,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
|
||||
|
@ -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))
|
||||
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(
|
||||
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
|
||||
|
@ -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
|
||||
<salt.states.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
|
||||
|
@ -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': {},
|
||||
|
@ -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
|
||||
|
@ -406,5 +406,9 @@ 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):
|
||||
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)
|
||||
|
@ -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 "$@"
|
Loading…
Reference in New Issue
Block a user