From e146d30388bcf15c470d48873d1eccf1b62fc127 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 10:10:12 +0100 Subject: [PATCH 01/63] salt-lint: cri module fix "useless-else-on-loop" ``` salt/_modules/cri.py:174: [W0120(useless-else-on-loop), wait_container] Else clause on loop without a break statement ``` --- salt/_modules/cri.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/_modules/cri.py b/salt/_modules/cri.py index 7591f5904c..4e16667cb8 100644 --- a/salt/_modules/cri.py +++ b/salt/_modules/cri.py @@ -171,9 +171,9 @@ def wait_container(name, state, timeout=60, delay=5): if out['retcode'] == 0 and out['stdout']: return True time.sleep(delay) - else: - log.error('Failed to find container "%s" in state "%s"', name, state) - return False + + log.error('Failed to find container "%s" in state "%s"', name, state) + return False def component_is_running(name): From ef6b534af9cf560754b44dc7b262359d3877086d Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 10:12:48 +0100 Subject: [PATCH 02/63] salt-lint: metalk8s_cordon module fix "too-many-blank-lines" ``` salt/_modules/metalk8s_cordon.py:84: [E8303(too-many-blank-lines), ] PEP8 E303: too many blank lines (2) ``` --- salt/_modules/metalk8s_cordon.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/_modules/metalk8s_cordon.py b/salt/_modules/metalk8s_cordon.py index afd9019268..e80573dd49 100644 --- a/salt/_modules/metalk8s_cordon.py +++ b/salt/_modules/metalk8s_cordon.py @@ -80,7 +80,6 @@ def uncordon_node(node_name, **kwargs): ] patch_dict['spec']['taints'] = new_taints - return __salt__['metalk8s_kubernetes.update_object']( name=node_name, kind='Node', From f8fdec12388f5399a18693dc7cc7e4b7d2a2b58b Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 10:23:11 +0100 Subject: [PATCH 03/63] salt-lint: metalk8s_drain module fix "raise-missing-from" Disable some "raise-missing-from" as it's known exception and we do not want to have upper exceptions raised ``` salt/_modules/metalk8s_drain.py:388: [W0707(raise-missing-from), Drain.run_drain] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_drain.py:394: [W0707(raise-missing-from), Drain.run_drain] Consider explicitly re-raising using the 'from' keyword ``` Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s_drain.py:360: [W0707(raise-missing-from), Drain.run_drain] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_drain.py:547: [W0707(raise-missing-from), evict_pod] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_drain.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/salt/_modules/metalk8s_drain.py b/salt/_modules/metalk8s_drain.py index 19c5bed7e7..75b8de47e9 100644 --- a/salt/_modules/metalk8s_drain.py +++ b/salt/_modules/metalk8s_drain.py @@ -365,7 +365,7 @@ def run_drain(self, dry_run=False): ).format( exc.message ) - ) + ) from exc if pods: pods_to_evict = ", ".join([ @@ -385,13 +385,13 @@ def run_drain(self, dry_run=False): self.evict_pods(pods) except DrainTimeoutException as exc: remaining_pods = self.get_pods_for_eviction() - raise CommandExecutionError( + raise CommandExecutionError( # pylint: disable=raise-missing-from "{0} List of remaining pods to follow".format(exc.message), [pod['metadata']['name'] for pod in remaining_pods] ) except CommandExecutionError as exc: remaining_pods = self.get_pods_for_eviction() - raise CommandExecutionError( + raise CommandExecutionError( # pylint: disable=raise-missing-from "{0} List of remaining pods to follow".format( exc.message ), @@ -545,10 +545,10 @@ def evict_pod(name, namespace='default', grace_period=1, return False raise CommandExecutionError( - 'Failed to evict pod "{}" in namespace "{}": {!s}'.format( - name, namespace, exc + 'Failed to evict pod "{}" in namespace "{}"'.format( + name, namespace ) - ) + ) from exc return True From a774ecd4be5afc3c7c39ccbd2cd6dd7fdb185606 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 10:31:26 +0100 Subject: [PATCH 04/63] salt-lint: metalk8s_drain module fix "unecessary-pass" Remove "unecessary-pass" ``` salt/_modules/metalk8s_drain.py:59: [W0107(unnecessary-pass), DrainTimeoutException] Unnecessary pass statement ``` --- salt/_modules/metalk8s_drain.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/_modules/metalk8s_drain.py b/salt/_modules/metalk8s_drain.py index 75b8de47e9..97f1076256 100644 --- a/salt/_modules/metalk8s_drain.py +++ b/salt/_modules/metalk8s_drain.py @@ -56,7 +56,6 @@ def __str__(self): class DrainTimeoutException(DrainException): '''Timeout-specific drain exception.''' - pass def _mirrorpod_filter(pod): From 7c6429543c98bf3ebac378aaf42b838fe6757ae2 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:20:23 +0100 Subject: [PATCH 05/63] salt-lint: metalk8s_drain module fix "unused-variable" Remove the unused variable ``` salt/_modules/metalk8s_drain.py:516: [W0612(unused-variable), evict_pod] Unused variable 'result' ``` --- salt/_modules/metalk8s_drain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s_drain.py b/salt/_modules/metalk8s_drain.py index 97f1076256..1ce09d27c1 100644 --- a/salt/_modules/metalk8s_drain.py +++ b/salt/_modules/metalk8s_drain.py @@ -513,7 +513,7 @@ def evict_pod(name, namespace='default', grace_period=1, client.configure(config_file=kubeconfig, context=context) try: - result = client.create( + client.create( name=name, namespace=namespace, body=V1beta1Eviction( From c1c4509996daa664312684e08c16fcdb91ef51ee Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 10:44:41 +0100 Subject: [PATCH 06/63] salt-lint: metalk8s_etcd module fix "blacklisted-module" Use six urllib parse module from salt instead of six directly ``` salt/_modules/metalk8s_etcd.py:6: [E9402(blacklisted-module), ] Uses of a blacklisted module 'six.moves.urllib.parse': Please report this error to SaltStack so we can fix it: Trying to import urlparse from six.moves.urllib.parse ``` --- salt/_modules/metalk8s_etcd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s_etcd.py b/salt/_modules/metalk8s_etcd.py index 69379f1c50..f72953799e 100644 --- a/salt/_modules/metalk8s_etcd.py +++ b/salt/_modules/metalk8s_etcd.py @@ -3,8 +3,8 @@ Module for handling etcd client specific calls. ''' import logging -from six.moves.urllib.parse import urlparse +from salt.ext.six.moves.urllib.parse import urlparse from salt.exceptions import CommandExecutionError PYTHON_ETCD_PRESENT = False From 772e5c96645fbba3a1ac248ad4e903fe4c1a452d Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 10:48:10 +0100 Subject: [PATCH 07/63] salt-lint: metalk8s_etcd module fix "bare-except" Fix "bare-except" and disable "broad-except" as we want to catch all exceptions ``` salt/_modules/metalk8s_etcd.py:198: [W0702(bare-except), get_etcd_member_list] No exception type(s) specified ``` --- salt/_modules/metalk8s_etcd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s_etcd.py b/salt/_modules/metalk8s_etcd.py index f72953799e..ceb5c4d798 100644 --- a/salt/_modules/metalk8s_etcd.py +++ b/salt/_modules/metalk8s_etcd.py @@ -195,7 +195,7 @@ def get_etcd_member_list( cert_key=cert_key, cert_cert=cert_cert ) - except: + except Exception: # pylint: disable=broad-except return [] with etcd3.client(host=endpoint, From bfb33b88eb31effe29c41a5bc4c401ab3fd0861f Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 10:54:30 +0100 Subject: [PATCH 08/63] salt-lint: metalk8s_kubeconfig fix "broad-except" Disable "broad-except" as we want to catch all exceptions ``` salt/_modules/metalk8s_kubeconfig.py:43: [W0703(broad-except), validate] Catching too general exception Exception ``` --- salt/_modules/metalk8s_kubeconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s_kubeconfig.py b/salt/_modules/metalk8s_kubeconfig.py index e001b06ad2..643ec05b52 100644 --- a/salt/_modules/metalk8s_kubeconfig.py +++ b/salt/_modules/metalk8s_kubeconfig.py @@ -40,7 +40,7 @@ def validate(filename, try: with open(filename, 'r') as fd: kubeconfig = yaml.safe_load(fd) - except Exception: + except Exception: # pylint: disable=broad-except return False # Verify that the current CA cert on disk matches the expected CA cert From 8af73f1b6f3dd31a5afe767ba832d9e9e01d2c10 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 11:01:35 +0100 Subject: [PATCH 09/63] salt-lint: metalk8s_kubeconfig fix "resource-leakage" Use `fopen` from salt instead of classic `open` ``` salt/_modules/metalk8s_kubeconfig.py:41: [W8470(resource-leakage), validate] Resource leakage detected. Please use 'with salt.utils.files.fopen()' instead of 'with open()'. It assures salt does not leak file handles. ``` --- salt/_modules/metalk8s_kubeconfig.py | 4 +++- salt/tests/unit/modules/test_metalk8s_kubeconfig.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/salt/_modules/metalk8s_kubeconfig.py b/salt/_modules/metalk8s_kubeconfig.py index 643ec05b52..ee475c769f 100644 --- a/salt/_modules/metalk8s_kubeconfig.py +++ b/salt/_modules/metalk8s_kubeconfig.py @@ -7,6 +7,8 @@ import stat import yaml +from salt.utils.files import fopen + __virtualname__ = 'metalk8s_kubeconfig' @@ -38,7 +40,7 @@ def validate(filename, return False try: - with open(filename, 'r') as fd: + with fopen(filename, 'r') as fd: kubeconfig = yaml.safe_load(fd) except Exception: # pylint: disable=broad-except return False diff --git a/salt/tests/unit/modules/test_metalk8s_kubeconfig.py b/salt/tests/unit/modules/test_metalk8s_kubeconfig.py index 33f1a2c0af..b8839cdf28 100644 --- a/salt/tests/unit/modules/test_metalk8s_kubeconfig.py +++ b/salt/tests/unit/modules/test_metalk8s_kubeconfig.py @@ -69,7 +69,7 @@ def test_validate(self, with patch("os.path.isfile", os_isfile_mock), \ patch("os.stat", MagicMock()), \ patch("stat.S_IMODE", stat_s_imode_mock), \ - patch("metalk8s_kubeconfig.open", open_mock), \ + patch("metalk8s_kubeconfig.fopen", open_mock), \ patch.dict(metalk8s_kubeconfig.__salt__, patch_salt_dict): cluster_info = KUBECONFIG['clusters'][0]['cluster'] self.assertEqual( From f6312b4ea06a640768e4a7f95c480ec4959452a4 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 13:32:21 +0100 Subject: [PATCH 10/63] salt-lint: metalk8s_kubernetes module fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s_kubernetes.py:56: [W0707(raise-missing-from), _extract_obj_and_kind_info] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_kubernetes.py:110: [W0707(raise-missing-from), _object_manipulation_function.method] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_kubernetes.py:115: [W0707(raise-missing-from), _object_manipulation_function.method] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_kubernetes.py:345: [W0707(raise-missing-from), list_objects] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_kubernetes.py:374: [W0707(raise-missing-from), list_objects] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_kubernetes.py | 24 +++++------ .../files/test_metalk8s_kubernetes.yaml | 40 ++++++------------- 2 files changed, 23 insertions(+), 41 deletions(-) diff --git a/salt/_modules/metalk8s_kubernetes.py b/salt/_modules/metalk8s_kubernetes.py index af4c07e4a3..bcfbe195a5 100644 --- a/salt/_modules/metalk8s_kubernetes.py +++ b/salt/_modules/metalk8s_kubernetes.py @@ -53,7 +53,7 @@ def _extract_obj_and_kind_info(manifest, force_custom_object=False): manifest, force_custom_object=force_custom_object ) except ValueError as exc: - raise CommandExecutionError('Invalid manifest: {!s}'.format(exc)) + raise CommandExecutionError('Invalid manifest') from exc return obj, kind_info @@ -64,13 +64,13 @@ def _handle_error(exception, action): Note that 'retrieve' and 'delete' will not re-raise if the error is just a "404 NOT FOUND", and instead return `None`. """ - base_msg = 'Failed to {} object: '.format(action) + base_msg = 'Failed to {} object'.format(action) if action in ['delete', 'retrieve'] and \ isinstance(exception, ApiException) and exception.status == 404: return None else: - raise CommandExecutionError(base_msg + str(exception)) + raise CommandExecutionError(base_msg) from exception def _object_manipulation_function(action): @@ -108,14 +108,12 @@ def method(manifest=None, name=None, kind=None, apiVersion=None, ) except IOError as exc: raise CommandExecutionError( - 'Failed to read file "{}": {}' - .format(name, str(exc)) - ) + 'Failed to read file "{}"'.format(name) + ) from exc except yaml.YAMLError as exc: raise CommandExecutionError( - 'Invalid YAML in file "{}": {}' - ''.format(name, str(exc)) - ) + 'Invalid YAML in file "{}"'.format(name) + ) from exc elif name is not None: raise CommandExecutionError( 'Cannot use both "manifest" and "name".' @@ -343,10 +341,10 @@ def list_objects(kind, apiVersion, namespace='default', all_namespaces=False, }) except ValueError as exc: raise CommandExecutionError( - 'Unsupported resource "{}/{}": {!s}'.format( - apiVersion, kind, exc + 'Unsupported resource "{}/{}"'.format( + apiVersion, kind ) - ) + ) from exc call_kwargs = {} if all_namespaces: @@ -371,7 +369,7 @@ def list_objects(kind, apiVersion, namespace='default', all_namespaces=False, base_msg = 'Failed to list resources "{}/{}"'.format(apiVersion, kind) if 'namespace' in call_kwargs: base_msg += ' in namespace "{}"'.format(namespace) - raise CommandExecutionError('{}: {!s}'.format(base_msg, exc)) + raise CommandExecutionError(base_msg) from exc return [obj.to_dict() for obj in result.items] diff --git a/salt/tests/unit/modules/files/test_metalk8s_kubernetes.yaml b/salt/tests/unit/modules/files/test_metalk8s_kubernetes.yaml index 6d0e1424c0..3440466e61 100644 --- a/salt/tests/unit/modules/files/test_metalk8s_kubernetes.yaml +++ b/salt/tests/unit/modules/files/test_metalk8s_kubernetes.yaml @@ -11,7 +11,7 @@ common_tests: a: b info_scope: null raises: True - result: "Invalid manifest: An error has occurred" + result: "Invalid manifest" # Error giving manifest and name (manifest file path) - name: /path/to/my/manifest.yaml @@ -27,13 +27,13 @@ common_tests: - name: /invalid/path/manifest.yaml manifest_file_content: null raises: True - result: 'Failed to read file "/invalid/path/manifest.yaml": An error has occurred' + result: 'Failed to read file "/invalid/path/manifest.yaml"' # Invalid YAML manifest file - name: /path/to/my/invalid-manifest.yaml manifest_file_content: False raises: True - result: 'Invalid YAML in file "/path/to/my/invalid-manifest.yaml": An error has occurred' + result: 'Invalid YAML in file "/path/to/my/invalid-manifest.yaml"' create_object: # Simple manifest without labels @@ -116,9 +116,7 @@ create_object: name: my_node api_status_code: 0 raises: True - result: | - Failed to create object: \(0\) - Reason: An error has occurred + result: Failed to create object delete_object: # Simple Pod deletion (using manifest) - No namespace @@ -179,9 +177,7 @@ delete_object: name: my_pod api_status_code: 0 raises: True - result: | - Failed to delete object: \(0\) - Reason: An error has occurred + result: Failed to delete object replace_object: # Simple replace object (same behavior as create) @@ -323,9 +319,7 @@ replace_object: name: my_node api_status_code: 0 raises: True - result: | - Failed to replace object: \(0\) - Reason: An error has occurred + result: Failed to replace object get_object: # Simple Get Pod (using manifest) - No namespace @@ -386,9 +380,7 @@ get_object: name: my_pod api_status_code: 0 raises: True - result: | - Failed to retrieve object: \(0\) - Reason: An error has occurred + result: Failed to retrieve object update_object: # Simple Node update (using manifest) @@ -450,9 +442,7 @@ update_object: labels: my.new.label: my-new-label raises: True - result: | - Failed to update object: \(0\) - Reason: An error has occurred + result: Failed to update object list_objects: # Simple list Pod @@ -521,16 +511,14 @@ list_objects: kind: MyInvalidKind info_scope: null raises: True - result: 'Unsupported resource "v1/MyInvalidKind": An error has occurred' + result: 'Unsupported resource "v1/MyInvalidKind"' # Error when listing namespaced resource (default namespace) - apiVersion: v1 kind: Pod api_status_code: 0 raises: True - result: |- - Failed to list resources "v1/Pod" in namespace "default": \(0\) - Reason: An error has occurred + result: 'Failed to list resources "v1/Pod" in namespace "default"' # Error when listing namespaced resource (specified namespace) - apiVersion: v1 @@ -538,9 +526,7 @@ list_objects: namespace: my-custom-namespace api_status_code: 0 raises: True - result: |- - Failed to list resources "v1/Pod" in namespace "my-custom-namespace": \(0\) - Reason: An error has occurred + result: 'Failed to list resources "v1/Pod" in namespace "my-custom-namespace"' # Error when listing cluster resource - apiVersion: v1 @@ -548,9 +534,7 @@ list_objects: info_scope: cluster api_status_code: 0 raises: True - result: |- - Failed to list resources "v1/Node": \(0\) - Reason: An error has occurred + result: 'Failed to list resources "v1/Node"' get_object_digest: # Simple full object digest From 111e6204dd2ea1129b5124ef35765030f2de27ee Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 13:37:40 +0100 Subject: [PATCH 11/63] salt-lint: metalk8s_kubernetes_utils module fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s_kubernetes_utils.py:98: [W0707(raise-missing-from), get_version_info] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_kubernetes_utils.py:178: [W0707(raise-missing-from), get_service_endpoints] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_kubernetes_utils.py:201: [W0707(raise-missing-from), get_service_endpoints] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_kubernetes_utils.py | 21 +++++++------------ .../files/test_metalk8s_kubernetes_utils.yaml | 6 +++--- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/salt/_modules/metalk8s_kubernetes_utils.py b/salt/_modules/metalk8s_kubernetes_utils.py index 6e9a4357a6..03a999bcf7 100644 --- a/salt/_modules/metalk8s_kubernetes_utils.py +++ b/salt/_modules/metalk8s_kubernetes_utils.py @@ -95,9 +95,7 @@ def get_version_info(**kwargs): try: version_info = api_instance.get_code() except (ApiException, HTTPError) as exc: - raise CommandExecutionError( - 'Failed to get version info: {}'.format(str(exc)) - ) + raise CommandExecutionError('Failed to get version info') from exc return version_info.to_dict() @@ -164,7 +162,7 @@ def read_and_render_yaml_file(source, template, context=None, saltenv='base'): def get_service_endpoints(service, namespace, kubeconfig): error_tpl = \ - 'Unable to get kubernetes endpoints for {} in namespace {}:\n{!s}' + 'Unable to get kubernetes endpoints for {} in namespace {}' try: endpoint = __salt__['metalk8s_kubernetes.get_object']( @@ -174,15 +172,12 @@ def get_service_endpoints(service, namespace, kubeconfig): namespace=namespace, kubeconfig=kubeconfig, ) + if not endpoint: + raise CommandExecutionError('Endpoint not found') except CommandExecutionError as exc: raise CommandExecutionError( - error_tpl.format(service, namespace, exc) - ) - - if not endpoint: - raise CommandExecutionError( - error_tpl.format(service, namespace, 'Endpoint not found') - ) + error_tpl.format(service, namespace) + ) from exc try: # Extract hostname, ip and node_name @@ -199,7 +194,7 @@ def get_service_endpoints(service, namespace, kubeconfig): } except (AttributeError, IndexError, KeyError, TypeError) as exc: raise CommandExecutionError( - error_tpl.format(service, namespace, exc) - ) + error_tpl.format(service, namespace) + ) from exc return result diff --git a/salt/tests/unit/modules/files/test_metalk8s_kubernetes_utils.yaml b/salt/tests/unit/modules/files/test_metalk8s_kubernetes_utils.yaml index 40cf3d9c8f..ed454113b9 100644 --- a/salt/tests/unit/modules/files/test_metalk8s_kubernetes_utils.yaml +++ b/salt/tests/unit/modules/files/test_metalk8s_kubernetes_utils.yaml @@ -176,12 +176,12 @@ get_service_endpoints: # 2. Error when getting the Endpoint object - obj: False raises: True - result: "Unable to get kubernetes endpoints for my_service in namespace my_namespace:\nAn error has occurred" + result: "Unable to get kubernetes endpoints for my_service in namespace my_namespace" # 3. Endpoint object does not exists - obj: null raises: True - result: "Unable to get kubernetes endpoints for my_service in namespace my_namespace:\nEndpoint not found" + result: "Unable to get kubernetes endpoints for my_service in namespace my_namespace" # 4. Endpoint do not have any addresses - obj: @@ -208,4 +208,4 @@ get_service_endpoints: uid: fad86410-00d9-43c2-b91c-8288b18b0337 subsets: null raises: True - result: "Unable to get kubernetes endpoints for my_service in namespace my_namespace:\n'NoneType' object is not subscriptable" + result: "Unable to get kubernetes endpoints for my_service in namespace my_namespace" From a13f3c37df56c49cf88e92c2bf2adf25426a2837 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 13:41:45 +0100 Subject: [PATCH 12/63] salt-lint: metalk8s_monitoring module fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s_monitoring.py:189: [W0707(raise-missing-from), _requests_alertmanager_api] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_monitoring.py:206: [W0707(raise-missing-from), _requests_alertmanager_api] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_monitoring.py | 6 +++--- salt/tests/unit/modules/files/test_metalk8s_monitoring.yaml | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/salt/_modules/metalk8s_monitoring.py b/salt/_modules/metalk8s_monitoring.py index e364ac3a76..ea11c69bf7 100644 --- a/salt/_modules/metalk8s_monitoring.py +++ b/salt/_modules/metalk8s_monitoring.py @@ -187,8 +187,8 @@ def _requests_alertmanager_api(route, method='GET', **kwargs): response = session.request(method, url, **kwargs) except Exception as exc: raise CommandExecutionError( - "Unable to query Alertmanager API on {}: {!s}".format(url, exc) - ) + "Unable to query Alertmanager API on {}".format(url) + ) from exc try: json = response.json() @@ -203,7 +203,7 @@ def _requests_alertmanager_api(route, method='GET', **kwargs): "Malformed response returned from Alertmanager API: {!s}: {}" .format(exc, response.text) ) - raise CommandExecutionError(error) + raise CommandExecutionError(error) from exc if json['status'] == 'error': raise CommandExecutionError( diff --git a/salt/tests/unit/modules/files/test_metalk8s_monitoring.yaml b/salt/tests/unit/modules/files/test_metalk8s_monitoring.yaml index b28abebf6f..74295281d5 100644 --- a/salt/tests/unit/modules/files/test_metalk8s_monitoring.yaml +++ b/salt/tests/unit/modules/files/test_metalk8s_monitoring.yaml @@ -33,8 +33,7 @@ alertmanager_api_helper: request_raises: 'some request error' raises: True result: >- - Unable to query Alertmanager API on http://10.0.0.1:1234/api/v1/alerts: - some request error + Unable to query Alertmanager API on http://10.0.0.1:1234/api/v1/alerts - _id: response-error endpoint: *alertmanager_endpoint @@ -166,4 +165,4 @@ get_alerts: state: active response: *alerts_list result: - - *active_alert \ No newline at end of file + - *active_alert From 2b4d9a18a1a140d945f274637b44f5923c43b99e Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 13:58:48 +0100 Subject: [PATCH 13/63] salt-lint: metalk8s_package_manager_yum fix "unused-import" Remove unused import ``` salt/_modules/metalk8s_package_manager_yum.py:7: [W0611(unused-import), ] Unused contextmanager imported from contextlib ``` --- salt/_modules/metalk8s_package_manager_yum.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/_modules/metalk8s_package_manager_yum.py b/salt/_modules/metalk8s_package_manager_yum.py index b40936bb52..857d9132a5 100644 --- a/salt/_modules/metalk8s_package_manager_yum.py +++ b/salt/_modules/metalk8s_package_manager_yum.py @@ -4,7 +4,6 @@ ''' import logging -from contextlib import contextmanager from salt.exceptions import CommandExecutionError log = logging.getLogger(__name__) From a0142247960cd4db0997e61dd215c0cd4ddd802a Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:21:07 +0100 Subject: [PATCH 14/63] salt-lint: metalk8s_package_manager_yum module fix "str-format-in-log" Replace the `format` inside logging by a logging formatting ``` salt/_modules/metalk8s_package_manager_yum.py:51: [E1323(str-format-in-logging), _list_dependents] String formatting used in logging: "'{}-{}'.format(name, version)" ``` --- salt/_modules/metalk8s_package_manager_yum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/_modules/metalk8s_package_manager_yum.py b/salt/_modules/metalk8s_package_manager_yum.py index 857d9132a5..25807b9c15 100644 --- a/salt/_modules/metalk8s_package_manager_yum.py +++ b/salt/_modules/metalk8s_package_manager_yum.py @@ -47,8 +47,8 @@ def _list_dependents( if ret['retcode'] != 0: log.error( - 'Failed to list packages requiring "%s": %s', - '{}-{}'.format(name, version), + 'Failed to list packages requiring "%s-%s": %s', + name, version, ret['stderr'] or ret['stdout'] ) return None From bfe486d31931f500e168c70575bd54876a6ff090 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:00:24 +0100 Subject: [PATCH 15/63] salt-lint: metalk8s module fix "blacklisted-module" Use six module from salt instead of six directly ``` salt/_modules/metalk8s.py:10: [E9405(blacklisted-external-import), ] Uses of an external blacklisted import 'six': Please use 'import salt.ext.six as six' ``` --- salt/_modules/metalk8s.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s.py b/salt/_modules/metalk8s.py index 1419ba04d7..f63e5780f9 100644 --- a/salt/_modules/metalk8s.py +++ b/salt/_modules/metalk8s.py @@ -7,13 +7,13 @@ import logging import os.path import re -import six import socket import tempfile import textwrap import time from salt.pillar import get_pillar +from salt.ext import six from salt.exceptions import CommandExecutionError import salt.loader import salt.template From 53301a7590a12d1145988112163013289a99a14b Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:06:28 +0100 Subject: [PATCH 16/63] salt-lint: metalk8s module fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s.py:102: [W0707(raise-missing-from), minions_by_role] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s.py:348: [W0707(raise-missing-from), format_slots] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s.py | 8 ++++---- salt/tests/unit/modules/files/test_metalk8s.yaml | 2 +- salt/tests/unit/modules/test_metalk8s.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/salt/_modules/metalk8s.py b/salt/_modules/metalk8s.py index f63e5780f9..4fda3acc83 100644 --- a/salt/_modules/metalk8s.py +++ b/salt/_modules/metalk8s.py @@ -100,8 +100,8 @@ def minions_by_role(role, nodes=None): nodes = __pillar__['metalk8s']['nodes'] except Exception as exc: raise CommandExecutionError( - "Can't retrieve 'metalk8s:nodes' pillar: {}".format(exc) - ) + "Can't retrieve 'metalk8s:nodes' pillar" + ) from exc pillar_errors = nodes.pop('_errors', None) if pillar_errors: @@ -346,8 +346,8 @@ def format_slots(data): return slots_callers[fmt[1]][fun](*args, **kwargs) except Exception as exc: raise CommandExecutionError( - "Unable to compute slot '{}': {}".format(data, exc) - ) + "Unable to compute slot '{}'".format(data) + ) from exc return data diff --git a/salt/tests/unit/modules/files/test_metalk8s.yaml b/salt/tests/unit/modules/files/test_metalk8s.yaml index 1e23b88f51..7e0be0fb8f 100644 --- a/salt/tests/unit/modules/files/test_metalk8s.yaml +++ b/salt/tests/unit/modules/files/test_metalk8s.yaml @@ -327,7 +327,7 @@ format_slots: slots_returns: my_mod.my_fun: null raises: True - result: "Unable to compute slot '__slot__:salt:my_mod.my_fun\\(\\)': An error has occurred" + result: "Unable to compute slot '__slot__:salt:my_mod.my_fun\\(\\)'" manage_static_pod_manifest: # Nominal: pre-cached source diff --git a/salt/tests/unit/modules/test_metalk8s.py b/salt/tests/unit/modules/test_metalk8s.py index 35a6014a42..5de4cbf766 100644 --- a/salt/tests/unit/modules/test_metalk8s.py +++ b/salt/tests/unit/modules/test_metalk8s.py @@ -107,7 +107,7 @@ def test_format_san(self, names, result): ({'node1': {}, 'node2': {}}, 'master', []), ({'node1': {'roles': ['node']}, 'node2': {'roles': ['node']}}, 'master', []), (None, 'master', ['node1'], False, {'node1': {'roles': ['master']}}), - (None, 'master', "Can't retrieve 'metalk8s:nodes' pillar: 'nodes'", True), + (None, 'master', "Can't retrieve 'metalk8s:nodes' pillar", True), (None, 'master', "Can't retrieve minions by role because of errors in pillar 'metalk8s:nodes': Error in pillar", True, {'_errors': ['Error in pillar']}) ]) def test_minions_by_role(self, nodes, role, result, From 45887c6da9303f606a1bf3d11208b5b686c2d2e8 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:08:35 +0100 Subject: [PATCH 17/63] salt-lint: metalk8s module fix "resource-leakage" Use `fopen` from salt instead of classic `open` ``` salt/_modules/metalk8s.py:408: [W8470(resource-leakage), _atomic_copy] Resource leakage detected. Please use 'with salt.utils.files.fopen()' instead of 'with open()'. It assures salt does not leak file handles. ``` --- salt/_modules/metalk8s.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s.py b/salt/_modules/metalk8s.py index 4fda3acc83..39ab90efb2 100644 --- a/salt/_modules/metalk8s.py +++ b/salt/_modules/metalk8s.py @@ -405,7 +405,7 @@ def _atomic_write( def _atomic_copy( source, dest, user, group, mode, tmp_prefix, ): # pragma: no cover - with open(source, mode='rb') as f: + with salt.utils.files.fopen(source, mode='rb') as f: contents = f.read() _atomic_write(contents, dest, user, group, mode, tmp_prefix) From 72b91ea434371b3b6e0a7a72c461670f6939dd21 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:19:34 +0100 Subject: [PATCH 18/63] salt-lint: metalk8s module fix "unused-variable" Remove the unused variable ``` salt/_modules/metalk8s.py:382: [W0612(unused-variable), _atomic_write] Unused variable 'base_name' ``` --- salt/_modules/metalk8s.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/_modules/metalk8s.py b/salt/_modules/metalk8s.py index 39ab90efb2..b03b6913d2 100644 --- a/salt/_modules/metalk8s.py +++ b/salt/_modules/metalk8s.py @@ -379,7 +379,6 @@ def _atomic_write( the target. Finally, we link the temporary file contents to the destination filename. """ - base_name = os.path.basename(dest) dir_name = os.path.dirname(dest) uid = __salt__['file.user_to_uid'](user) From 7bee2f0ba264009ca3523817393a42fbc4a8f99d Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:23:39 +0100 Subject: [PATCH 19/63] salt-lint: metalk8s module fix "str-format-in-logging" Replace the `format` inside logging by a logging formatting ``` salt/_modules/metalk8s.py:473: [E1323(str-format-in-logging), manage_static_pod_manifest] String formatting used in logging: "'Cached source file {} does not match expected checksum, will fetch it again'.format(source_filename)" ``` --- salt/_modules/metalk8s.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/salt/_modules/metalk8s.py b/salt/_modules/metalk8s.py index b03b6913d2..f9dfa79bf7 100644 --- a/salt/_modules/metalk8s.py +++ b/salt/_modules/metalk8s.py @@ -470,8 +470,9 @@ def _clean_tmp(sfn): cached_hash = get_hash(source_filename, form=hash_type) if source_sum.get("hsum") != cached_hash: log.debug( - "Cached source file {} does not match expected checksum, " - "will fetch it again".format(source_filename) + "Cached source file %s does not match expected checksum, " + "will fetch it again", + source_filename ) source_filename = '' # Reset source filename to fetch it again From 2fe35fdc54ab992d5ec8954a6a785754cbe81e97 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:19:49 +0100 Subject: [PATCH 20/63] salt-lint: metalk8s_service_configuration fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s_service_configuration.py:67: [W0707(raise-missing-from), get_service_conf] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_service_configuration.py:81: [W0707(raise-missing-from), get_service_conf] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_service_configuration.py:87: [W0707(raise-missing-from), get_service_conf] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_service_configuration.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/salt/_modules/metalk8s_service_configuration.py b/salt/_modules/metalk8s_service_configuration.py index f4fdf0fa1e..a0abf8e7df 100644 --- a/salt/_modules/metalk8s_service_configuration.py +++ b/salt/_modules/metalk8s_service_configuration.py @@ -65,9 +65,8 @@ def get_service_conf( ) except ValueError as exc: raise CommandExecutionError( - 'Failed to read ConfigMap object {}: {!s}' - .format(configmap_name, exc) - ) + 'Failed to read ConfigMap object {}'.format(configmap_name) + ) from exc if manifest is None: raise CommandExecutionError( @@ -79,16 +78,14 @@ def get_service_conf( config = yaml.safe_load(conf_section) or {} except yaml.YAMLError as exc: raise CommandExecutionError( - 'Invalid YAML format in ConfigMap {}: {!s}'.format( - configmap_name, exc - ) - ) + 'Invalid YAML format in ConfigMap {}'.format(configmap_name) + ) from exc except Exception as exc: raise CommandExecutionError( - 'Failed loading `config.yaml` from ConfigMap {}: {!s}'.format( - configmap_name, exc + 'Failed loading `config.yaml` from ConfigMap {}'.format( + configmap_name ) - ) + ) from exc if not config: raise CommandExecutionError( 'Expected `config.yaml` as yaml in the ConfigMap {} but got {}' From 378cc54b3a075899afe4bc68ca7d23d15814f25c Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:26:59 +0100 Subject: [PATCH 21/63] salt-lint: metalk8s_service_configuration module fix "unused-argument" Remove the unused argument ``` salt/_modules/metalk8s_service_configuration.py:20: [W0613(unused-argument), get_service_conf] Unused argument 'kwargs' ``` --- salt/_modules/metalk8s_service_configuration.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/salt/_modules/metalk8s_service_configuration.py b/salt/_modules/metalk8s_service_configuration.py index a0abf8e7df..ff25c9c777 100644 --- a/salt/_modules/metalk8s_service_configuration.py +++ b/salt/_modules/metalk8s_service_configuration.py @@ -21,8 +21,7 @@ def get_service_conf( configmap_name, default_csc, apiVersion=None, - kind=None, - **kwargs + kind=None ): """Reads a ConfigMap from the name specified From 3291a9fcb252ba520bff02cd42a35e05ecd92e76 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:21:38 +0100 Subject: [PATCH 22/63] salt-lint: metalk8s_solutions_k8s module fix "unused-import" Remove unused import ``` salt/_modules/metalk8s_solutions_k8s.py:9: [W0611(unused-import), ] Unused CommandExecutionError imported from salt.exceptions ``` --- salt/_modules/metalk8s_solutions_k8s.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/salt/_modules/metalk8s_solutions_k8s.py b/salt/_modules/metalk8s_solutions_k8s.py index b27478d58b..68098eb729 100644 --- a/salt/_modules/metalk8s_solutions_k8s.py +++ b/salt/_modules/metalk8s_solutions_k8s.py @@ -6,8 +6,6 @@ import json import logging -from salt.exceptions import CommandExecutionError - log = logging.getLogger(__name__) __virtualname__ = 'metalk8s_solutions' From fab98f3439a19d16efd4e89ac2e6c1e8a97b6865 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:25:51 +0100 Subject: [PATCH 23/63] salt-lint: metalk8s_solutions module fix "resource-leakage" Use `fopen` from salt instead of classic `open` ``` salt/_modules/metalk8s_solutions.py:40: [W8470(resource-leakage), _load_config_file] Resource leakage detected. Please use 'with salt.utils.files.fopen()' instead of 'with open()'. It assures salt does not leak file handles. salt/_modules/metalk8s_solutions.py:51: [W8470(resource-leakage), _write_config_file] Resource leakage detected. Please use 'with salt.utils.files.fopen()' instead of 'with open()'. It assures salt does not leak file handles. ``` --- salt/_modules/metalk8s_solutions.py | 4 ++-- salt/tests/unit/modules/test_metalk8s_solutions.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/salt/_modules/metalk8s_solutions.py b/salt/_modules/metalk8s_solutions.py index ef8e7aeb10..f538726298 100644 --- a/salt/_modules/metalk8s_solutions.py +++ b/salt/_modules/metalk8s_solutions.py @@ -37,7 +37,7 @@ def __virtual__(): def _load_config_file(create=False): try: - with open(CONFIG_FILE, 'r') as fd: + with salt.utils.files.fopen(CONFIG_FILE, 'r') as fd: return yaml.safe_load(fd) except IOError as exc: if create and exc.errno == errno.ENOENT: @@ -48,7 +48,7 @@ def _load_config_file(create=False): def _write_config_file(data): try: - with open(CONFIG_FILE, 'w') as fd: + with salt.utils.files.fopen(CONFIG_FILE, 'w') as fd: yaml.safe_dump(data, fd) except Exception as exc: msg = 'Failed to write Solutions config file at "{}": {}'.format( diff --git a/salt/tests/unit/modules/test_metalk8s_solutions.py b/salt/tests/unit/modules/test_metalk8s_solutions.py index 00b758f339..8dd703c882 100644 --- a/salt/tests/unit/modules/test_metalk8s_solutions.py +++ b/salt/tests/unit/modules/test_metalk8s_solutions.py @@ -47,7 +47,7 @@ def test_read_config(self, create=False, config=None, result=None, errno.ENOENT, "No such file or directory" ) - with patch("metalk8s_solutions.open", open_mock), \ + with patch("salt.utils.files.fopen", open_mock), \ patch("metalk8s_solutions._write_config_file", MagicMock()): if raises: self.assertRaisesRegex( @@ -119,7 +119,7 @@ def _yaml_safe_dump_mock(data, _): with patch("metalk8s_solutions.list_available", list_available_mock), \ patch("metalk8s_solutions.read_config", read_config_mock), \ - patch("metalk8s_solutions.open", mock_open()), \ + patch("salt.utils.files.fopen", mock_open()), \ patch("yaml.safe_dump", yaml_safe_dump_mock): if raises: self.assertRaisesRegex( @@ -161,7 +161,7 @@ def _yaml_safe_dump_mock(data, _): with patch("metalk8s_solutions.read_config", read_config_mock), \ patch("yaml.safe_dump", yaml_safe_dump_mock), \ - patch("metalk8s_solutions.open", mock_open()): + patch("salt.utils.files.fopen", mock_open()): if raises: self.assertRaisesRegex( CommandExecutionError, From 1d94ff45b55e1145cee4fa634fadd0e7b8e1c105 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:31:20 +0100 Subject: [PATCH 24/63] salt-lint: metalk8s_solutions module fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s_solutions.py:46: [W0707(raise-missing-from), _load_config_file] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_solutions.py:57: [W0707(raise-missing-from), _write_config_file] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_solutions.py:328: [W0707(raise-missing-from), manifest_from_iso] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_solutions.py | 16 ++++++++-------- .../modules/files/test_metalk8s_solutions.yaml | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/salt/_modules/metalk8s_solutions.py b/salt/_modules/metalk8s_solutions.py index f538726298..facd66e67d 100644 --- a/salt/_modules/metalk8s_solutions.py +++ b/salt/_modules/metalk8s_solutions.py @@ -42,8 +42,8 @@ def _load_config_file(create=False): except IOError as exc: if create and exc.errno == errno.ENOENT: return _create_config_file() - msg = 'Failed to load "{}": {}'.format(CONFIG_FILE, str(exc)) - raise CommandExecutionError(message=msg) + msg = 'Failed to load "{}"'.format(CONFIG_FILE) + raise CommandExecutionError(message=msg) from exc def _write_config_file(data): @@ -51,10 +51,10 @@ def _write_config_file(data): with salt.utils.files.fopen(CONFIG_FILE, 'w') as fd: yaml.safe_dump(data, fd) except Exception as exc: - msg = 'Failed to write Solutions config file at "{}": {}'.format( - CONFIG_FILE, exc + msg = 'Failed to write Solutions config file at "{}"'.format( + CONFIG_FILE ) - raise CommandExecutionError(message=msg) + raise CommandExecutionError(message=msg) from exc def _create_config_file(): @@ -326,10 +326,10 @@ def manifest_from_iso(path): manifest = yaml.safe_load(result['stdout']) except yaml.YAMLError as exc: raise CommandExecutionError( - "Failed to load YAML from Solution manifest {}: {!s}".format( - path, exc + "Failed to load YAML from Solution manifest {}".format( + path ) - ) + ) from exc return _archive_info_from_manifest(manifest) diff --git a/salt/tests/unit/modules/files/test_metalk8s_solutions.yaml b/salt/tests/unit/modules/files/test_metalk8s_solutions.yaml index f9ff37d1b2..562a09d034 100644 --- a/salt/tests/unit/modules/files/test_metalk8s_solutions.yaml +++ b/salt/tests/unit/modules/files/test_metalk8s_solutions.yaml @@ -23,7 +23,7 @@ read_config: my-solution: 1.0.0 # Nok - no solutions configuration file, create left to default (False) - raises: True - result: 'Failed to load ".*": .*' + result: 'Failed to load ".*"' # Nok - no solutions configuration kind - raises: True config: |- @@ -335,7 +335,7 @@ manifest_from_iso: raises: True # Nok - invalid YAML - manifest: '{' - result: Failed to load YAML from Solution manifest .* + result: Failed to load YAML from Solution manifest raises: True list_available: From 60b8b9276196d2849ace24a6cfbc17fd94523e5c Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:32:47 +0100 Subject: [PATCH 25/63] salt-lint: metalk8s_sysctl module fix "unused-import" Remove unused import ``` salt/_modules/metalk8s_sysctl.py:7: [W0611(unused-import), ] Unused import itertools ``` --- salt/_modules/metalk8s_sysctl.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/_modules/metalk8s_sysctl.py b/salt/_modules/metalk8s_sysctl.py index 92588b3c9c..39190c7ab8 100644 --- a/salt/_modules/metalk8s_sysctl.py +++ b/salt/_modules/metalk8s_sysctl.py @@ -4,7 +4,6 @@ """ import configparser -import itertools import pathlib from salt.exceptions import CommandExecutionError From 4a0746dc177b744ce5c51b2d94f65c2ff6ce7994 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:35:19 +0100 Subject: [PATCH 26/63] salt-lint: metalk8s_sysctl module fix "raise-missing-from" Disable "raise-missing-from" as it's known exception and we do not want to have upper exceptions raised ``` salt/_modules/metalk8s_sysctl.py:78: [W0707(raise-missing-from), has_precedence] Consider explicitly re-raising using the 'from' keyword salt/_modules/metalk8s_sysctl.py:84: [W0707(raise-missing-from), has_precedence] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_sysctl.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/_modules/metalk8s_sysctl.py b/salt/_modules/metalk8s_sysctl.py index 39190c7ab8..0e054d2151 100644 --- a/salt/_modules/metalk8s_sysctl.py +++ b/salt/_modules/metalk8s_sysctl.py @@ -75,13 +75,13 @@ def has_precedence(name, value, config, strict=False): for sysctl_file in sysctl_files: sysctl_name = pathlib.PurePath(sysctl_file).name if sysctl_name == config_name: - raise CommandExecutionError( + raise CommandExecutionError( # pylint: disable=raise-missing-from "'{0}' has a higher precedence and overrides '{1}'" .format(sysctl_file, config) ) # The target file is not in a directory checked by the system - raise CommandExecutionError( + raise CommandExecutionError( # pylint: disable=raise-missing-from "{0} is not a correct path for a sysctl configuration " "file, please use one of the following:\n- {1}" .format(config, "\n- ".join(SYSCTL_CFG_DIRECTORIES)) From d523d7a48189140493ae97c39d2fb16b5c1a0ef6 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:37:08 +0100 Subject: [PATCH 27/63] salt-lint: metalk8s_sysctl module fix "resource-leakage" Use `fopen` from salt instead of classic `open` ``` salt/_modules/metalk8s_sysctl.py:94: [W8470(resource-leakage), has_precedence] Resource leakage detected. Please use 'with salt.utils.files.fopen()' instead of 'with open()'. It assures salt does not leak file handles. ``` --- salt/_modules/metalk8s_sysctl.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s_sysctl.py b/salt/_modules/metalk8s_sysctl.py index 0e054d2151..b2a48b0842 100644 --- a/salt/_modules/metalk8s_sysctl.py +++ b/salt/_modules/metalk8s_sysctl.py @@ -7,6 +7,7 @@ import pathlib from salt.exceptions import CommandExecutionError +import salt.utils.files __virtualname__ = 'metalk8s_sysctl' @@ -91,7 +92,7 @@ def has_precedence(name, value, config, strict=False): epured_value = " ".join(str(value).split()) for sysctl_file in sysctl_files: - with open(sysctl_file, 'r') as sysctl_fd: + with salt.utils.files.fopen(sysctl_file, 'r') as sysctl_fd: parser.read_file(['[global]', *sysctl_fd], source=sysctl_file) sysctl = dict(parser.items('global')) parser.remove_section('global') From 16d8116717e59c4f3b8c09dff34c63ab54861911 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:39:02 +0100 Subject: [PATCH 28/63] salt-lint: metalk8s_volumes module "2 spaces before inline comment" Add 2 spaces before inline comments ``` salt/_modules/metalk8s_volumes.py:366: [E8261(at-least-two-spaces-before-inline-comment), ] PEP8 E261: at least two spaces before inline comment salt/_modules/metalk8s_volumes.py:404: [E8261(at-least-two-spaces-before-inline-comment), ] PEP8 E261: at least two spaces before inline comment ``` --- salt/_modules/metalk8s_volumes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/_modules/metalk8s_volumes.py b/salt/_modules/metalk8s_volumes.py index a788410d6b..660c321905 100644 --- a/salt/_modules/metalk8s_volumes.py +++ b/salt/_modules/metalk8s_volumes.py @@ -363,7 +363,7 @@ def prepare(self, force=False): @property def is_cleaned_up(self): - return True # Nothing to do so it's always True. + return True # Nothing to do so it's always True. def clean_up(self): return # Nothing to do @@ -401,7 +401,7 @@ def is_prepared(self): return True device = os.path.basename(self.path) if self._kind == DeviceType.DISK: - device += '1' # In DISK case we always have a single partition. + device += '1' # In DISK case we always have a single partition. try: return _device_name(self.persistent_path) == device # Expected exception if the symlink doesn't exist. From c9c030504d597c2003fa5b3b821017bdc49bc005 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 14:58:17 +0100 Subject: [PATCH 29/63] salt-lint: metalk8s_volumes module fix "2-blank-lines" Add one more blank line between different functions ``` salt/_modules/metalk8s_volumes.py:371: [E8302(expected-2-blank-lines-found-0), ] PEP8 E302: expected 2 blank lines, found 1 salt/_modules/metalk8s_volumes.py:611: [E8302(expected-2-blank-lines-found-0), ] PEP8 E302: expected 2 blank lines, found 1 ``` --- salt/_modules/metalk8s_volumes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/salt/_modules/metalk8s_volumes.py b/salt/_modules/metalk8s_volumes.py index 660c321905..3614d8b90c 100644 --- a/salt/_modules/metalk8s_volumes.py +++ b/salt/_modules/metalk8s_volumes.py @@ -368,6 +368,7 @@ def is_cleaned_up(self): def clean_up(self): return # Nothing to do + class RawBlockDeviceBlock(RawBlockDevice): def __init__(self, volume): super(RawBlockDeviceBlock, self).__init__(volume) @@ -608,6 +609,7 @@ def _mkfs_xfs(path, uuid, force=False, options=None): command.append(path) return command + def prepare_block(path, name, uuid): """Prepare a "Block" volume. From 0c639e73bfd08af6daf3efa2d03a492a64d4a5b3 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:00:13 +0100 Subject: [PATCH 30/63] salt-lint: metalk8s_volumes module fix "backslash-is-redundant-" Re-format to not use `backslash` inside brackets ``` salt/_modules/metalk8s_volumes.py:250: [E8502(the-backslash-is-redundant-between-brackets), ] PEP8 E502: the backslash is redundant between brackets ``` --- salt/_modules/metalk8s_volumes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/salt/_modules/metalk8s_volumes.py b/salt/_modules/metalk8s_volumes.py index 3614d8b90c..624c0709a4 100644 --- a/salt/_modules/metalk8s_volumes.py +++ b/salt/_modules/metalk8s_volumes.py @@ -247,8 +247,10 @@ def prepare(self, force=False): 'backing device `{}` already formatted'.format(self.path) ) if device_info.has_partition: - raise Exception('backing device `{}` contains a partition table'\ - .format(self.path)) + raise Exception( + 'backing device `{}` contains a partition table' + .format(self.path) + ) storage_class = self.get('spec.storageClass') # If we got a string that means the name wasn't replaced by the object. if isinstance(storage_class, six.string_types): From 1fb25e4325922b312be900601bc0a0aac8844f61 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:02:06 +0100 Subject: [PATCH 31/63] salt-lint: metalk8s_volumes module fix "blacklisted-module" Use six module from salt instead of six directly ``` salt/_modules/metalk8s_volumes.py:14: [E9405(blacklisted-external-import), ] Uses of an external blacklisted import 'six': Please use 'import salt.ext.six as six' ``` --- salt/_modules/metalk8s_volumes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s_volumes.py b/salt/_modules/metalk8s_volumes.py index 624c0709a4..cb50e9bbf6 100644 --- a/salt/_modules/metalk8s_volumes.py +++ b/salt/_modules/metalk8s_volumes.py @@ -11,12 +11,12 @@ import re import operator import os -import six import time import logging from salt.exceptions import CommandExecutionError +from salt.ext import six log = logging.getLogger(__name__) From bf7abcd1ddec2d2ce1254547a0883f20abf1cc9f Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:03:21 +0100 Subject: [PATCH 32/63] salt-lint: metalk8s_volumes module fix "unused-import" Remove unused import ``` salt/_modules/metalk8s_volumes.py:7: [W0611(unused-import), ] Unused import fcntl ``` --- salt/_modules/metalk8s_volumes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/_modules/metalk8s_volumes.py b/salt/_modules/metalk8s_volumes.py index cb50e9bbf6..b6398199bb 100644 --- a/salt/_modules/metalk8s_volumes.py +++ b/salt/_modules/metalk8s_volumes.py @@ -4,7 +4,6 @@ import abc import contextlib import errno -import fcntl import functools import glob import json From ad7a32129bfda9ddecb59c9b80bb8b82c8c043f5 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:08:16 +0100 Subject: [PATCH 33/63] salt-lint: metalk8s_volumes module fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_modules/metalk8s_volumes.py:300: [W0707(raise-missing-from), SparseLoopDevice.create] Consider explicitly re-raising using the 'from' keyword ``` Disable "raise-missing-from" as it's known exception and we do not want to have upper exceptions raised ``` salt/_modules/metalk8s_volumes.py:591: [W0707(raise-missing-from), _mkfs] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_modules/metalk8s_volumes.py | 8 ++++---- salt/tests/unit/modules/files/test_metalk8s_volumes.yaml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/salt/_modules/metalk8s_volumes.py b/salt/_modules/metalk8s_volumes.py index b6398199bb..86a59ce3b4 100644 --- a/salt/_modules/metalk8s_volumes.py +++ b/salt/_modules/metalk8s_volumes.py @@ -297,9 +297,9 @@ def create(self): os.unlink(self.path) raise except OSError as exn: - raise Exception('cannot create sparse file at {}: {}'.format( - self.path, exn - )) + raise Exception('cannot create sparse file at {}'.format( + self.path + )) from exn def prepare(self, force=False): # We format a "normal" file, not a block device: we need force=True. @@ -588,7 +588,7 @@ def _mkfs(path, fs_type, uuid, force=False, options=None): try: return globals()[funcname](path, uuid, force, options) except KeyError: - raise ValueError('unsupported filesystem: {}'.format(fs_type)) + raise ValueError('unsupported filesystem: {}'.format(fs_type)) # pylint: disable=raise-missing-from def _mkfs_ext4(path, uuid, force=False, options=None): diff --git a/salt/tests/unit/modules/files/test_metalk8s_volumes.yaml b/salt/tests/unit/modules/files/test_metalk8s_volumes.yaml index fb978d1ee6..5c4e5dbcc0 100644 --- a/salt/tests/unit/modules/files/test_metalk8s_volumes.yaml +++ b/salt/tests/unit/modules/files/test_metalk8s_volumes.yaml @@ -413,7 +413,7 @@ create: - name: my-sparse-volume pillar_volumes: *volumes_details ftruncate: False - raise_msg: "cannot create sparse file at .*: An error has occurred" + raise_msg: "cannot create sparse file at .*" ## SPARSE block volume # create a simple sparse volume @@ -424,7 +424,7 @@ create: - name: my-sparse-block-volume pillar_volumes: *volumes_details ftruncate: False - raise_msg: "cannot create sparse file at .*: An error has occurred" + raise_msg: "cannot create sparse file at .*" ## RAW BLOCK DEVICE volume # create on raw block device (nothing to create) From 20ec13164edda2771ef0163e79d5894706558d99 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:28:15 +0100 Subject: [PATCH 34/63] salt-lint: metalk8s_volumes module fix "str-format-in-logging" Replace the `format` inside logging by a logging formatting ``` salt/_modules/metalk8s_volumes.py:318: [E1323(str-format-in-logging), SparseLoopDevice.clean_up] String formatting used in logging: "'{} already removed'.format(exn.filename)" ``` --- salt/_modules/metalk8s_volumes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_modules/metalk8s_volumes.py b/salt/_modules/metalk8s_volumes.py index 86a59ce3b4..b861f6ac13 100644 --- a/salt/_modules/metalk8s_volumes.py +++ b/salt/_modules/metalk8s_volumes.py @@ -315,7 +315,7 @@ def clean_up(self): except OSError as exn: if exn.errno != errno.ENOENT: raise - log.warning('{} already removed'.format(exn.filename)) + log.warning('%s already removed', exn.filename) class SparseLoopDeviceBlock(SparseLoopDevice): From abff661692492041befa01c48c0fe0091ee1ba50 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:10:11 +0100 Subject: [PATCH 35/63] salt-lint: containerd state fix "too-many-blank-lines" Remove extra blank lines ``` salt/_states/containerd.py:43: [E8303(too-many-blank-lines), ] PEP8 E303: too many blank lines (2) ``` --- salt/_states/containerd.py | 1 - 1 file changed, 1 deletion(-) diff --git a/salt/_states/containerd.py b/salt/_states/containerd.py index 1ce14f3780..b536c46cba 100644 --- a/salt/_states/containerd.py +++ b/salt/_states/containerd.py @@ -39,7 +39,6 @@ def image_managed(name, archive_path=None): 'comment': '', } - if __salt__['cri.available'](name): ret['comment'] = 'Image already available' ret['result'] = True From de5402eced21ad540025ec33712832b0c92abef6 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:29:51 +0100 Subject: [PATCH 36/63] salt-lint: kubeconfig state fix "unused-argument" Remove the unused argument ``` salt/_states/kubeconfig.py:12: [W0613(unused-argument), managed] Unused argument 'kwargs' ``` --- salt/_states/kubeconfig.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/salt/_states/kubeconfig.py b/salt/_states/kubeconfig.py index 75f5fcfd6c..cc99bb6879 100644 --- a/salt/_states/kubeconfig.py +++ b/salt/_states/kubeconfig.py @@ -16,8 +16,7 @@ def managed(name, apiserver, cluster, days_valid=365, - days_remaining=90, - **kwargs): + days_remaining=90): """Generate kubeconfig file with identities for control plane components""" ret = { 'name': name, From f1e27405cf33425ead8a317d7c2f0dfbc120796e Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:11:45 +0100 Subject: [PATCH 37/63] salt-lint: metalk8s_kubernetes state fix "unused-import" Remove unused import ``` salt/_states/metalk8s_kubernetes.py:10: [W0611(unused-import), ] Unused yaml imported from salt.utils ``` --- salt/_states/metalk8s_kubernetes.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/salt/_states/metalk8s_kubernetes.py b/salt/_states/metalk8s_kubernetes.py index 852c971a36..9d909de504 100644 --- a/salt/_states/metalk8s_kubernetes.py +++ b/salt/_states/metalk8s_kubernetes.py @@ -7,8 +7,6 @@ """ import time -from salt.utils import yaml - __virtualname__ = 'metalk8s_kubernetes' From 1ff9857166758b624e97a461276e28983aa6e3aa Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:17:12 +0100 Subject: [PATCH 38/63] salt-lint: metalk8s state fix "undefined-variable" Add missing import for `CommandExecutionError` exception ``` salt/_states/metalk8s.py:81: [E0602(undefined-variable), static_pod_managed] Undefined variable 'CommandExecutionError' ``` --- salt/_states/metalk8s.py | 1 + 1 file changed, 1 insertion(+) diff --git a/salt/_states/metalk8s.py b/salt/_states/metalk8s.py index af35193dc4..2784b36e12 100644 --- a/salt/_states/metalk8s.py +++ b/salt/_states/metalk8s.py @@ -5,6 +5,7 @@ import traceback import re +from salt.exceptions import CommandExecutionError from salt.ext import six From c81365e6d257b3add993103212fbd5ffc776dbbe Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:19:08 +0100 Subject: [PATCH 39/63] salt-lint: metalk8s_volumes state fix "broad-except" Disable "broad-except" as we want to catch all exceptions ``` salt/_states/metalk8s_volumes.py:43: [W0703(broad-except), present] Catching too general exception Exception salt/_states/metalk8s_volumes.py:78: [W0703(broad-except), prepared] Catching too general exception Exception salt/_states/metalk8s_volumes.py:112: [W0703(broad-except), removed] Catching too general exception Exception ``` --- salt/_states/metalk8s_volumes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/_states/metalk8s_volumes.py b/salt/_states/metalk8s_volumes.py index d739f7e522..49b891222e 100644 --- a/salt/_states/metalk8s_volumes.py +++ b/salt/_states/metalk8s_volumes.py @@ -40,7 +40,7 @@ def present(name): # Let's go for real. try: __salt__['metalk8s_volumes.create'](name) - except Exception as exn: + except Exception as exn: # pylint: disable=broad-except ret['result'] = False ret['comment'] = 'Cannot create storage for volume {}: {}.'\ .format(name, exn) @@ -75,7 +75,7 @@ def prepared(name): # Let's go for real. try: __salt__['metalk8s_volumes.prepare'](name) - except Exception as exn: + except Exception as exn: # pylint: disable=broad-except ret['result'] = False ret['comment'] = 'Failed to prepare volume {}: {}.'.format(name, exn) else: @@ -109,7 +109,7 @@ def removed(name): # Let's go for real. try: __salt__['metalk8s_volumes.clean_up'](name) - except Exception as exn: + except Exception as exn: # pylint: disable=broad-except ret['result'] = False ret['comment'] = 'Failed to clean up volume {}: {}.'.format(name, exn) else: From 5526f7c4bb99daa6ff4281d4e39b773f84b90dd2 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:19:57 +0100 Subject: [PATCH 40/63] salt-lint: metalk8s_volumes state fix "unused-import" Remove unused import ``` salt/_states/metalk8s_volumes.py:6: [W0611(unused-import), ] Unused CommandExecutionError imported from salt.exceptions ``` --- salt/_states/metalk8s_volumes.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/salt/_states/metalk8s_volumes.py b/salt/_states/metalk8s_volumes.py index 49b891222e..3217c67c38 100644 --- a/salt/_states/metalk8s_volumes.py +++ b/salt/_states/metalk8s_volumes.py @@ -3,8 +3,6 @@ import logging -from salt.exceptions import CommandExecutionError - log = logging.getLogger(__name__) From 3c71df67ea3c85bbb211e6fc2652c9b2cb411bc9 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:23:16 +0100 Subject: [PATCH 41/63] salt-lint: kubernetes_utils utils fix "arguments-differ" Rename `method` to `verb` in initial class so that arguments name match ``` salt/_utils/kubernetes_utils.py:413: [W0221(arguments-differ), CustomApiClient._method] Parameters differ from overridden '_method' method ``` --- salt/_utils/kubernetes_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/_utils/kubernetes_utils.py b/salt/_utils/kubernetes_utils.py index eb63644168..2f6b6e6d9c 100644 --- a/salt/_utils/kubernetes_utils.py +++ b/salt/_utils/kubernetes_utils.py @@ -156,10 +156,10 @@ def api(self): def _method_name(self, verb): return '{}_{}'.format(verb, self.name) - def _method(self, method): + def _method(self, verb): # Inject the API instance as the first argument, since those methods # are not classmethods, yet stored unbound - return partial(self._api_methods[method], self.api) + return partial(self._api_methods[verb], self.api) class KindInfo(object): From 85413e213a8895925b02c56e12c585074ceee89e Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:27:55 +0100 Subject: [PATCH 42/63] salt-lint: kubernetes_utils utils fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_utils/kubernetes_utils.py:694: [W0707(raise-missing-from), _build_standard_object] Consider explicitly re-raising using the 'from' keyword ``` Disable "raise-missing-from" as it's known exception and we do not want to have upper exceptions raised ``` salt/_utils/kubernetes_utils.py:564: [W0707(raise-missing-from), _DictWrapper.__getattribute__] Consider explicitly re-raising using the 'from' keyword salt/_utils/kubernetes_utils.py:622: [W0707(raise-missing-from), get_kind_info] Consider explicitly re-raising using the 'from' keyword salt/_utils/kubernetes_utils.py:754: [W0707(raise-missing-from), _cast_value] Consider explicitly re-raising using the 'from' keyword salt/_utils/kubernetes_utils.py:783: [W0707(raise-missing-from), _cast_value] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_utils/kubernetes_utils.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/salt/_utils/kubernetes_utils.py b/salt/_utils/kubernetes_utils.py index 2f6b6e6d9c..53613cf6fc 100644 --- a/salt/_utils/kubernetes_utils.py +++ b/salt/_utils/kubernetes_utils.py @@ -561,7 +561,7 @@ def __getattribute__(self, name): for key in self._fields: if _convert_attribute_name(key) == name: return self.from_value(self._fields[key]) - raise AttributeError( + raise AttributeError( # pylint: disable=raise-missing-from "Custom object has no attribute '{}'".format(name) ) @@ -619,7 +619,7 @@ def get_kind_info(manifest): api_version = manifest['apiVersion'] kind = manifest['kind'] except KeyError: - raise ValueError( + raise ValueError( # pylint: disable=raise-missing-from 'Make sure to provide a valid Kubernetes manifest, including' ' `kind` and `apiVersion` fields.' ) @@ -692,10 +692,10 @@ def _build_standard_object(model, manifest): value = _cast_value(src_value, type_str) except TypeError as exc: raise ValueError( - 'Invalid value for attribute {} of a "{}" object: {}.'.format( - src_key, model.__name__, str(exc) + 'Invalid value for attribute {} of a "{}" object'.format( + src_key, model.__name__ ) - ) + ) from exc kwargs[key] = value @@ -751,7 +751,7 @@ def _cast_value(value, type_string): try: return datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%SZ') except (TypeError, ValueError): - raise _type_error(value, expected='a date-time string') + raise _type_error(value, expected='a date-time string') # pylint: disable=raise-missing-from dict_match = DICT_PATTERN.match(type_string) if dict_match is not None: @@ -780,7 +780,7 @@ def _cast_value(value, type_string): model = getattr(k8s_client.models, type_string) except AttributeError: # This should never happen, otherwise this function should get updated - raise ValueError( + raise ValueError( # pylint: disable=raise-missing-from 'Unknown type string provided: {}.'.format(type_string) ) From dcd4720e0976d820d4ffde8f7eceec70ae303404 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:29:42 +0100 Subject: [PATCH 43/63] salt-lint: pillar_utils utils fix "expected-2-blank-lines" Add one more blank line ``` salt/_utils/pillar_utils.py:8: [E8302(expected-2-blank-lines-found-0), ] PEP8 E302: expected 2 blank lines, found 1 ``` --- salt/_utils/pillar_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/salt/_utils/pillar_utils.py b/salt/_utils/pillar_utils.py index 5de387ed16..e1efedf166 100644 --- a/salt/_utils/pillar_utils.py +++ b/salt/_utils/pillar_utils.py @@ -5,6 +5,7 @@ they may be imported as is in external pillar modules. """ + def assert_equals(source_dict, expected_dict): """ Check equality with expected values in dictionary keys. From 3a861f8232cd0e6da70f396240bf03ef6d03bcf6 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:39:38 +0100 Subject: [PATCH 44/63] salt-lint: volume_utils utils fix "backslash-is-redundant" Re-format to not use `backslash` inside brackets ``` salt/_utils/volume_utils.py:280: [E8502(the-backslash-is-redundant-between-brackets), ] PEP8 E502: the backslash is redundant between brackets ``` --- salt/_utils/volume_utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/salt/_utils/volume_utils.py b/salt/_utils/volume_utils.py index 3f5851947c..8f027a858a 100644 --- a/salt/_utils/volume_utils.py +++ b/salt/_utils/volume_utils.py @@ -277,8 +277,10 @@ def _get_flags(klass, kind, default, *args): for arg in args: flag = getattr(klass, arg) if flag is None: - raise ValueError('{} is not a valid flag for the {} prober'\ - .format(arg, kind)) + raise ValueError( + '{} is not a valid flag for the {} prober' + .format(arg, kind) + ) flags.append(flag) return functools.reduce(lambda x, y: x | y, flags, 0) From 04455ecda37d6c1db3504c7a700754a37e3b51fc Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:35:47 +0100 Subject: [PATCH 45/63] salt-lint: metalk8s_endpoints pillar fix "unused-argument" Disable "unused-argument" for `ext_pillar` as we need a specific function signature ``` salt/_pillar/metalk8s_endpoints.py:20: [W0613(unused-argument), ext_pillar] Unused argument 'minion_id' salt/_pillar/metalk8s_endpoints.py:20: [W0613(unused-argument), ext_pillar] Unused argument 'pillar' ``` --- salt/_pillar/metalk8s_endpoints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s_endpoints.py b/salt/_pillar/metalk8s_endpoints.py index f60b341ba9..65d29ae728 100644 --- a/salt/_pillar/metalk8s_endpoints.py +++ b/salt/_pillar/metalk8s_endpoints.py @@ -17,7 +17,7 @@ def __virtual__(): return __virtualname__ -def ext_pillar(minion_id, pillar, kubeconfig): +def ext_pillar(minion_id, pillar, kubeconfig): # pylint: disable=unused-argument services = { "kube-system": ['salt-master', 'repositories'], } From 47d87a7086644cd7dbb6a7267245fe25017871c2 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:40:46 +0100 Subject: [PATCH 46/63] salt-lint: metalk8s_etcd pillar fix "broad-except" Disable "broad-except" as we want to catch all exceptions ``` salt/_pillar/metalk8s_etcd.py:18: [W0703(broad-except), _load_members] Catching too general exception Exception ``` --- salt/_pillar/metalk8s_etcd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s_etcd.py b/salt/_pillar/metalk8s_etcd.py index a0265b25ac..b0e67c5cde 100644 --- a/salt/_pillar/metalk8s_etcd.py +++ b/salt/_pillar/metalk8s_etcd.py @@ -15,7 +15,7 @@ def _load_members(pillar): members = __salt__['metalk8s_etcd.get_etcd_member_list']( nodes=pillar['metalk8s']['nodes'] ) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except members = [] errors.append( 'Error while retrieving etcd cluster members: {}'.format( From 31f381f7fc3c9768316908254cf15cd7d4842a51 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:38:59 +0100 Subject: [PATCH 47/63] salt-lint: metalk8s_etcd pillar fix "unused-argument" Disable "unused-argument" from `ext_pillar` as we need a specific function signature ``` salt/_pillar/metalk8s_etcd.py:32: [W0613(unused-argument), ext_pillar] Unused argument 'minion_id' ``` --- salt/_pillar/metalk8s_etcd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s_etcd.py b/salt/_pillar/metalk8s_etcd.py index b0e67c5cde..c2158d8576 100644 --- a/salt/_pillar/metalk8s_etcd.py +++ b/salt/_pillar/metalk8s_etcd.py @@ -29,5 +29,5 @@ def _load_members(pillar): return result -def ext_pillar(minion_id, pillar): +def ext_pillar(minion_id, pillar): # pylint: disable=unused-argument return {"metalk8s": {'etcd': _load_members(pillar)}} From f9485af1c377aeb3225b5aa6f93193a4d1c644a4 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:42:21 +0100 Subject: [PATCH 48/63] salt-lint: metalk8s_private pillar fix "resource-leakage" Use `fopen` from salt instead of classic `open` ``` salt/_pillar/metalk8s_private.py:19: [W8470(resource-leakage), _read_private_key] Resource leakage detected. Please use 'with salt.utils.files.fopen()' instead of 'with open()'. It assures salt does not leak file handles. ``` --- salt/_pillar/metalk8s_private.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s_private.py b/salt/_pillar/metalk8s_private.py index 25831662f6..1b8c7b06af 100644 --- a/salt/_pillar/metalk8s_private.py +++ b/salt/_pillar/metalk8s_private.py @@ -1,6 +1,7 @@ import errno import logging +import salt.utils.files SA_PRIVATE_KEY_PATH = "/etc/kubernetes/pki/sa.key" APISERVER_KEY_PATH = "/etc/metalk8s/crypt/apiserver.key" @@ -16,7 +17,7 @@ def __virtual__(): def _read_private_key(key_name, key_path): try: - with open(key_path, "r") as key_file: + with salt.utils.files.fopen(key_path, "r") as key_file: key_data = key_file.read() except IOError as exn: if exn.errno == errno.ENOENT: From 7629a812430db18a34d9030fa95df526fc1f011c Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:44:12 +0100 Subject: [PATCH 49/63] salt-lint: metalk8s pillar fix "missing-whitspace-after-comma" Remove uneeded comma ``` salt/_pillar/metalk8s.py:187: [E8231(missing-whitespace-after-comma), ] PEP8 E231: missing whitespace after ',' ``` --- salt/_pillar/metalk8s.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s.py b/salt/_pillar/metalk8s.py index 3d2203a807..33f4df8f9f 100644 --- a/salt/_pillar/metalk8s.py +++ b/salt/_pillar/metalk8s.py @@ -184,7 +184,7 @@ def ext_pillar(minion_id, pillar, bootstrap_config): if not isinstance(metal_data['archives'], list): # Special case for archives in pillar __utils__['pillar_utils.promote_errors'](metal_data, 'archives') - for key in ['ca',]: + for key in ['ca']: __utils__['pillar_utils.promote_errors'](metal_data, key) for key in ['networks', 'metalk8s']: __utils__['pillar_utils.promote_errors'](result, key) From 070c0227be2898b14f825aee7bdc148a4a6dac4b Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:45:46 +0100 Subject: [PATCH 50/63] salt-lint: metalk8s pillar fix "broad-except" Disable "broad-except" as we want to catch all exceptions ``` salt/_pillar/metalk8s.py:28: [W0703(broad-except), _load_config] Catching too general exception Exception ``` --- salt/_pillar/metalk8s.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s.py b/salt/_pillar/metalk8s.py index 33f4df8f9f..7ae09991ca 100644 --- a/salt/_pillar/metalk8s.py +++ b/salt/_pillar/metalk8s.py @@ -25,7 +25,7 @@ def _load_config(path): try: with salt.utils.files.fopen(path, 'rb') as fd: config = salt.utils.yaml.safe_load(fd) or {} - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except return __utils__['pillar_utils.errors_to_dict']([ "Failed to load {}: {}".format(path, exc) ]) From dfc592e0f46296b48b8ab0c592189eef2a1530fa Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:40:11 +0100 Subject: [PATCH 51/63] salt-lint: metalk8s pillar fix "unused-argument" Disable "unused-argument" for `ext_pillar` as we need a specific function signature ``` salt/_pillar/metalk8s.py:156: [W0613(unused-argument), ext_pillar] Unused argument 'minion_id' salt/_pillar/metalk8s.py:156: [W0613(unused-argument), ext_pillar] Unused argument 'pillar' ``` --- salt/_pillar/metalk8s.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s.py b/salt/_pillar/metalk8s.py index 7ae09991ca..462a2b9ea8 100644 --- a/salt/_pillar/metalk8s.py +++ b/salt/_pillar/metalk8s.py @@ -153,7 +153,7 @@ def _load_iso_path(config_data): return res -def ext_pillar(minion_id, pillar, bootstrap_config): +def ext_pillar(minion_id, pillar, bootstrap_config): # pylint: disable=unused-argument config = _load_config(bootstrap_config) if config.get('_errors'): metal_data = __utils__['pillar_utils.errors_to_dict']( From 3e36b1760eba99109c8e0f01cbc98c072063635f Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:48:04 +0100 Subject: [PATCH 52/63] salt-lint: metalk8s_solutions pillar fix "broad-except" Disable "broad-except" as we want to catch all exceptions ``` salt/_pillar/metalk8s_solutions.py:43: [W0703(broad-except), _load_solutions] Catching too general exception Exception salt/_pillar/metalk8s_solutions.py:50: [W0703(broad-except), _load_solutions] Catching too general exception Exception salt/_pillar/metalk8s_solutions.py:70: [W0703(broad-except), _load_solutions] Catching too general exception Exception ``` --- salt/_pillar/metalk8s_solutions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/salt/_pillar/metalk8s_solutions.py b/salt/_pillar/metalk8s_solutions.py index 781bcb26e2..bff81d35c6 100644 --- a/salt/_pillar/metalk8s_solutions.py +++ b/salt/_pillar/metalk8s_solutions.py @@ -40,14 +40,14 @@ def _load_solutions(bootstrap_id): )) result['available'] = available_ret['ret'] - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except errors.append( "Error when listing available Solutions: {}".format(exc) ) try: active = __salt__['metalk8s_solutions.list_active']() - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except errors.append( "Error when listing active Solution versions: {}".format(exc) ) @@ -67,7 +67,7 @@ def _load_solutions(bootstrap_id): try: result['environments'] = \ __salt__['metalk8s_solutions.list_environments']() - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except result['environments'] = __utils__['pillar_utils.errors_to_dict']([ "Error when listing Solution Environments: {}".format(exc) ]) From 8797a940334a788941e6c6d5a6d459abca60a4ea Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:45:16 +0100 Subject: [PATCH 53/63] salt-lint: metalk8s_solutions pillar fix "unused-argument" Disable "unused-argument" for `ext_pillar` as we need a specific function signature ``` salt/_pillar/metalk8s_solutions.py:81: [W0613(unused-argument), ext_pillar] Unused argument 'minion_id' ``` --- salt/_pillar/metalk8s_solutions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_pillar/metalk8s_solutions.py b/salt/_pillar/metalk8s_solutions.py index bff81d35c6..044c5cc01f 100644 --- a/salt/_pillar/metalk8s_solutions.py +++ b/salt/_pillar/metalk8s_solutions.py @@ -78,7 +78,7 @@ def _load_solutions(bootstrap_id): return result -def ext_pillar(minion_id, pillar): +def ext_pillar(minion_id, pillar): # pylint: disable=unused-argument # NOTE: this ext_pillar relies on the `metalk8s_nodes` ext_pillar to find # the Bootstrap minion ID, for the remote execution of # `metalk8s_solutions.list_available`. From 0814b604e8e28e89115c191ac725f6318306f6a9 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:49:35 +0100 Subject: [PATCH 54/63] salt-lint: metalk8s_saltutil runner fix "undefined-variable" Add missing import for `SaltInvocationError` exception ``` salt/_runners/metalk8s_saltutil.py:136: [E0602(undefined-variable), orchestrate_show_sls] Undefined variable 'SaltInvocationError' ``` --- salt/_runners/metalk8s_saltutil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_runners/metalk8s_saltutil.py b/salt/_runners/metalk8s_saltutil.py index e895acc736..3daeaa2972 100644 --- a/salt/_runners/metalk8s_saltutil.py +++ b/salt/_runners/metalk8s_saltutil.py @@ -2,7 +2,7 @@ import logging import time -from salt.exceptions import CommandExecutionError +from salt.exceptions import CommandExecutionError, SaltInvocationError import salt.client import salt.utils.extmods From 445650e63352ed77295dfc9a94489292be1524de Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:50:51 +0100 Subject: [PATCH 55/63] salt-lint: kubernetes_rbac auth fix "expected-2-blank-lines" Add one more blank line ``` salt/_auth/kubernetes_rbac.py:24: [E8302(expected-2-blank-lines-found-0), ] PEP8 E302: expected 2 blank lines, found 1 ``` --- salt/_auth/kubernetes_rbac.py | 1 + 1 file changed, 1 insertion(+) diff --git a/salt/_auth/kubernetes_rbac.py b/salt/_auth/kubernetes_rbac.py index 65d2fce813..2c78b4e360 100644 --- a/salt/_auth/kubernetes_rbac.py +++ b/salt/_auth/kubernetes_rbac.py @@ -21,6 +21,7 @@ __virtualname__ = 'kubernetes_rbac' + def __virtual__(): if MISSING_DEPS: return False, 'Missing Python dependencies: {}'.format( From 7880d10cfd653368304924f30a3532c7e7bfb2f8 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:56:14 +0100 Subject: [PATCH 56/63] salt-lint: kubernetes_rbac auth fix "unused-import" Remove unused import ``` salt/_auth/kubernetes_rbac.py:1: [W0611(unused-import), ] Unused import base64 salt/_auth/kubernetes_rbac.py:10: [W0611(unused-import), ] Unused ApiException imported from kubernetes.client.rest ``` Disable "unused-import" as we import to check for virtual ``` salt/_auth/kubernetes_rbac.py:15: [W0611(unused-import), ] Unused import requests ``` --- salt/_auth/kubernetes_rbac.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/salt/_auth/kubernetes_rbac.py b/salt/_auth/kubernetes_rbac.py index 2c78b4e360..7d7bb205fa 100644 --- a/salt/_auth/kubernetes_rbac.py +++ b/salt/_auth/kubernetes_rbac.py @@ -1,4 +1,3 @@ -import base64 from functools import wraps import logging @@ -7,12 +6,11 @@ try: import kubernetes.client import kubernetes.config - from kubernetes.client.rest import ApiException except ImportError: MISSING_DEPS.append('kubernetes') try: - import requests + import requests # pylint: disable=unused-import except ImportError: MISSING_DEPS.append('requests') From f6b87f966ea95b4210076269e644abf27157a3e0 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 15:58:41 +0100 Subject: [PATCH 57/63] salt-lint: kubernetes_rbac auth fix "undefined-variable" Add missing import for `CommandExecutionError` exception ``` salt/_auth/kubernetes_rbac.py:57: [E0602(undefined-variable), _check_auth_args.wrapped] Undefined variable 'CommandExecutionError' ``` --- salt/_auth/kubernetes_rbac.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/salt/_auth/kubernetes_rbac.py b/salt/_auth/kubernetes_rbac.py index 7d7bb205fa..44fcc08763 100644 --- a/salt/_auth/kubernetes_rbac.py +++ b/salt/_auth/kubernetes_rbac.py @@ -1,6 +1,8 @@ from functools import wraps import logging +from salt.exceptions import CommandExecutionError + MISSING_DEPS = [] try: From bf7866f690cf47edc8d2750c6e77029fb95336ea Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:43:50 +0100 Subject: [PATCH 58/63] salt-lint: kubernetes_rbac auth fix "unused-argument" Disable "unused-argument" for `auth` and `groups` as we need a specific function signature ``` salt/_auth/kubernetes_rbac.py:198: [W0613(unused-argument), groups] Unused argument 'password' ``` Discard `kwargs` argument as it does not change the function signature ``` salt/_auth/kubernetes_rbac.py:180: [W0613(unused-argument), auth] Unused argument 'kwargs' salt/_auth/kubernetes_rbac.py:198: [W0613(unused-argument), groups] Unused argument 'kwargs' ``` --- salt/_auth/kubernetes_rbac.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/_auth/kubernetes_rbac.py b/salt/_auth/kubernetes_rbac.py index 44fcc08763..26120f66d3 100644 --- a/salt/_auth/kubernetes_rbac.py +++ b/salt/_auth/kubernetes_rbac.py @@ -177,7 +177,7 @@ def _load_kubeconfig(opts): @_check_auth_args -def auth(username, token=None, **kwargs): +def auth(username, token=None, **_kwargs): log.info('Authentication request for "%s"', username) kubeconfig = _load_kubeconfig(__opts__) @@ -195,7 +195,7 @@ def auth(username, token=None, **kwargs): @_check_auth_args -def groups(username, password=None, token=None, **kwargs): +def groups(username, password=None, token=None, **_kwargs): # pylint: disable=unused-argument log.info('Groups request for "%s"', username) kubeconfig = _load_kubeconfig(__opts__) From 0dbf83ad1c80934a578cd11788ed44df2c63b042 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 16:00:00 +0100 Subject: [PATCH 59/63] salt-lint: metalk8s_kubeconfig_info beacons fix "blacklisted-module" Use six module from salt instead of six directly ``` salt/_beacons/metalk8s_kubeconfig_info.py:4: [E9405(blacklisted-external-import), ] Uses of an external blacklisted import 'six': Please use 'import salt.ext.six as six' ``` --- salt/_beacons/metalk8s_kubeconfig_info.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/salt/_beacons/metalk8s_kubeconfig_info.py b/salt/_beacons/metalk8s_kubeconfig_info.py index ca31145fa4..0a5d83023c 100644 --- a/salt/_beacons/metalk8s_kubeconfig_info.py +++ b/salt/_beacons/metalk8s_kubeconfig_info.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- import logging -import six + +from salt.ext import six __virtualname__ = 'metalk8s_kubeconfig_info' From 65efea1920ad277a8636edc9067a8fe409549c88 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Mon, 25 Jan 2021 16:01:25 +0100 Subject: [PATCH 60/63] salt-lint: metalk8s_kubernetes renderers fix "raise-missing-from" Use `from` in exception instead of formatting with the exception message ``` salt/_renderers/metalk8s_kubernetes.py:41: [W0707(raise-missing-from), _step_name] Consider explicitly re-raising using the 'from' keyword ``` --- salt/_renderers/metalk8s_kubernetes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salt/_renderers/metalk8s_kubernetes.py b/salt/_renderers/metalk8s_kubernetes.py index 28910444cc..2c6917d621 100644 --- a/salt/_renderers/metalk8s_kubernetes.py +++ b/salt/_renderers/metalk8s_kubernetes.py @@ -37,8 +37,8 @@ def __virtual__(): def _step_name(manifest, absent=False): try: name = manifest['metadata']['name'] - except KeyError: - raise SaltRenderError('Object `metadata.name` must be set.') + except KeyError as exc: + raise SaltRenderError('Object `metadata.name` must be set.') from exc namespace = manifest['metadata'].get('namespace', None) if namespace is not None: From 7d3fcabbc8993c2b104304d7e26bb9be9dcf4d3b Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:47:05 +0100 Subject: [PATCH 61/63] salt-lint: metalk8s_kubernetes renderers fix "unused-argument" Disable "unused-argument" for `render` as we need a specific function signature ``` salt/_renderers/metalk8s_kubernetes.py:73: [W0613(unused-argument), render] Unused argument 'saltenv' salt/_renderers/metalk8s_kubernetes.py:73: [W0613(unused-argument), render] Unused argument 'sls' ``` Discard `kwargs` argument as it does not change the function signature ``` salt/_renderers/metalk8s_kubernetes.py:73: [W0613(unused-argument), render] Unused argument 'kwargs' ``` --- salt/_renderers/metalk8s_kubernetes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_renderers/metalk8s_kubernetes.py b/salt/_renderers/metalk8s_kubernetes.py index 2c6917d621..57d69d89d3 100644 --- a/salt/_renderers/metalk8s_kubernetes.py +++ b/salt/_renderers/metalk8s_kubernetes.py @@ -70,7 +70,7 @@ def _step(manifest, kubeconfig=None, context=None, absent=False): return step_name, {state_func: state_args} -def render(source, saltenv='', sls='', argline='', **kwargs): +def render(source, saltenv='', sls='', argline='', **_kwargs): # pylint: disable=unused-argument args = six.moves.urllib.parse.parse_qs(argline) kubeconfig = args.get('kubeconfig', [None])[0] From 18aacaca58858692a8da26642efa221ae34e9024 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 5 Feb 2021 11:48:31 +0100 Subject: [PATCH 62/63] salt-lint: kubernetes_nodes roster fix "unused-argument" Discard `kwargs` argument as it does not change the function signature ``` salt/_roster/kubernetes_nodes.py:14: [W0613(unused-argument), targets] Unused argument 'kwargs' ``` --- salt/_roster/kubernetes_nodes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/_roster/kubernetes_nodes.py b/salt/_roster/kubernetes_nodes.py index 720d1be18f..6d8214124e 100644 --- a/salt/_roster/kubernetes_nodes.py +++ b/salt/_roster/kubernetes_nodes.py @@ -11,7 +11,7 @@ def __virtual__(): return __virtualname__ -def targets(tgt, tgt_type='glob', **kwargs): +def targets(tgt, tgt_type='glob', **_kwargs): if tgt_type not in ['glob', 'list']: log.error('Only "glob" and "list" lookups are supported for now') return {} From 885810a75e16b9ec8479b03ddd69c1b30ea9dac9 Mon Sep 17 00:00:00 2001 From: Teddy Andrieux Date: Fri, 22 Jan 2021 17:49:41 +0100 Subject: [PATCH 63/63] tox: Add linting for Salt Python modules Add a dedicated `pylintrc` file for all Salt Python modules and run a pylint on all thoses files with tox `lint-python` as well as `./doit.sh lint:python` so that we do some linting check in the CI Fixes: #2649 --- buildchain/buildchain/lint.py | 11 + buildchain/requirements-dev.in | 1 + buildchain/requirements-dev.txt | 79 ++-- salt/.pylintrc | 684 ++++++++++++++++++++++++++++++++ tox.ini | 16 +- 5 files changed, 755 insertions(+), 36 deletions(-) create mode 100644 salt/.pylintrc diff --git a/buildchain/buildchain/lint.py b/buildchain/buildchain/lint.py index 022ce58d97..442e1b63a3 100644 --- a/buildchain/buildchain/lint.py +++ b/buildchain/buildchain/lint.py @@ -57,6 +57,17 @@ def lint_python() -> types.TaskDict: buildchain/'dodo.py', *buildchain.glob('buildchain/*.py'), *buildchain.glob('buildchain/targets/*.py'), + constants.ROOT/'packages/debian/common/download_packages.py', + constants.ROOT/'salt/metalk8s/volumes/files/sparse_volume_cleanup.py', + *constants.ROOT.glob('salt/_modules/*.py'), + *constants.ROOT.glob('salt/_states/*.py'), + *constants.ROOT.glob('salt/_utils/*.py'), + *constants.ROOT.glob('salt/_pillar/*.py'), + *constants.ROOT.glob('salt/_runners/*.py'), + *constants.ROOT.glob('salt/_auth/*.py'), + *constants.ROOT.glob('salt/_beacons/*.py'), + *constants.ROOT.glob('salt/_renderers/*.py'), + *constants.ROOT.glob('salt/_roster/*.py') ] cmd = ' '.join(map(shlex.quote, ['tox', '-e', 'lint-python'])) env = {'PATH': os.environ['PATH'], 'OSTYPE': os.uname().sysname} diff --git a/buildchain/requirements-dev.in b/buildchain/requirements-dev.in index 6ad678292c..420fb621e0 100644 --- a/buildchain/requirements-dev.in +++ b/buildchain/requirements-dev.in @@ -1,3 +1,4 @@ mypy == 0.740 pylint ~= 2.4 pyenchant ~= 2.0 +saltpylint == 2020.9.28 diff --git a/buildchain/requirements-dev.txt b/buildchain/requirements-dev.txt index 97a3006595..2980a31aa7 100644 --- a/buildchain/requirements-dev.txt +++ b/buildchain/requirements-dev.txt @@ -8,9 +8,9 @@ astroid==2.4.2 \ --hash=sha256:2f4078c2a41bf377eea06d71c9d2ba4eb8f6b1af2135bec27bbbb7d8f12bb703 \ --hash=sha256:bc58d83eb610252fd8de6363e39d4f1d0619c894b0ed24603b881c02e64c7386 \ # via pylint -isort==5.6.4 \ - --hash=sha256:dcab1d98b469a12a1a624ead220584391648790275560e1a43e54c5dceae65e7 \ - --hash=sha256:dcaeec1b5f0eca77faea2a35ab790b4f3680ff75590bfcb7145986905aab2f58 \ +isort==5.7.0 \ + --hash=sha256:c729845434366216d320e936b8ad6f9d681aab72dc7cbc2d51bedc3582f3ad1e \ + --hash=sha256:fff4f0c04e1825522ce6949973e83110a6e907750cd92d128b0d14aaaadbffdc \ # via pylint lazy-object-proxy==1.4.3 \ --hash=sha256:0c4b206227a8097f05c4dbdd323c50edf81f15db3b8dc064d08c62d37e1a504d \ @@ -39,6 +39,9 @@ mccabe==0.6.1 \ --hash=sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42 \ --hash=sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f \ # via pylint +modernize==0.5 \ + --hash=sha256:358dbb35baec7619d9b7cd5efed532c9f4a2e4e4a80f70c4d03f7aa30f76905d \ + # via saltpylint mypy-extensions==0.4.3 \ --hash=sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d \ --hash=sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8 \ @@ -59,6 +62,10 @@ mypy==0.740 \ --hash=sha256:dc889c84241a857c263a2b1cd1121507db7d5b5f5e87e77147097230f374d10b \ --hash=sha256:f4748697b349f373002656bf32fede706a0e713d67bfdcf04edf39b1f61d46eb \ # via -r buildchain/requirements-dev.in +pycodestyle==2.6.0 \ + --hash=sha256:2295e7b2f6b5bd100585ebcb1f616591b652db8a741695b3d8f5d28bdc934367 \ + --hash=sha256:c58a7d2815e0e8d7972bf1803331fb0152f867bd89adf8a01dfd55085434192e \ + # via saltpylint pyenchant==2.0.0 \ --hash=sha256:b9526fc2c5f1ba0637e50200b645a7c20fb6644dbc6f6322027e7d2fbf1084a5 \ --hash=sha256:e8000144e61551fcab9cd1b6fdccdded20e577e8d6d0985533f0b2b9c38fd952 \ @@ -67,6 +74,10 @@ pyenchant==2.0.0 \ pylint==2.6.0 \ --hash=sha256:bb4a908c9dadbc3aac18860550e870f58e1a02c9f2c204fdf5693d73be061210 \ --hash=sha256:bfe68f020f8a0fece830a22dd4d5dddb4ecc6137db04face4c3420a46a52239f \ + # via -r buildchain/requirements-dev.in, saltpylint +saltpylint==2020.9.28 \ + --hash=sha256:40fed07b859d28307d7ff02ca5b5df12763420127997016acbac7a8a32dbc80e \ + --hash=sha256:e34b8a221f3951b23469f1abb19507f70891330954965f91bbdb858e38dd987d \ # via -r buildchain/requirements-dev.in six==1.15.0 \ --hash=sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259 \ @@ -76,37 +87,37 @@ toml==0.10.2 \ --hash=sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b \ --hash=sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f \ # via pylint -typed-ast==1.4.1 \ - --hash=sha256:0666aa36131496aed8f7be0410ff974562ab7eeac11ef351def9ea6fa28f6355 \ - --hash=sha256:0c2c07682d61a629b68433afb159376e24e5b2fd4641d35424e462169c0a7919 \ - --hash=sha256:0d8110d78a5736e16e26213114a38ca35cb15b6515d535413b090bd50951556d \ - --hash=sha256:249862707802d40f7f29f6e1aad8d84b5aa9e44552d2cc17384b209f091276aa \ - --hash=sha256:24995c843eb0ad11a4527b026b4dde3da70e1f2d8806c99b7b4a7cf491612652 \ - --hash=sha256:269151951236b0f9a6f04015a9004084a5ab0d5f19b57de779f908621e7d8b75 \ - --hash=sha256:3742b32cf1c6ef124d57f95be609c473d7ec4c14d0090e5a5e05a15269fb4d0c \ - --hash=sha256:4083861b0aa07990b619bd7ddc365eb7fa4b817e99cf5f8d9cf21a42780f6e01 \ - --hash=sha256:498b0f36cc7054c1fead3d7fc59d2150f4d5c6c56ba7fb150c013fbc683a8d2d \ - --hash=sha256:4e3e5da80ccbebfff202a67bf900d081906c358ccc3d5e3c8aea42fdfdfd51c1 \ - --hash=sha256:6daac9731f172c2a22ade6ed0c00197ee7cc1221aa84cfdf9c31defeb059a907 \ - --hash=sha256:715ff2f2df46121071622063fc7543d9b1fd19ebfc4f5c8895af64a77a8c852c \ - --hash=sha256:73d785a950fc82dd2a25897d525d003f6378d1cb23ab305578394694202a58c3 \ - --hash=sha256:7e4c9d7658aaa1fc80018593abdf8598bf91325af6af5cce4ce7c73bc45ea53d \ - --hash=sha256:8c8aaad94455178e3187ab22c8b01a3837f8ee50e09cf31f1ba129eb293ec30b \ - --hash=sha256:8ce678dbaf790dbdb3eba24056d5364fb45944f33553dd5869b7580cdbb83614 \ - --hash=sha256:92c325624e304ebf0e025d1224b77dd4e6393f18aab8d829b5b7e04afe9b7a2c \ - --hash=sha256:aaee9905aee35ba5905cfb3c62f3e83b3bec7b39413f0a7f19be4e547ea01ebb \ - --hash=sha256:b52ccf7cfe4ce2a1064b18594381bccf4179c2ecf7f513134ec2f993dd4ab395 \ - --hash=sha256:bcd3b13b56ea479b3650b82cabd6b5343a625b0ced5429e4ccad28a8973f301b \ - --hash=sha256:c9e348e02e4d2b4a8b2eedb48210430658df6951fa484e59de33ff773fbd4b41 \ - --hash=sha256:d205b1b46085271b4e15f670058ce182bd1199e56b317bf2ec004b6a44f911f6 \ - --hash=sha256:d43943ef777f9a1c42bf4e552ba23ac77a6351de620aa9acf64ad54933ad4d34 \ - --hash=sha256:d5d33e9e7af3b34a40dc05f498939f0ebf187f07c385fd58d591c533ad8562fe \ - --hash=sha256:d648b8e3bf2fe648745c8ffcee3db3ff903d0817a01a12dd6a6ea7a8f4889072 \ - --hash=sha256:f208eb7aff048f6bea9586e61af041ddf7f9ade7caed625742af423f6bae3298 \ - --hash=sha256:fac11badff8313e23717f3dada86a15389d0708275bddf766cca67a84ead3e91 \ - --hash=sha256:fc0fea399acb12edbf8a628ba8d2312f583bdbdb3335635db062fa98cf71fca4 \ - --hash=sha256:fcf135e17cc74dbfbc05894ebca928ffeb23d9790b3167a674921db19082401f \ - --hash=sha256:fe460b922ec15dd205595c9b5b99e2f056fd98ae8f9f56b888e7a17dc2b757e7 \ +typed-ast==1.4.2 \ + --hash=sha256:07d49388d5bf7e863f7fa2f124b1b1d89d8aa0e2f7812faff0a5658c01c59aa1 \ + --hash=sha256:14bf1522cdee369e8f5581238edac09150c765ec1cb33615855889cf33dcb92d \ + --hash=sha256:240296b27397e4e37874abb1df2a608a92df85cf3e2a04d0d4d61055c8305ba6 \ + --hash=sha256:36d829b31ab67d6fcb30e185ec996e1f72b892255a745d3a82138c97d21ed1cd \ + --hash=sha256:37f48d46d733d57cc70fd5f30572d11ab8ed92da6e6b28e024e4a3edfb456e37 \ + --hash=sha256:4c790331247081ea7c632a76d5b2a265e6d325ecd3179d06e9cf8d46d90dd151 \ + --hash=sha256:5dcfc2e264bd8a1db8b11a892bd1647154ce03eeba94b461effe68790d8b8e07 \ + --hash=sha256:7147e2a76c75f0f64c4319886e7639e490fee87c9d25cb1d4faef1d8cf83a440 \ + --hash=sha256:7703620125e4fb79b64aa52427ec192822e9f45d37d4b6625ab37ef403e1df70 \ + --hash=sha256:8368f83e93c7156ccd40e49a783a6a6850ca25b556c0fa0240ed0f659d2fe496 \ + --hash=sha256:84aa6223d71012c68d577c83f4e7db50d11d6b1399a9c779046d75e24bed74ea \ + --hash=sha256:85f95aa97a35bdb2f2f7d10ec5bbdac0aeb9dafdaf88e17492da0504de2e6400 \ + --hash=sha256:8db0e856712f79c45956da0c9a40ca4246abc3485ae0d7ecc86a20f5e4c09abc \ + --hash=sha256:9044ef2df88d7f33692ae3f18d3be63dec69c4fb1b5a4a9ac950f9b4ba571606 \ + --hash=sha256:963c80b583b0661918718b095e02303d8078950b26cc00b5e5ea9ababe0de1fc \ + --hash=sha256:987f15737aba2ab5f3928c617ccf1ce412e2e321c77ab16ca5a293e7bbffd581 \ + --hash=sha256:9ec45db0c766f196ae629e509f059ff05fc3148f9ffd28f3cfe75d4afb485412 \ + --hash=sha256:9fc0b3cb5d1720e7141d103cf4819aea239f7d136acf9ee4a69b047b7986175a \ + --hash=sha256:a2c927c49f2029291fbabd673d51a2180038f8cd5a5b2f290f78c4516be48be2 \ + --hash=sha256:a38878a223bdd37c9709d07cd357bb79f4c760b29210e14ad0fb395294583787 \ + --hash=sha256:b4fcdcfa302538f70929eb7b392f536a237cbe2ed9cba88e3bf5027b39f5f77f \ + --hash=sha256:c0c74e5579af4b977c8b932f40a5464764b2f86681327410aa028a22d2f54937 \ + --hash=sha256:c1c876fd795b36126f773db9cbb393f19808edd2637e00fd6caba0e25f2c7b64 \ + --hash=sha256:c9aadc4924d4b5799112837b226160428524a9a45f830e0d0f184b19e4090487 \ + --hash=sha256:cc7b98bf58167b7f2db91a4327da24fb93368838eb84a44c472283778fc2446b \ + --hash=sha256:cf54cfa843f297991b7388c281cb3855d911137223c6b6d2dd82a47ae5125a41 \ + --hash=sha256:d003156bb6a59cda9050e983441b7fa2487f7800d76bdc065566b7d728b4581a \ + --hash=sha256:d175297e9533d8d37437abc14e8a83cbc68af93cc9c1c59c2c292ec59a0697a3 \ + --hash=sha256:d746a437cdbca200622385305aedd9aef68e8a645e385cc483bdc5e488f07166 \ + --hash=sha256:e683e409e5c45d5c9082dc1daf13f6374300806240719f95dc783d1fc942af10 \ # via astroid, mypy typing-extensions==3.7.4.3 \ --hash=sha256:7cb407020f00f7bfc3cb3e7881628838e69d8f3fcab2f64742a5e76b2f841918 \ diff --git a/salt/.pylintrc b/salt/.pylintrc new file mode 100644 index 0000000000..f8143c5224 --- /dev/null +++ b/salt/.pylintrc @@ -0,0 +1,684 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code. +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS, + ext, + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns=salt.ext.* + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the +# number of processors available to use. +jobs=1 + +# Control the amount of potential inferred values when inferring a single +# object. This can help the performance when dealing with large functions or +# complex, nested conditions. +limit-inference-results=100 + +# List of plugins (as comma separated values of python module names) to load, +# usually to register additional checkers. +load-plugins=saltpylint.pep8, + saltpylint.strings, + saltpylint.fileperms, + saltpylint.py3modernize, + saltpylint.smartup, + saltpylint.minpyver, + saltpylint.blacklist, + saltpylint.thirdparty, + saltpylint.dunder_del + +# Pickle collected data for later comparisons. +persistent=no + +# Specify a configuration file. +#rcfile= + +# When enabled, pylint would attempt to guess common misconfiguration and emit +# user-friendly hints instead of false-positive error messages. +suggestion-mode=yes + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED. +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use "--disable=all --enable=classes +# --disable=W". +disable=R, + locally-disabled, + file-ignored, + unexpected-special-method-signature, + import-error, + no-member, + unsubscriptable-object, + un-indexed-curly-braces-error, + blacklisted-name, + invalid-name, + missing-docstring, + empty-docstring, + misplaced-comparison-constant, + unidiomatic-typecheck, + wrong-import-order, + ungrouped-imports, + wrong-import-position, + bad-mcs-method-argument, + bad-mcs-classmethod-argument, + line-too-long, + too-many-lines, + bad-continuation, + exec-used, + attribute-defined-outside-init, + protected-access, + reimported, + fixme, + global-statement, + redefined-outer-name, + redefined-builtin, + logging-format-interpolation, + invalid-format-index, + line-too-long, + module-level-import-not-at-top-of-file, + do-not-assign-a-lambda-expression-use-a-def, + 3rd-party-local-module-not-gated, + import-outside-toplevel, + deprecated-method, + repr-flag-used-in-string, + keyword-arg-before-vararg, + incompatible-py3-code, + multiple-spaces-before-operator + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable=c-extension-no-member, + literal-comparison + + +[REPORTS] + +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'error', 'warning', 'refactor', and 'convention' +# which contain the number of messages in each category, as well as 'statement' +# which is the total number of statements analyzed. This score is used by the +# global evaluation report (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details. +msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +output-format=parseable + +# Tells whether to display a full report or only the messages. +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + +# Complete name of functions that never returns. When checking for +# inconsistent-return-statements if a never returning function is called then +# it will be considered as an explicit return statement and no message will be +# printed. +never-returning-functions=sys.exit + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +expected-line-ending-format=LF + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=120 + +# Maximum number of lines in a module. +max-module-lines=3000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma, + dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME, + FIX, + XXX, + TODO + + +[BASIC] + +# Naming style matching correct argument names. +argument-naming-style=snake_case + +# Regular expression matching correct argument names. Overrides argument- +# naming-style. +argument-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming style matching correct attribute names. +attr-naming-style=snake_case + +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. +attr-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Bad variable names which should always be refused, separated by a comma. +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +# Naming style matching correct class attribute names. +class-attribute-naming-style=any + +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Naming style matching correct class names. +class-naming-style=PascalCase + +# Regular expression matching correct class names. Overrides class-naming- +# style. +class-rgx=[A-Z_][a-zA-Z0-9]+$ + +# Naming style matching correct constant names. +const-naming-style=UPPER_CASE + +# Regular expression matching correct constant names. Overrides const-naming- +# style. +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming style matching correct function names. +function-naming-style=snake_case + +# Regular expression matching correct function names. Overrides function- +# naming-style. +function-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Good variable names which should always be accepted, separated by a comma. +good-names=i, + j, + k, + ex, + Run, + _, + log + +# Include a hint for the correct naming format with invalid-name. +include-naming-hint=yes + +# Naming style matching correct inline iteration names. +inlinevar-naming-style=any + +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Naming style matching correct method names. +method-naming-style=snake_case + +# Regular expression matching correct method names. Overrides method-naming- +# style. +method-rgx=[a-z_][a-z0-9_]{2,30}$ + +# Naming style matching correct module names. +module-naming-style=snake_case + +# Regular expression matching correct module names. Overrides module-naming- +# style. +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=__.*__ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +# These decorators are taken in consideration only for invalid-name. +property-classes=abc.abstractproperty + +# Naming style matching correct variable names. +variable-naming-style=snake_case + +# Regular expression matching correct variable names. Overrides variable- +# naming-style. +variable-rgx=[a-z_][a-z0-9_]{2,30}$ + + +[STRING] + +# This flag controls whether the implicit-str-concat-in-sequence should +# generate a warning on implicit string concatenation in sequences defined over +# several lines. +check-str-concat-over-line-jumps=no + +# Enforce string formatting over string substitution +enforce-string-formatting-over-substitution=yes + +# Force string substitution usage on strings to always be an error. +string-substitutions-usage-is-an-error=yes + +# Force un-indexed curly braces on a 'string.format()' call to always be an +# error. +un-indexed-curly-braces-always-error=no + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid defining new builtins when possible. +additional-builtins=__opts__, + __utils__, + __salt__, + __pillar__, + __grains__, + __context__, + __runner__, + __ret__, + __env__, + __low__, + __states__, + __lowstate__, + __running__, + __active_provider_name__, + __master_opts__, + __jid_event__, + __instance_id__, + __salt_system_encoding__, + __proxy__, + __serializers__, + __reg__, + __executors__, + __events__ + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_, + _cb + +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). +dummy-variables-rgx=_|dummy + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore. +ignored-argument-names=_.* + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves, + salt.ext.six.moves, + past.builtins, + future.builtins, + builtins, + io + + +[LOGGING] + +# Format style used to check logging format string. `old` means using % +# formatting, `new` is for `{}` formatting,and `fstr` is for f-strings. +logging-format-style=old + +# Logging modules to check that the string format arguments are in logging +# function parameter format. +logging-modules= + + +[SPELLING] + +# Limits count of emitted suggestions for spelling mistakes. +max-spelling-suggestions=4 + +# Spelling dictionary name. Available dictionaries: none. To make it work, +# install the python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains the private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to the private dictionary (see the +# --spelling-private-dict-file option) instead of raising a message. +spelling-store-unknown-words=no + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members=REQUEST, + acl_users, + aq_parent + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# Tells whether to warn about missing members when the owner of the attribute +# is inferred to be None. +ignore-none=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=SQLObject + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis). It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules=salt.ext.six.moves, + six.moves, + _MovedItems, + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + +# List of decorators that change the signature of a decorated function. +signature-mutators= + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[FILEPERMS] + +# Desired file permissons. Default: 0644 +fileperms-default=0644 + +# File paths to ignore file permission. Glob patterns allowed. +fileperms-ignore-paths=setup.py,noxfile.py,tests/runtests.py,tests/jenkins*.py,tests/saltsh.py,tests/buildpackage.py,tests/unit/files/rosters/ansible/roster.py + + +[MODERNIZE] + +# Fix up doctests only +modernize-doctests-only=no + +# Each FIX specifies a transformation; "default" includes default fixes. +modernize-fix= + +# Use 'from __future__ import unicode_literals' (only useful for Python 2.6+). +modernize-future-unicode=no + +# Exclude fixes that depend on the six package. +modernize-no-six=no + +# Comma separated list of fixer names not to fix. +modernize-nofix= + +# Modify the grammar so that print() is a function. +modernize-print-function=yes + +# Wrap unicode literals in six.u(). +modernize-six-unicode=no + + +[MININUM-PYTHON-VERSION] + +# The desired minimum python version to enforce. Default: 2.6 +minimum-python-version=2.7 + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__, + __new__, + setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict, + _fields, + _replace, + _source, + _make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# Maximum number of arguments for function / method. +max-args=35 + +# Maximum number of attributes for a class (see R0902). +max-attributes=7 + +# Maximum number of boolean expressions in an if statement (see R0916). +max-bool-expr=5 + +# Maximum number of branch for function / method body. +max-branches=48 + +# Maximum number of locals for function / method body. +max-locals=40 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body. +max-returns=6 + +# Maximum number of statements in function / method body. +max-statements=100 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[IMPORTS] + +# List of modules that can be imported at any level, not just the top level +# one. +allow-any-import-level= + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=yes + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=yes + +# Deprecated modules which should not be used, separated by a comma. +deprecated-modules=regsub, + TERMIOS, + Bastion, + rexec + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled). +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled). +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled). +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + +# Couples of modules and preferred modules, separated by a comma. +preferred-modules= + + +[BLACKLISTED-FUNCTIONS] + +# List of blacklisted functions and suggested replacements +# +# NOTE: This pylint check will infer the full name of the function by walking +# back up from the function name to the parent, to the parent's parent, etc., +# and this means that functions which come from platform-specific modules need +# to be referenced using name of the module from which the function was +# imported. This happens a lot in the os and os.path modules. Functions from +# os.path should be defined using posixpath.funcname and ntpath.funcname, while +# functions from os should be defined using posix.funcname and nt.funcname. +# +# When defining a blacklisted function, the format is: +# +# = +# +# The replacement text will be included in the alert message. +# +blacklisted-functions=posix.umask=salt.utils.files.set_umask or get_umask, + nt.umask=salt.utils.files.set_umask or get_umask + +[3RD-PARTY-IMPORTS] + +# Known 3rd-party modules which don' require being gated, separated by a comma +allowed-3rd-party-modules=salt, + msgpack, + tornado, + yaml, + jinja2, + Crypto, + requests, + libcloud, + zmq, + pytest, + attr, + setuptools, + pytestsalt, + saltfactories, + distro, + os, + re, + shutil, + copy, + base64, + tempfile, + fnmatch + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "BaseException, Exception". +overgeneral-exceptions=BaseException, + Exception diff --git a/tox.ini b/tox.ini index 7676c84a09..d54eeccecb 100644 --- a/tox.ini +++ b/tox.ini @@ -113,10 +113,22 @@ commands = untyped_files=( \ salt/metalk8s/volumes/files/sparse_volume_cleanup.py \ ); \ + salt_files=( \ + salt/_modules/*.py \ + salt/_states/*.py \ + salt/_utils/*.py \ + salt/_pillar/*.py \ + salt/_runners/*.py \ + salt/_auth/*.py \ + salt/_beacons/*.py \ + salt/_renderers/*.py \ + salt/_roster/*.py \ + ); \ pylint $\{untyped_files[@]\} $\{typed_files[@]\}; PYLINT_RC=$?; \ + pylint --rcfile=salt/.pylintrc --ignore=metalk8s_package_manager_apt.py $\{salt_files[@]\}; PYLINT_SALT_RC=$?; \ mypy --strict $\{typed_files[@]\}; MYPY_RC=$?; \ - if [[ $PYLINT_RC -gt 0 || $MYPY_RC -gt 0 ]]; then \ - echo Failed: pylint [$PYLINT_RC] - mypy [$MYPY_RC]; exit 1; \ + if [[ $PYLINT_RC -gt 0 || $PYLINT_SALT_RC -gt 0 || $MYPY_RC -gt 0 ]]; then \ + echo Failed: pylint [$PYLINT_RC] - pylint salt [$PYLINT_SALT_RC] - mypy [$MYPY_RC]; exit 1; \ else \ echo Success!; \ fi \