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: - project:
check: check:
jobs: jobs:
- tox-linters
- zuul-tox-docs - zuul-tox-docs
- zuul-operator-build-image - zuul-operator-build-image
- zuul-operator-functional-k8s: - zuul-operator-functional-k8s:
dependencies: zuul-operator-build-image dependencies: zuul-operator-build-image
gate: gate:
jobs: jobs:
- tox-linters
- zuul-tox-docs - zuul-tox-docs
- zuul-operator-upload-image - zuul-operator-upload-image
- zuul-operator-functional-k8s: - zuul-operator-functional-k8s:

10
tox.ini
View File

@ -1,13 +1,12 @@
[tox] [tox]
minversion = 1.6 minversion = 1.6
skipsdist = True skipsdist = True
envlist = pep8 envlist = linters,docs
[testenv] [testenv]
basepython = python3 basepython = python3
install_command = pip install {opts} {packages} install_command = pip install {opts} {packages}
deps = -r{toxinidir}/requirements.txt deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands = commands =
python setup.py testr --slowest --testr-args='{posargs}' python setup.py testr --slowest --testr-args='{posargs}'
@ -26,8 +25,8 @@ deps =
commands = commands =
sphinx-build -E -W -d doc/build/doctrees -b html doc/source/ doc/build/html sphinx-build -E -W -d doc/build/doctrees -b html doc/source/ doc/build/html
[testenv:pep8] [testenv:linters]
whitelist_externals = bash deps = flake8
commands = commands =
flake8 {posargs} flake8 {posargs}
@ -40,3 +39,6 @@ commands = {posargs}
ignore = E124,E125,E129,E252,E402,E741,H,W503,W504 ignore = E124,E125,E129,E252,E402,E741,H,W503,W504
show-source = True show-source = True
exclude = .venv,.tox,dist,doc,build,*.egg 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. # under the License.
from .operator import ZuulOperator from .operator import ZuulOperator
__all__ = [ZuulOperator]

View File

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

View File

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

View File

@ -14,15 +14,11 @@
import asyncio import asyncio
import collections import collections
import yaml
import kopf import kopf
import pykube import pykube
import kubernetes
from . import objects from . import objects
from . import utils
from . import certmanager
from .zuul import Zuul from .zuul import Zuul
@ -99,7 +95,8 @@ def create_fn(spec, name, namespace, logger, **kwargs):
zuul.write_zuul_conf() zuul.write_zuul_conf()
zuul.create_zuul() 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) @kopf.on.update('zuuls', backoff=10)

View File

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

View File

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

View File

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

View File

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