Flake8 cleanups

Tox can now run the linters test.

The linters gate job is added.

Change-Id: If39545c928991baa47c919ab6b357bf47ca9ca90
This commit is contained in:
James E. Blair 2021-04-14 18:53:15 -07:00
parent c531a6fb23
commit 9f2f4ec145
10 changed files with 27 additions and 23 deletions

View File

@ -92,12 +92,14 @@
- project:
check:
jobs:
- tox-linters
- zuul-tox-docs
- zuul-operator-build-image
- zuul-operator-functional-k8s:
dependencies: zuul-operator-build-image
gate:
jobs:
- tox-linters
- zuul-tox-docs
- zuul-operator-upload-image
- zuul-operator-functional-k8s:

10
tox.ini
View File

@ -1,13 +1,12 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = pep8
envlist = linters,docs
[testenv]
basepython = python3
install_command = pip install {opts} {packages}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
python setup.py testr --slowest --testr-args='{posargs}'
@ -26,8 +25,8 @@ deps =
commands =
sphinx-build -E -W -d doc/build/doctrees -b html doc/source/ doc/build/html
[testenv:pep8]
whitelist_externals = bash
[testenv:linters]
deps = flake8
commands =
flake8 {posargs}
@ -40,3 +39,6 @@ commands = {posargs}
ignore = E124,E125,E129,E252,E402,E741,H,W503,W504
show-source = True
exclude = .venv,.tox,dist,doc,build,*.egg
per-file-ignores =
# Allow import * to create a superset of objects
zuul_operator/objects.py:F403,F405

View File

@ -13,3 +13,5 @@
# under the License.
from .operator import ZuulOperator
__all__ = [ZuulOperator]

View File

@ -13,7 +13,6 @@
# under the License.
import time
import base64
import pykube
@ -31,7 +30,7 @@ class CertManager:
kind = objects.get_object('apiextensions.k8s.io/v1beta1',
'CustomResourceDefinition')
try:
obj = kind.objects(self.api).\
kind.objects(self.api).\
get(name="certificaterequests.cert-manager.io")
except pykube.exceptions.ObjectDoesNotExist:
return False
@ -57,5 +56,5 @@ class CertManager:
self.log.info("Cert-manager is running")
return
else:
self.log.info(f"Waiting for Cert-manager")
self.log.info("Waiting for Cert-manager")
time.sleep(10)

View File

@ -14,6 +14,7 @@
import inspect
# We deliberately import * to create a superset of objects.
from pykube.objects import *

View File

@ -14,15 +14,11 @@
import asyncio
import collections
import yaml
import kopf
import pykube
import kubernetes
from . import objects
from . import utils
from . import certmanager
from .zuul import Zuul
@ -99,7 +95,8 @@ def create_fn(spec, name, namespace, logger, **kwargs):
zuul.write_zuul_conf()
zuul.create_zuul()
#return {'message': 'hello world'} # will be the new status
# We can set a status with something like:
# return {'message': 'hello world'}
@kopf.on.update('zuuls', backoff=10)

View File

@ -31,7 +31,7 @@ class PXC:
kind = objects.get_object('apiextensions.k8s.io/v1beta1',
'CustomResourceDefinition')
try:
obj = kind.objects(self.api).\
kind.objects(self.api).\
get(name="perconaxtradbclusters.pxc.percona.com")
except pykube.exceptions.ObjectDoesNotExist:
return False
@ -62,7 +62,8 @@ class PXC:
namespace=self.namespace,
selector={'app.kubernetes.io/instance': 'db-cluster',
'app.kubernetes.io/component': 'pxc',
'app.kubernetes.io/name': 'percona-xtradb-cluster'}):
'app.kubernetes.io/name':
'percona-xtradb-cluster'}):
if obj.obj['status']['phase'] == 'Running':
count += 1
if count == 3:

View File

@ -22,7 +22,6 @@ import jinja2
import kubernetes
from kubernetes.client import Configuration
from kubernetes.client.api import core_v1_api
from kubernetes.client.rest import ApiException
from kubernetes.stream import stream
from . import objects

View File

@ -13,9 +13,6 @@
# under the License.
import time
import base64
import pykube
from . import objects
from . import utils

View File

@ -45,7 +45,7 @@ class Zuul:
self.db_secret = 'zuul-db'
self.manage_db = True
self.nodepool_secret = spec.get('launcher', {}).get('config',{}).\
self.nodepool_secret = spec.get('launcher', {}).get('config', {}).\
get('secretName')
zk_spec = self.spec.setdefault('zookeeper', {})
@ -267,7 +267,8 @@ class Zuul:
# Shard the config so we can create a deployment + secret for
# each provider.
nodepool_yaml = yaml.safe_load(base64.b64decode(obj.obj['data']['nodepool.yaml']))
nodepool_yaml = yaml.safe_load(base64.b64decode(
obj.obj['data']['nodepool.yaml']))
nodepool_yaml['zookeeper-servers'] = self.parse_zk_string(
self.spec['zookeeper']['hosts'])
@ -321,7 +322,8 @@ class Zuul:
for unused_provider in old_providers - new_providers:
self.log.info("Deleting unused provider %s", unused_provider)
deployment_name = f"nodepool-launcher-{self.name}-{unused_provider}"
deployment_name = "nodepool-launcher-"\
f"{self.name}-{unused_provider}"
secret_name = f"nodepool-config-{self.name}-{unused_provider}"
try:
@ -339,7 +341,8 @@ class Zuul:
pass
def write_registry_conf(self):
config_secret = self.spec['registry'].get('config', {}).get('secretName')
config_secret = self.spec['registry'].get('config', {}).\
get('secretName')
if not config_secret:
raise kopf.PermanentError("No registry config secret found")
@ -435,7 +438,8 @@ class Zuul:
str(timeout),
'/bin/sh',
'-c',
f'while !( echo -n "{expected}" | sha256sum -c - ); do sleep {delay}; done'
f'while !( echo -n "{expected}" | sha256sum -c - );'
f'do sleep {delay}; done'
]
resp = utils.pod_exec(self.namespace, obj.name, command)
self.log.debug("Response: %s", resp)