mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #42782 from rallytime/fix-42697
Add a cmp compatibility function utility
This commit is contained in:
commit
135f9522d0
8 changed files with 31 additions and 8 deletions
|
@ -22,6 +22,7 @@ from salt.ext.six.moves.urllib.request import urlopen as _urlopen # pylint: dis
|
|||
# Import salt libs
|
||||
import salt.key
|
||||
import salt.utils
|
||||
import salt.utils.compat
|
||||
import salt.utils.minions
|
||||
import salt.client
|
||||
import salt.client.ssh
|
||||
|
@ -669,7 +670,7 @@ def versions():
|
|||
ver_diff = -2
|
||||
else:
|
||||
minion_version = salt.version.SaltStackVersion.parse(minions[minion])
|
||||
ver_diff = cmp(minion_version, master_version)
|
||||
ver_diff = salt.utils.compat.cmp(minion_version, master_version)
|
||||
|
||||
if ver_diff not in version_status:
|
||||
version_status[ver_diff] = {}
|
||||
|
|
|
@ -85,7 +85,7 @@ def _check_for_changes(entity_type, ret, existing, modified):
|
|||
if 'generation' in existing['content'].keys():
|
||||
del existing['content']['generation']
|
||||
|
||||
if cmp(modified['content'], existing['content']) == 0:
|
||||
if modified['content'] == existing['content']:
|
||||
ret['comment'] = '{entity_type} is currently enforced to the desired state. No changes made.'.format(entity_type=entity_type)
|
||||
else:
|
||||
ret['comment'] = '{entity_type} was enforced to the desired state. Note: Only parameters specified ' \
|
||||
|
@ -94,7 +94,7 @@ def _check_for_changes(entity_type, ret, existing, modified):
|
|||
ret['changes']['new'] = modified['content']
|
||||
|
||||
else:
|
||||
if cmp(modified, existing) == 0:
|
||||
if modified == existing:
|
||||
ret['comment'] = '{entity_type} is currently enforced to the desired state. No changes made.'.format(entity_type=entity_type)
|
||||
else:
|
||||
ret['comment'] = '{entity_type} was enforced to the desired state. Note: Only parameters specified ' \
|
||||
|
|
|
@ -43,6 +43,9 @@ from __future__ import absolute_import
|
|||
import logging
|
||||
import json
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.compat
|
||||
|
||||
# Import 3rd party libs
|
||||
try:
|
||||
from salt._compat import ElementTree as ET
|
||||
|
@ -158,7 +161,7 @@ def present(name, template_body=None, template_url=None, parameters=None, notifi
|
|||
template = template['GetTemplateResponse']['GetTemplateResult']['TemplateBody'].encode('ascii', 'ignore')
|
||||
template = json.loads(template)
|
||||
_template_body = json.loads(template_body)
|
||||
compare = cmp(template, _template_body)
|
||||
compare = salt.utils.compat.cmp(template, _template_body)
|
||||
if compare != 0:
|
||||
log.debug('Templates are not the same. Compare value is {0}'.format(compare))
|
||||
# At this point we should be able to run update safely since we already validated the template
|
||||
|
|
|
@ -8,6 +8,12 @@ For documentation on setting up the cisconso proxy minion look in the documentat
|
|||
for :mod:`salt.proxy.cisconso <salt.proxy.cisconso>`.
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.compat
|
||||
|
||||
|
||||
def __virtual__():
|
||||
return 'cisconso.set_data_value' in __salt__
|
||||
|
@ -53,7 +59,7 @@ def value_present(name, datastore, path, config):
|
|||
|
||||
existing = __salt__['cisconso.get_data'](datastore, path)
|
||||
|
||||
if cmp(existing, config):
|
||||
if salt.utils.compat.cmp(existing, config):
|
||||
ret['result'] = True
|
||||
ret['comment'] = 'Config is already set'
|
||||
|
||||
|
|
|
@ -206,7 +206,7 @@ def sections_present(name, sections=None, separator='='):
|
|||
ret['result'] = False
|
||||
ret['comment'] = "{0}".format(err)
|
||||
return ret
|
||||
if cmp(dict(sections[section]), cur_section) == 0:
|
||||
if dict(sections[section]) == cur_section:
|
||||
ret['comment'] += 'Section unchanged {0}.\n'.format(section)
|
||||
continue
|
||||
elif cur_section:
|
||||
|
|
|
@ -84,7 +84,7 @@ def present(name, **kwargs):
|
|||
for right in kwargs['rights']:
|
||||
for key in right:
|
||||
right[key] = str(right[key])
|
||||
if cmp(sorted(kwargs['rights']), sorted(usergroup['rights'])) != 0:
|
||||
if sorted(kwargs['rights']) != sorted(usergroup['rights']):
|
||||
update_rights = True
|
||||
else:
|
||||
update_rights = True
|
||||
|
|
|
@ -58,6 +58,7 @@ import salt.config
|
|||
import salt.loader
|
||||
import salt.template
|
||||
import salt.utils
|
||||
import salt.utils.compat
|
||||
import salt.utils.event
|
||||
from salt.utils import vt
|
||||
from salt.utils.nb_popen import NonBlockingPopen
|
||||
|
@ -3041,7 +3042,7 @@ def diff_node_cache(prov_dir, node, new_data, opts):
|
|||
# Perform a simple diff between the old and the new data, and if it differs,
|
||||
# return both dicts.
|
||||
# TODO: Return an actual diff
|
||||
diff = cmp(new_data, cache_data)
|
||||
diff = salt.utils.compat.cmp(new_data, cache_data)
|
||||
if diff != 0:
|
||||
fire_event(
|
||||
'event',
|
||||
|
|
|
@ -46,3 +46,15 @@ def deepcopy_bound(name):
|
|||
finally:
|
||||
copy._deepcopy_dispatch = pre_dispatch
|
||||
return ret
|
||||
|
||||
|
||||
def cmp(x, y):
|
||||
'''
|
||||
Compatibility helper function to replace the ``cmp`` function from Python 2. The
|
||||
``cmp`` function is no longer available in Python 3.
|
||||
|
||||
cmp(x, y) -> integer
|
||||
|
||||
Return negative if x<y, zero if x==y, positive if x>y.
|
||||
'''
|
||||
return (x > y) - (x < y)
|
||||
|
|
Loading…
Add table
Reference in a new issue