mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Cmp python3 compat (#25008)
* Use double-quotes for expect integration tests * Cast user input to string for expect integration tests * Remove usage of cmp() for python3 compatibility - Add code smell test to look for cmp usage - Fixes #24756
This commit is contained in:
parent
64f63a3cac
commit
5c43bd3bae
5 changed files with 20 additions and 4 deletions
|
@ -1755,7 +1755,8 @@ def present(manager, containers, count, name):
|
|||
if delta < 0:
|
||||
# If both running and stopped containers exist, remove
|
||||
# stopped containers first.
|
||||
containers.deployed.sort(lambda cx, cy: cmp(is_running(cx), is_running(cy)))
|
||||
# Use key param for python 2/3 compatibility.
|
||||
containers.deployed.sort(key=is_running)
|
||||
|
||||
to_stop = []
|
||||
to_remove = []
|
||||
|
|
|
@ -478,7 +478,7 @@ class Ntp(object):
|
|||
peer_type=ntp_dict['type'], prefer=is_preferred, key_id=key_id)
|
||||
exp_ntp_cfg = dict(vpn_name=self.vpn_name, source_int=self.interface.lower(), address=self.address,
|
||||
peer_type=self.peer_type, prefer=self.is_preferred, key_id=self.key_id)
|
||||
if cmp(cur_ntp_cfg, exp_ntp_cfg) == 0:
|
||||
if cur_ntp_cfg == exp_ntp_cfg:
|
||||
self.conf_exsit = True
|
||||
|
||||
vpn_name = ntp_dict['vpnName']
|
||||
|
|
|
@ -402,7 +402,7 @@ class RollBack(object):
|
|||
self.module.fail_json(
|
||||
msg='Error: Commit label which should not start with a number.')
|
||||
if len(self.label.replace(' ', '')) == 1:
|
||||
if cmp(self.label, '-') == 0:
|
||||
if self.label == '-':
|
||||
self.module.fail_json(
|
||||
msg='Error: Commit label which should not be "-"')
|
||||
if len(self.label.replace(' ', '')) < 1 or len(self.label) > 256:
|
||||
|
|
|
@ -568,7 +568,7 @@ class ACMEClient(object):
|
|||
for index, cur_auth in enumerate(self.authorizations):
|
||||
if (cur_auth['uri'] == auth['uri']):
|
||||
# does the auth parameter contain updated data?
|
||||
if cmp(cur_auth, auth) != 0:
|
||||
if cur_auth != auth:
|
||||
# yes, update our current authorization list
|
||||
self.authorizations[index] = auth
|
||||
return True
|
||||
|
|
15
test/sanity/code-smell/no-list-cmp.sh
Executable file
15
test/sanity/code-smell/no-list-cmp.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
CMP_USERS=$(grep -rI ' cmp[^a-zA-Z0-9_]' . \
|
||||
--exclude-dir .tox \
|
||||
| grep -v \
|
||||
-e lib/ansible/module_utils/six/_six.py \
|
||||
-e test/sanity/code-smell/no-list-cmp.sh
|
||||
)
|
||||
|
||||
if [ "${CMP_USERS}" ]; then
|
||||
echo 'cmp has been removed in python3. Alternatives:'
|
||||
echo ' http://python3porting.com/preparing.html#when-sorting-use-key-instead-of-cmp'
|
||||
echo "${CMP_USERS}"
|
||||
exit 1
|
||||
fi
|
Loading…
Reference in a new issue