diff --git a/lib/ansible/modules/cloud/docker/_docker.py b/lib/ansible/modules/cloud/docker/_docker.py index 3512e1ed519..cba5c29fc52 100644 --- a/lib/ansible/modules/cloud/docker/_docker.py +++ b/lib/ansible/modules/cloud/docker/_docker.py @@ -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 = [] diff --git a/lib/ansible/modules/network/cloudengine/ce_ntp.py b/lib/ansible/modules/network/cloudengine/ce_ntp.py index 21acb6ad809..b9cf4e30556 100644 --- a/lib/ansible/modules/network/cloudengine/ce_ntp.py +++ b/lib/ansible/modules/network/cloudengine/ce_ntp.py @@ -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'] diff --git a/lib/ansible/modules/network/cloudengine/ce_rollback.py b/lib/ansible/modules/network/cloudengine/ce_rollback.py index 95ad587f4b3..bff44c470d8 100644 --- a/lib/ansible/modules/network/cloudengine/ce_rollback.py +++ b/lib/ansible/modules/network/cloudengine/ce_rollback.py @@ -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: diff --git a/lib/ansible/modules/web_infrastructure/letsencrypt.py b/lib/ansible/modules/web_infrastructure/letsencrypt.py index e2e4285a0c1..e12194da932 100644 --- a/lib/ansible/modules/web_infrastructure/letsencrypt.py +++ b/lib/ansible/modules/web_infrastructure/letsencrypt.py @@ -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 diff --git a/test/sanity/code-smell/no-list-cmp.sh b/test/sanity/code-smell/no-list-cmp.sh new file mode 100755 index 00000000000..d5db30ba75f --- /dev/null +++ b/test/sanity/code-smell/no-list-cmp.sh @@ -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