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 ee36628f40..b7d14aa86d 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 0c459bfac2..138b612de8 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 cbd85eaf3e..95870ad2d0 100644 --- a/plugins/connection/saltstack.py +++ b/plugins/connection/saltstack.py @@ -51,7 +51,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 085c258d45..c678d3e0e5 100644 --- a/plugins/inventory/online.py +++ b/plugins/inventory/online.py @@ -235,7 +235,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 126cc1bf16..8eda53b344 100644 --- a/plugins/module_utils/_netapp.py +++ b/plugins/module_utils/_netapp.py @@ -384,8 +384,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 c0294abb79..b5acbcc017 100644 --- a/plugins/module_utils/online.py +++ b/plugins/module_utils/online.py @@ -101,7 +101,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 d714fd69e8..bcada5fcb9 100644 --- a/plugins/module_utils/scaleway.py +++ b/plugins/module_utils/scaleway.py @@ -142,7 +142,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 3b0b601193..b1d2c69ccf 100644 --- a/plugins/modules/cloud/opennebula/one_template.py +++ b/plugins/modules/cloud/opennebula/one_template.py @@ -213,8 +213,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 5cc8d13e9a..5912a6f46a 100644 --- a/plugins/modules/cloud/packet/packet_device.py +++ b/plugins/modules/cloud/packet/packet_device.py @@ -509,11 +509,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 57e988630e..4800718fd0 100644 --- a/plugins/modules/cloud/packet/packet_sshkey.py +++ b/plugins/modules/cloud/packet/packet_sshkey.py @@ -168,7 +168,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 9e2f94190f..c184830580 100644 --- a/plugins/modules/packaging/language/maven_artifact.py +++ b/plugins/modules/packaging/language/maven_artifact.py @@ -565,7 +565,7 @@ class MavenDownloader: return "Cannot find %s checksum from %s" % (checksum_alg, remote_url) try: # Check if remote checksum only contains md5/sha1 or md5/sha1 + filename - _remote_checksum = remote_checksum.split(None)[0] + _remote_checksum = remote_checksum.split(None, 1)[0] remote_checksum = _remote_checksum # remote_checksum is empty so we continue and keep original checksum string # This should not happen since we check for remote_checksum before diff --git a/plugins/modules/system/launchd.py b/plugins/modules/system/launchd.py index e8d82ff318..8c09a44f6e 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 756d532e68..5389bdcb2f 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: