From bc02dc4c4427baeaaba52688cd565738ef2527b2 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Thu, 12 Aug 2021 14:17:01 +0200 Subject: [PATCH] [PR #3194/1fec1d0c backport][stable-3] Fix sanity failures (#3195) (#3196) * Fix new devel sanity errors. (#3194) (cherry picked from commit 1fec1d0c81449fb4fc3dea9de362a27de7c1fbda) * Add two more. * Fix PR #. Co-authored-by: Felix Fontein (cherry picked from commit 1a3c2219958d389ba7dde42571e343f1b57534de) Co-authored-by: patchback[bot] <45432694+patchback[bot]@users.noreply.github.com> --- changelogs/fragments/3194-sanity.yml | 16 ++++++++++++++++ plugins/cache/memcached.py | 8 ++++---- plugins/callback/logdna.py | 2 +- plugins/connection/saltstack.py | 2 +- plugins/inventory/online.py | 2 +- plugins/module_utils/_netapp.py | 4 ++-- plugins/module_utils/online.py | 2 +- plugins/module_utils/scaleway.py | 2 +- plugins/modules/cloud/opennebula/one_template.py | 4 ++-- plugins/modules/cloud/packet/packet_device.py | 5 ++--- plugins/modules/cloud/packet/packet_sshkey.py | 2 +- .../modules/packaging/language/maven_artifact.py | 2 +- plugins/modules/system/launchd.py | 6 +++--- plugins/modules/system/ufw.py | 4 ++-- scripts/inventory/scaleway.py | 2 +- scripts/inventory/vbox.py | 8 ++++---- tests/unit/mock/loader.py | 4 ++-- 17 files changed, 45 insertions(+), 30 deletions(-) create mode 100644 changelogs/fragments/3194-sanity.yml diff --git a/changelogs/fragments/3194-sanity.yml b/changelogs/fragments/3194-sanity.yml new file mode 100644 index 0000000000..1e0150cd31 --- /dev/null +++ b/changelogs/fragments/3194-sanity.yml @@ -0,0 +1,16 @@ +bugfixes: +- "memcached cache plugin - change function argument names to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "logdns callback plugin - improve split call to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "saltstack connection plugin - fix function signature (https://github.com/ansible-collections/community.general/pull/3194)." +- "online inventory plugin - improve split call to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "netapp module utils - remove always-true conditional to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "online module utils - improve split call to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "scaleway module utils - improve split call to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "one_template - change function argument name to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "packet_device - use generator to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "packet_sshkey - use generator to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "maven_artifact - improve split call to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "launchd - use private attribute to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "ufw - use generator to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3194)." +- "scaleway inventory script - improve split call to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3195)." +- "vbox inventory script - change function argument name to fix sanity errors (https://github.com/ansible-collections/community.general/pull/3195)." diff --git a/plugins/cache/memcached.py b/plugins/cache/memcached.py index fb2a778fc3..557b4b844b 100644 --- a/plugins/cache/memcached.py +++ b/plugins/cache/memcached.py @@ -154,12 +154,12 @@ class CacheModuleKeys(MutableSet): def __len__(self): return len(self._keyset) - def add(self, key): - self._keyset[key] = time.time() + def add(self, value): + self._keyset[value] = time.time() self._cache.set(self.PREFIX, self._keyset) - def discard(self, key): - del self._keyset[key] + def discard(self, value): + del self._keyset[value] self._cache.set(self.PREFIX, self._keyset) def remove_by_timerange(self, s_min, s_max): diff --git a/plugins/callback/logdna.py b/plugins/callback/logdna.py index ddb4c477da..f4ebd6aba6 100644 --- a/plugins/callback/logdna.py +++ b/plugins/callback/logdna.py @@ -78,7 +78,7 @@ def get_mac(): # Getting hostname of system: def get_hostname(): - return str(socket.gethostname()).split('.local')[0] + return str(socket.gethostname()).split('.local', 1)[0] # Getting IP of system: diff --git a/plugins/connection/saltstack.py b/plugins/connection/saltstack.py index 8405931431..1ce8d6a4c2 100644 --- a/plugins/connection/saltstack.py +++ b/plugins/connection/saltstack.py @@ -58,7 +58,7 @@ class Connection(ConnectionBase): self._connected = True return self - def exec_command(self, cmd, sudoable=False, in_data=None): + def exec_command(self, cmd, in_data=None, sudoable=False): ''' run a command on the remote minion ''' super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) diff --git a/plugins/inventory/online.py b/plugins/inventory/online.py index f5a939b69d..feee9f1886 100644 --- a/plugins/inventory/online.py +++ b/plugins/inventory/online.py @@ -234,7 +234,7 @@ class InventoryModule(BaseInventoryPlugin): self.headers = { 'Authorization': "Bearer %s" % token, - 'User-Agent': "ansible %s Python %s" % (ansible_version, python_version.split(' ')[0]), + 'User-Agent': "ansible %s Python %s" % (ansible_version, python_version.split(' ', 1)[0]), 'Content-type': 'application/json' } diff --git a/plugins/module_utils/_netapp.py b/plugins/module_utils/_netapp.py index d80506bb9a..8fa6a0f220 100644 --- a/plugins/module_utils/_netapp.py +++ b/plugins/module_utils/_netapp.py @@ -383,8 +383,8 @@ class NetAppESeriesModule(object): path = path[1:] request_url = self.url + self.DEFAULT_REST_API_PATH + path - if self.log_requests or True: - self.module.log(pformat(dict(url=request_url, data=data, method=method))) + # if self.log_requests: + self.module.log(pformat(dict(url=request_url, data=data, method=method))) return request(url=request_url, data=data, method=method, headers=headers, use_proxy=True, force=False, last_mod_time=None, timeout=self.DEFAULT_TIMEOUT, http_agent=self.HTTP_AGENT, force_basic_auth=True, ignore_errors=ignore_errors, **self.creds) diff --git a/plugins/module_utils/online.py b/plugins/module_utils/online.py index 464e454288..ada558cb4b 100644 --- a/plugins/module_utils/online.py +++ b/plugins/module_utils/online.py @@ -100,7 +100,7 @@ class Online(object): @staticmethod def get_user_agent_string(module): - return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ')[0]) + return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ', 1)[0]) def get(self, path, data=None, headers=None): return self.send('GET', path, data, headers) diff --git a/plugins/module_utils/scaleway.py b/plugins/module_utils/scaleway.py index 3c73e92bb8..0e7a398739 100644 --- a/plugins/module_utils/scaleway.py +++ b/plugins/module_utils/scaleway.py @@ -141,7 +141,7 @@ class Scaleway(object): @staticmethod def get_user_agent_string(module): - return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ')[0]) + return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ', 1)[0]) def get(self, path, data=None, headers=None, params=None): return self.send(method='GET', path=path, data=data, headers=headers, params=params) diff --git a/plugins/modules/cloud/opennebula/one_template.py b/plugins/modules/cloud/opennebula/one_template.py index b4c8a2fa83..bce6119980 100644 --- a/plugins/modules/cloud/opennebula/one_template.py +++ b/plugins/modules/cloud/opennebula/one_template.py @@ -212,8 +212,8 @@ class TemplateModule(OpenNebulaModule): def get_template_by_id(self, template_id): return self.get_template(lambda template: (template.ID == template_id)) - def get_template_by_name(self, template_name): - return self.get_template(lambda template: (template.NAME == template_name)) + def get_template_by_name(self, name): + return self.get_template(lambda template: (template.NAME == name)) def get_template_instance(self, requested_id, requested_name): if requested_id: diff --git a/plugins/modules/cloud/packet/packet_device.py b/plugins/modules/cloud/packet/packet_device.py index 5dc662a255..108098dbd0 100644 --- a/plugins/modules/cloud/packet/packet_device.py +++ b/plugins/modules/cloud/packet/packet_device.py @@ -508,11 +508,10 @@ def wait_for_devices_active(module, packet_conn, watched_devices): def wait_for_public_IPv(module, packet_conn, created_devices): def has_public_ip(addr_list, ip_v): - return any([a['public'] and a['address_family'] == ip_v and - a['address'] for a in addr_list]) + return any(a['public'] and a['address_family'] == ip_v and a['address'] for a in addr_list) def all_have_public_ip(ds, ip_v): - return all([has_public_ip(d.ip_addresses, ip_v) for d in ds]) + return all(has_public_ip(d.ip_addresses, ip_v) for d in ds) address_family = module.params.get('wait_for_public_IPv') diff --git a/plugins/modules/cloud/packet/packet_sshkey.py b/plugins/modules/cloud/packet/packet_sshkey.py index 97589cddb9..4c71d1bcd2 100644 --- a/plugins/modules/cloud/packet/packet_sshkey.py +++ b/plugins/modules/cloud/packet/packet_sshkey.py @@ -167,7 +167,7 @@ def get_sshkey_selector(module): return k.key == select_dict['key'] else: # if key string not specified, all the fields must match - return all([select_dict[f] == getattr(k, f) for f in select_dict]) + return all(select_dict[f] == getattr(k, f) for f in select_dict) return selector diff --git a/plugins/modules/packaging/language/maven_artifact.py b/plugins/modules/packaging/language/maven_artifact.py index 50b808f57a..14e3e25a0a 100644 --- a/plugins/modules/packaging/language/maven_artifact.py +++ b/plugins/modules/packaging/language/maven_artifact.py @@ -556,7 +556,7 @@ class MavenDownloader: return "Cannot find md5 from " + remote_url try: # Check if remote md5 only contains md5 or md5 + filename - _remote_md5 = remote_md5.split(None)[0] + _remote_md5 = remote_md5.split(None, 1)[0] remote_md5 = _remote_md5 # remote_md5 is empty so we continue and keep original md5 string # This should not happen since we check for remote_md5 before diff --git a/plugins/modules/system/launchd.py b/plugins/modules/system/launchd.py index b7a5efdfff..3c2cc4f484 100644 --- a/plugins/modules/system/launchd.py +++ b/plugins/modules/system/launchd.py @@ -141,14 +141,14 @@ class Plist: self.__changed = False self.__service = service - state, pid, dummy, dummy = LaunchCtlList(module, service).run() + state, pid, dummy, dummy = LaunchCtlList(module, self.__service).run() # Check if readPlist is available or not self.old_plistlib = hasattr(plistlib, 'readPlist') - self.__file = self.__find_service_plist(service) + self.__file = self.__find_service_plist(self.__service) if self.__file is None: - msg = 'Unable to infer the path of %s service plist file' % service + msg = 'Unable to infer the path of %s service plist file' % self.__service if pid is None and state == ServiceState.UNLOADED: msg += ' and it was not found among active services' module.fail_json(msg=msg) diff --git a/plugins/modules/system/ufw.py b/plugins/modules/system/ufw.py index c6df6fe63a..465df6adb5 100644 --- a/plugins/modules/system/ufw.py +++ b/plugins/modules/system/ufw.py @@ -526,8 +526,8 @@ def main(): lines = [(numbered_line_re.match(line), '(v6)' in line) for line in numbered_state.splitlines()] lines = [(int(matcher.group(1)), ipv6) for (matcher, ipv6) in lines if matcher] last_number = max([no for (no, ipv6) in lines]) if lines else 0 - has_ipv4 = any([not ipv6 for (no, ipv6) in lines]) - has_ipv6 = any([ipv6 for (no, ipv6) in lines]) + has_ipv4 = any(not ipv6 for (no, ipv6) in lines) + has_ipv6 = any(ipv6 for (no, ipv6) in lines) if relative_to_cmd == 'first-ipv4': relative_to = 1 elif relative_to_cmd == 'last-ipv4': diff --git a/scripts/inventory/scaleway.py b/scripts/inventory/scaleway.py index f68eb128a5..a936cc7765 100755 --- a/scripts/inventory/scaleway.py +++ b/scripts/inventory/scaleway.py @@ -51,7 +51,7 @@ class ScalewayAPI: def __init__(self, auth_token, region): self.session = requests.session() self.session.headers.update({ - 'User-Agent': 'Ansible Python/%s' % (sys.version.split(' ')[0]) + 'User-Agent': 'Ansible Python/%s' % (sys.version.split(' ', 1)[0]) }) self.session.headers.update({ 'X-Auth-Token': auth_token.encode('latin1') diff --git a/scripts/inventory/vbox.py b/scripts/inventory/vbox.py index 110ead1471..0b5f0ee8f9 100755 --- a/scripts/inventory/vbox.py +++ b/scripts/inventory/vbox.py @@ -12,10 +12,10 @@ import json class SetEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, set): - return list(obj) - return json.JSONEncoder.default(self, obj) + def default(self, o): + if isinstance(o, set): + return list(o) + return json.JSONEncoder.default(self, o) VBOX = "VBoxManage" diff --git a/tests/unit/mock/loader.py b/tests/unit/mock/loader.py index 907ec9b928..5e8502cd25 100644 --- a/tests/unit/mock/loader.py +++ b/tests/unit/mock/loader.py @@ -32,8 +32,8 @@ class DictDataLoader(DataLoader): # TODO: the real _get_file_contents returns a bytestring, so we actually convert the # unicode/text it's created with to utf-8 - def _get_file_contents(self, path): - path = to_text(path) + def _get_file_contents(self, file_name): + path = to_text(file_name) if path in self._file_mapping: return (to_bytes(self._file_mapping[path]), False) else: