Update all other calls to "cmp" function

Some should just use the new utility function, while others can just
be compared more directly.
This commit is contained in:
rallytime 2017-08-07 15:38:39 -04:00
parent 5605104285
commit d707f94863
6 changed files with 17 additions and 7 deletions

View file

@ -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 ' \

View file

@ -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

View file

@ -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'

View file

@ -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:

View file

@ -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

View file

@ -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',