Skip to content

Commit

Permalink
Merge pull request #50438 from rallytime/merge-develop
Browse files Browse the repository at this point in the history
[develop] Merge forward from fluorine to develop
  • Loading branch information
rallytime authored Nov 12, 2018
2 parents bf8b9d7 + 1af68b8 commit 8bebb19
Show file tree
Hide file tree
Showing 16 changed files with 888 additions and 50 deletions.
6 changes: 6 additions & 0 deletions salt/beacons/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,3 +435,9 @@ def disable_beacon(self, name):
tag='/salt/minion/minion_beacon_disabled_complete')

return True

def reset(self):
'''
Reset the beacons to defaults
'''
self.opts['beacons'] = {}
2 changes: 2 additions & 0 deletions salt/minion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,8 @@ def manage_beacons(self, tag, data):
self.beacons.list_available_beacons()
elif func == 'validate_beacon':
self.beacons.validate_beacon(name, beacon_data)
elif func == 'reset':
self.beacons.reset()

def environ_setenv(self, tag, data):
'''
Expand Down
39 changes: 37 additions & 2 deletions salt/modules/beacons.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def add(name, beacon_data, **kwargs):
.. code-block:: bash
salt '*' beacons.add ps "[{'salt-master': 'stopped', 'apache2': 'stopped'}]"
salt '*' beacons.add ps "[{'salt-master': 'stopped'}, {'apache2': 'stopped'}]"
'''
ret = {'comment': 'Failed to add beacon {0}.'.format(name),
Expand Down Expand Up @@ -215,7 +215,7 @@ def modify(name, beacon_data, **kwargs):
.. code-block:: bash
salt '*' beacons.modify ps "[{'salt-master': 'stopped', 'apache2': 'stopped'}]"
salt '*' beacons.modify ps "[{'salt-master': 'stopped'}, {'apache2': 'stopped'}]"
'''

ret = {'comment': '',
Expand Down Expand Up @@ -579,3 +579,38 @@ def disable_beacon(name, **kwargs):
# Effectively a no-op, since we can't really return without an event system
ret['comment'] = 'Event module not available. Beacon disable job failed.'
return ret


def reset(**kwargs):
'''
Resest beacon configuration on the minion
CLI Example:
.. code-block:: bash
salt '*' beacons.reset
'''

ret = {'comment': [],
'result': True}

if 'test' in kwargs and kwargs['test']:
ret['comment'] = 'Beacons would be reset.'
else:
try:
eventer = salt.utils.event.get_event('minion', opts=__opts__)
res = __salt__['event.fire']({'func': 'reset'}, 'manage_beacons')
if res:
event_ret = eventer.get_event(tag='/salt/minion/minion_beacon_reset_complete', wait=30)
if event_ret and event_ret['complete']:
ret['result'] = True
ret['comment'] = 'Beacon configuration reset.'
else:
ret['result'] = False
ret['comment'] = event_ret['comment']
return ret
except KeyError:
# Effectively a no-op, since we can't really return without an event system
ret['comment'] = 'Event module not available. Beacon disable job failed.'
return ret
54 changes: 41 additions & 13 deletions salt/modules/win_lgpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3196,8 +3196,8 @@ def _sidConversion(cls, val, **kwargs):
userSid = '{0}'.format(userSid[0])
# TODO: This needs to be more specific
except Exception:
log.exception('Handle this explicitly')
userSid = win32security.ConvertSidToStringSid(_sid)
log.warning('Unable to convert SID "%s" to a friendly name. The SID will be disaplayed instead of a user/group name.', userSid)
usernames.append(userSid)
return usernames

Expand Down Expand Up @@ -3780,9 +3780,9 @@ def _getAdmlPresentationRefId(adml_data, ref_id):
else:
if etree.QName(p_item.tag).localname == 'text':
if prepended_text:
prepended_text = ' '.join([prepended_text, p_item.text.rstrip()])
prepended_text = ' '.join((text for text in (prepended_text, getattr(p_item, 'text', '').rstrip()) if text))
else:
prepended_text = p_item.text.rstrip()
prepended_text = getattr(p_item, 'text', '').rstrip()
else:
prepended_text = ''
if prepended_text.endswith('.'):
Expand Down Expand Up @@ -4181,7 +4181,7 @@ def _processValueItem(element, reg_key, reg_valuename, policy, parent_element,
encoded_semicolon,
chr(registry.vtype[this_vtype]).encode('utf-32-le'),
encoded_semicolon,
chr(len(' {0}'.format(chr(0)).encode('utf-16-le'))).encode('utf-32-le'),
six.unichr(len(' {0}'.format(chr(0)).encode('utf-16-le'))).encode('utf-32-le'),
encoded_semicolon,
' '.encode('utf-16-le'),
encoded_null,
Expand Down Expand Up @@ -4242,7 +4242,7 @@ def _processValueItem(element, reg_key, reg_valuename, policy, parent_element,
encoded_semicolon,
chr(registry.vtype[this_vtype]).encode('utf-32-le'),
encoded_semicolon,
chr(len(' {0}'.format(chr(0)))).encode('utf-32-le'),
six.unichr(len(' {0}'.format(chr(0)).encode('utf-16-le'))).encode('utf-32-le'),
encoded_semicolon,
' '.encode('utf-16-le'),
encoded_null,
Expand Down Expand Up @@ -4870,7 +4870,9 @@ def _regexSearchKeyValueCombo(policy_data, policy_regpath, policy_regkey):
b'\00;'])
match = re.search(_thisSearch, policy_data, re.IGNORECASE)
if match:
return policy_data[match.start():(policy_data.index(']', match.end())) + 1]
# add 2 so we get the ']' and the \00
# to return the full policy entry
return policy_data[match.start():(policy_data.index(b']', match.end())) + 2]

return None

Expand Down Expand Up @@ -5368,8 +5370,8 @@ def _writeAdminTemplateRegPolFile(admtemplate_data,
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.exception('Unhandled exception %s occurred while attempting to write Adm Template Policy File')
except Exception as e:
log.exception('Unhandled exception %s occurred while attempting to write Adm Template Policy File', e)
return False
return True

Expand Down Expand Up @@ -5511,12 +5513,14 @@ def _lookup_admin_template(policy_name,
suggested_policies = ''
adml_to_remove = []
if len(adml_search_results) > 1:
log.debug('multiple ADML entries found matching the policy name %s', policy_name)
multiple_adml_entries = True
for adml_search_result in adml_search_results:
if not getattr(adml_search_result, 'text', '').strip() == policy_name:
adml_to_remove.append(adml_search_result)
else:
if hierarchy:
log.debug('we have hierarchy of %s', hierarchy)
display_name_searchval = '$({0}.{1})'.format(
adml_search_result.tag.split('}')[1],
adml_search_result.attrib['id'])
Expand All @@ -5526,20 +5530,41 @@ def _lookup_admin_template(policy_name,
display_name_searchval,
policy_class)
admx_results = []
admx_search_results = admx_policy_definitions.xpath(policy_search_string, namespaces=adml_search_result.nsmap)
for search_result in admx_search_results:
these_admx_search_results = admx_policy_definitions.xpath(policy_search_string, namespaces=adml_search_result.nsmap)
if not these_admx_search_results:
log.debug('No admx was found for the adml entry %s, it will be removed', display_name_searchval)
adml_to_remove.append(adml_search_result)
for search_result in these_admx_search_results:
log.debug('policy_name == %s', policy_name)
this_hierarchy = _build_parent_list(
policy_definition=search_result,
return_full_policy_names=True,
adml_language=adml_language)
this_hierarchy.reverse()
if hierarchy != this_hierarchy:
adml_to_remove.append(adml_search_result)
msg = 'hierarchy %s does not match this item\'s hierarchy of %s'
log.debug(msg, hierarchy, this_hierarchy)
if len(these_admx_search_results) == 1:
log.debug('only 1 admx was found and it does not match this adml, it is safe to remove from the list')
adml_to_remove.append(adml_search_result)
else:
log.debug('hierarchy %s matches item\'s hierarchy of %s', hierarchy, this_hierarchy)
log.debug('search_result %s added to results', search_result)
admx_results.append(search_result)
if len(admx_results) == 1:
admx_search_results = admx_results
admx_search_results.append(admx_results[0])
else:
# verify the ADMX correlated to this ADML is in the same class
# that we are looking for
display_name_searchval = '$({0}.{1})'.format(
adml_search_result.tag.split('}')[1],
adml_search_result.attrib['id'])
these_admx_search_results = ADMX_DISPLAYNAME_SEARCH_XPATH(
admx_policy_definitions,
display_name=display_name_searchval,
registry_class=policy_class)
if not these_admx_search_results:
adml_to_remove.append(adml_search_result)
for adml in adml_to_remove:
if adml in adml_search_results:
adml_search_results.remove(adml)
Expand All @@ -5554,12 +5579,15 @@ def _lookup_admin_template(policy_name,
adml_search_result.attrib['id'])
log.debug('searching for displayName == %s', display_name_searchval)
if not admx_search_results:
log.debug('search for an admx entry matching display_name %s and registry_class %s', display_name_searchval, policy_class)
admx_search_results = ADMX_DISPLAYNAME_SEARCH_XPATH(
admx_policy_definitions,
display_name=display_name_searchval,
registry_class=policy_class)
if admx_search_results:
if len(admx_search_results) == 1 or hierarchy and not multiple_adml_entries:
log.debug('processing admx_search_results of {0}'.format(admx_search_results))
log.debug('multiple_adml_entries is {0}'.format(multiple_adml_entries))
if (len(admx_search_results) == 1 or hierarchy) and not multiple_adml_entries:
found = False
for search_result in admx_search_results:
found = False
Expand Down
9 changes: 7 additions & 2 deletions salt/runners/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def key_regen():
return msg


def down(removekeys=False, tgt='*', tgt_type='glob'):
def down(removekeys=False, tgt='*', tgt_type='glob', timeout=None, gather_job_timeout=None):
'''
.. versionchanged:: 2017.7.0
The ``expr_form`` argument has been renamed to ``tgt_type``, earlier
Expand All @@ -166,7 +166,12 @@ def down(removekeys=False, tgt='*', tgt_type='glob'):
salt-run manage.down tgt="webservers" tgt_type="nodegroup"
'''
ret = status(output=False, tgt=tgt, tgt_type=tgt_type).get('down', [])
ret = status(output=False,
tgt=tgt,
tgt_type=tgt_type,
timeout=timeout,
gather_job_timeout=gather_job_timeout
).get('down', [])
for minion in ret:
if removekeys:
wheel = salt.wheel.Wheel(__opts__)
Expand Down
8 changes: 7 additions & 1 deletion salt/states/beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
'''
from __future__ import absolute_import, print_function, unicode_literals

# Import Salt libs
from salt.ext import six

import logging
log = logging.getLogger(__name__)


def present(name,
save=False,
Expand All @@ -54,7 +60,7 @@ def present(name,
'comment': []}

current_beacons = __salt__['beacons.list'](return_yaml=False)
beacon_data = [kwargs]
beacon_data = [{k: v} for k, v in six.iteritems(kwargs)]

if name in current_beacons:

Expand Down
4 changes: 2 additions & 2 deletions salt/states/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3425,7 +3425,7 @@ def directory(name,
# NOTE: Should this be enough to stop the whole check altogether?
if recurse_set:
if 'user' in recurse_set:
if user:
if user or isinstance(user, int):
uid = __salt__['file.user_to_uid'](user)
# file.user_to_uid returns '' if user does not exist. Above
# check for user is not fatal, so we need to be sure user
Expand All @@ -3443,7 +3443,7 @@ def directory(name,
else:
user = None
if 'group' in recurse_set:
if group:
if group or isinstance(group, int):
gid = __salt__['file.group_to_gid'](group)
# As above with user, we need to make sure group exists.
if isinstance(gid, six.string_types):
Expand Down
2 changes: 1 addition & 1 deletion salt/states/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def swap(name, persist=True, config='/etc/fstab'):
else:
fstab_data = __salt__['mount.fstab'](config)
if __opts__['test']:
if name not in fstab_data:
if name not in fstab_data and name not in [fstab_data[item]['device'] for item in fstab_data]:
ret['result'] = None
if name in on_:
ret['comment'] = ('Swap {0} is set to be added to the '
Expand Down
6 changes: 3 additions & 3 deletions salt/utils/atomicfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def close(self):
return
self._fh.close()
if os.path.isfile(self._filename):
shutil.copymode(self._filename, self._tmp_filename)
if salt.utils.win_dacl.HAS_WIN32:
owner = salt.utils.win_dacl.get_owner(self._filename)
salt.utils.win_dacl.set_owner(self._tmp_filename, owner)
salt.utils.win_dacl.copy_security(
source=self._filename, target=self._tmp_filename)
else:
shutil.copymode(self._filename, self._tmp_filename)
st = os.stat(self._filename)
os.chown(self._tmp_filename, st.st_uid, st.st_gid)
atomic_rename(self._tmp_filename, self._filename)
Expand Down
Loading

0 comments on commit 8bebb19

Please sign in to comment.