Merge pull request #123 from willthames/flake8

Flake8
This commit is contained in:
Jeff Geerling
2020-06-15 12:34:46 -05:00
committed by GitHub
10 changed files with 20 additions and 34 deletions

View File

@@ -84,7 +84,7 @@ jobs:
python-version: ${{ matrix.python_version }}
- name: Install molecule and openshift dependencies
run: pip install molecule yamllint openshift
run: pip install molecule yamllint openshift flake8
- name: Install ansible base (devel branch)
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check

View File

@@ -9,6 +9,7 @@ driver:
lint: |
set -e
yamllint .
flake8
platforms:
- name: instance-kind
provisioner:

View File

@@ -173,7 +173,6 @@ import os
import os.path
import subprocess
import ansible.constants as C
from ansible.parsing.yaml.loader import AnsibleLoader
from ansible.errors import AnsibleError, AnsibleFileNotFound
from ansible.module_utils.six.moves import shlex_quote

View File

@@ -317,7 +317,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable, K8sAnsibleM
try:
self.inventory.add_child(namespace_services_group, service_name)
except AnsibleError as e:
except AnsibleError:
raise
ports = [{'name': port.name,

View File

@@ -202,7 +202,6 @@ from ansible_collections.community.kubernetes.plugins.module_utils.common import
try:
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import NotFoundError
HAS_K8S_MODULE_HELPER = True
k8s_import_exception = None
@@ -210,12 +209,6 @@ except ImportError as e:
HAS_K8S_MODULE_HELPER = False
k8s_import_exception = e
try:
import yaml
HAS_YAML = True
except ImportError:
HAS_YAML = False
class KubernetesLookup(K8sAnsibleMixin):
@@ -226,11 +219,6 @@ class KubernetesLookup(K8sAnsibleMixin):
"Requires the OpenShift Python client. Try `pip install openshift`. Detail: {0}".format(k8s_import_exception)
)
if not HAS_YAML:
raise Exception(
"Requires PyYAML. Try `pip install PyYAML`"
)
self.kind = None
self.name = None
self.namespace = None

View File

@@ -329,21 +329,21 @@ class KubernetesAnsibleModule(AnsibleModule, K8sAnsibleMixin):
# Scaling up means that we also need to check that we're not in a
# situation where status.replicas == status.availableReplicas
# but spec.replicas != status.replicas
return (deployment.status and
deployment.spec.replicas == (deployment.status.replicas or 0) and
deployment.status.availableReplicas == deployment.status.replicas and
deployment.status.observedGeneration == deployment.metadata.generation and
not deployment.status.unavailableReplicas)
return (deployment.status
and deployment.spec.replicas == (deployment.status.replicas or 0)
and deployment.status.availableReplicas == deployment.status.replicas
and deployment.status.observedGeneration == deployment.metadata.generation
and not deployment.status.unavailableReplicas)
def _pod_ready(pod):
return (pod.status and pod.status.containerStatuses is not None and
all([container.ready for container in pod.status.containerStatuses]))
return (pod.status and pod.status.containerStatuses is not None
and all([container.ready for container in pod.status.containerStatuses]))
def _daemonset_ready(daemonset):
return (daemonset.status and daemonset.status.desiredNumberScheduled is not None and
daemonset.status.numberReady == daemonset.status.desiredNumberScheduled and
daemonset.status.observedGeneration == daemonset.metadata.generation and
not daemonset.status.unavailableReplicas)
return (daemonset.status and daemonset.status.desiredNumberScheduled is not None
and daemonset.status.numberReady == daemonset.status.desiredNumberScheduled
and daemonset.status.observedGeneration == daemonset.metadata.generation
and not daemonset.status.unavailableReplicas)
def _custom_condition(resource):
if not resource.status or not resource.status.conditions:

View File

@@ -39,11 +39,6 @@ except ImportError:
# Exceptions handled in common
pass
try:
import kubernetes_validate
HAS_KUBERNETES_VALIDATE = True
except ImportError:
HAS_KUBERNETES_VALIDATE = False
K8S_CONFIG_HASH_IMP_ERR = None
try:

View File

@@ -251,7 +251,7 @@ class KubernetesAuthModule(AnsibleModule):
self.openshift_auth_endpoint = oauth_info['authorization_endpoint']
self.openshift_token_endpoint = oauth_info['token_endpoint']
except Exception as e:
except Exception:
self.fail_json(msg="Something went wrong discovering OpenShift OAuth details.",
exception=traceback.format_exc())
@@ -311,7 +311,7 @@ class KubernetesAuthModule(AnsibleModule):
"kind": "DeleteOptions"
}
ret = requests.delete(url, headers=headers, json=json, verify=self.con_verify_ca)
requests.delete(url, headers=headers, json=json, verify=self.con_verify_ca)
# Ignore errors, the token will time out eventually anyway
def fail(self, msg=None):

View File

@@ -181,7 +181,7 @@ import traceback
from collections import defaultdict
from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC, COMMON_ARG_SPEC
from ansible_collections.community.kubernetes.plugins.module_utils.common import AUTH_ARG_SPEC
from ansible_collections.community.kubernetes.plugins.module_utils.raw import KubernetesRawModule

3
setup.cfg Normal file
View File

@@ -0,0 +1,3 @@
[flake8]
max-line-length = 160
ignore = W503,E402