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 }} python-version: ${{ matrix.python_version }}
- name: Install molecule and openshift dependencies - 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) - name: Install ansible base (devel branch)
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check

View File

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

View File

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

View File

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

View File

@@ -202,7 +202,6 @@ from ansible_collections.community.kubernetes.plugins.module_utils.common import
try: try:
from openshift.dynamic import DynamicClient
from openshift.dynamic.exceptions import NotFoundError from openshift.dynamic.exceptions import NotFoundError
HAS_K8S_MODULE_HELPER = True HAS_K8S_MODULE_HELPER = True
k8s_import_exception = None k8s_import_exception = None
@@ -210,12 +209,6 @@ except ImportError as e:
HAS_K8S_MODULE_HELPER = False HAS_K8S_MODULE_HELPER = False
k8s_import_exception = e k8s_import_exception = e
try:
import yaml
HAS_YAML = True
except ImportError:
HAS_YAML = False
class KubernetesLookup(K8sAnsibleMixin): 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) "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.kind = None
self.name = None self.name = None
self.namespace = 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 # Scaling up means that we also need to check that we're not in a
# situation where status.replicas == status.availableReplicas # situation where status.replicas == status.availableReplicas
# but spec.replicas != status.replicas # but spec.replicas != status.replicas
return (deployment.status and return (deployment.status
deployment.spec.replicas == (deployment.status.replicas or 0) and and deployment.spec.replicas == (deployment.status.replicas or 0)
deployment.status.availableReplicas == deployment.status.replicas and and deployment.status.availableReplicas == deployment.status.replicas
deployment.status.observedGeneration == deployment.metadata.generation and and deployment.status.observedGeneration == deployment.metadata.generation
not deployment.status.unavailableReplicas) and not deployment.status.unavailableReplicas)
def _pod_ready(pod): def _pod_ready(pod):
return (pod.status and pod.status.containerStatuses is not None and return (pod.status and pod.status.containerStatuses is not None
all([container.ready for container in pod.status.containerStatuses])) and all([container.ready for container in pod.status.containerStatuses]))
def _daemonset_ready(daemonset): def _daemonset_ready(daemonset):
return (daemonset.status and daemonset.status.desiredNumberScheduled is not None and return (daemonset.status and daemonset.status.desiredNumberScheduled is not None
daemonset.status.numberReady == daemonset.status.desiredNumberScheduled and and daemonset.status.numberReady == daemonset.status.desiredNumberScheduled
daemonset.status.observedGeneration == daemonset.metadata.generation and and daemonset.status.observedGeneration == daemonset.metadata.generation
not daemonset.status.unavailableReplicas) and not daemonset.status.unavailableReplicas)
def _custom_condition(resource): def _custom_condition(resource):
if not resource.status or not resource.status.conditions: if not resource.status or not resource.status.conditions:

View File

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

View File

@@ -251,7 +251,7 @@ class KubernetesAuthModule(AnsibleModule):
self.openshift_auth_endpoint = oauth_info['authorization_endpoint'] self.openshift_auth_endpoint = oauth_info['authorization_endpoint']
self.openshift_token_endpoint = oauth_info['token_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.", self.fail_json(msg="Something went wrong discovering OpenShift OAuth details.",
exception=traceback.format_exc()) exception=traceback.format_exc())
@@ -311,7 +311,7 @@ class KubernetesAuthModule(AnsibleModule):
"kind": "DeleteOptions" "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 # Ignore errors, the token will time out eventually anyway
def fail(self, msg=None): def fail(self, msg=None):

View File

@@ -181,7 +181,7 @@ import traceback
from collections import defaultdict 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 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