Skip to content

Commit d37abc2

Browse files
committed
style(controller): flake8 upgrade
1 parent c87bb80 commit d37abc2

11 files changed

Lines changed: 38 additions & 13 deletions

File tree

rootfs/api/authentication.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import logging
12
from django.contrib.auth.models import AnonymousUser
23
from rest_framework import authentication
34
from rest_framework.authentication import TokenAuthentication
45

56

7+
logger = logging.getLogger(__name__)
8+
9+
610
class AnonymousAuthentication(authentication.BaseAuthentication):
711

812
def authenticate(self, request):
@@ -20,5 +24,6 @@ def authenticate(self, request):
2024
"""
2125
try:
2226
return TokenAuthentication.authenticate(TokenAuthentication(), request)
23-
except:
27+
except Exception as e:
28+
logger.debug(e)
2429
return AnonymousUser(), None

rootfs/api/management/commands/load_db_state_to_k8s.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import logging
12
from django.core.management.base import BaseCommand
23
from django.shortcuts import get_object_or_404
34

45
from api.models import Key, App, Domain, Certificate, Service
56
from api.exceptions import DryccException, AlreadyExists
67

78

9+
logger = logging.getLogger(__name__)
10+
11+
812
class Command(BaseCommand):
913
"""Management command for publishing Drycc platform state from the database
1014
to k8s.
@@ -33,10 +37,12 @@ def handle(self, *args, **options):
3337
try:
3438
application.deploy(rel)
3539
except AlreadyExists as error:
40+
logger.debug(error)
3641
print('WARNING: {} has a deployment in progress. '
3742
'Skipping deployment...'.format(application))
3843
continue
3944
except DryccException as error:
45+
logger.exception(error)
4046
print('ERROR: There was a problem deploying {} '
4147
'due to {}'.format(application, str(error)))
4248

rootfs/api/models/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def list_pods(self, *args, **kwargs):
896896
data.sort(key=lambda x: x['started'], reverse=True)
897897
return data
898898
except KubeHTTPException as e:
899-
pass
899+
logger.debug(e)
900900
except Exception as e:
901901
err = '(list pods): {}'.format(e)
902902
self.log(err, logging.ERROR)

rootfs/api/models/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from django.conf import settings
23
from django.db import models
34
from jsonfield import JSONField
@@ -8,6 +9,9 @@
89
from api.exceptions import DryccException, UnprocessableEntity
910

1011

12+
logger = logging.getLogger(__name__)
13+
14+
1115
class Config(UuidAuditedModel):
1216
"""
1317
Set of configuration values applied as environment variables
@@ -100,6 +104,7 @@ def set_tags(self, previous_config):
100104
tags = json.loads(settings.DRYCC_DEFAULT_CONFIG_TAGS)
101105
self.tags = tags
102106
except json.JSONDecodeError as e:
107+
logger.exception(e)
103108
return
104109
else:
105110
return

rootfs/api/models/resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def attach_update(self, *args, **kwargs):
139139
data = self._scheduler.svcat.get_instance(
140140
self.app.id, self.name).json()
141141
except KubeException as e:
142+
logger.debug(e)
142143
self.DryccException("resource {} does not exist".format(self.name))
143144
try:
144145
version = data["metadata"]["resourceVersion"]

rootfs/api/serializers.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import json
6+
import logging
67
import jmespath
78
import re
89
import jsonschema
@@ -21,6 +22,9 @@
2122
# https://docs-v2.readthedocs.io/en/latest/using-workflow/process-types-and-the-procfile/#declaring-process-types
2223
from api.exceptions import DryccException
2324

25+
26+
logger = logging.getLogger(__name__)
27+
2428
PROCTYPE_MATCH = re.compile(r'^(?P<type>[a-z0-9]+(\-[a-z0-9]+)*)$')
2529
PROCTYPE_MISMATCH_MSG = "Process types can only contain lowercase alphanumeric characters"
2630
MEMLIMIT_MATCH = re.compile(r'^(?P<mem>([1-9][0-9]*[mgMG]))$', re.IGNORECASE)
@@ -536,6 +540,7 @@ def validate_path_pattern(value):
536540
try:
537541
re.compile(pattern)
538542
except re.error as e:
543+
logger.exception(e)
539544
raise serializers.ValidationError(
540545
"Service value should be valid regex (or set of regex split by comma)")
541546

@@ -592,13 +597,16 @@ def validate_whitelist(data):
592597
for address in data:
593598
try:
594599
ipaddress.ip_address(address)
595-
except:
600+
except Exception as e:
601+
logger.exception(e)
596602
try:
597603
ipaddress.ip_network(address)
598-
except:
604+
except Exception as e:
605+
logger.exception(e)
599606
try:
600607
ipaddress.ip_interface(address)
601-
except:
608+
except Exception as e:
609+
logger.exception(e)
602610
raise serializers.ValidationError(
603611
"The address {} is not valid".format(address))
604612

rootfs/dev_requirements.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# test module
22
# test
33
# Run "make test-unit" for the % of code exercised during tests
4-
coverage==4.4.1
4+
coverage==5.3
55

66
# Run "make test-style" to check python syntax and style
7-
flake8==3.4.1
7+
flake8==3.8.3
88

99
# code coverage report at https://codecov.io/github/drycc/controller
10-
codecov==2.0.9
10+
codecov==2.1.9
1111

1212
# mock out python-requests, mostly k8s
13-
requests-mock==1.5.2
13+
requests-mock==1.8.0
1414

1515
# tail a log and pipe into tbgrep to find all tracebacks
1616
tbgrep==0.3.0

rootfs/scheduler/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def version(self):
8686

8787
data = response.json()
8888
parsed_version = parse(
89-
re.sub("[^0-9\.]", '', str('{}.{}'.format(data['major'], data['minor']))))
89+
re.sub(r"[^0-9\.]", '', str('{}.{}'.format(data['major'], data['minor']))))
9090
return Version('{}'.format(parsed_version))
9191

9292
@staticmethod

rootfs/scheduler/mock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def prepare_query_filters(query):
626626
filters = {'labels': {}, 'fields': {}}
627627
if query:
628628
# set based regex - does not support only field
629-
labelRegex = re.compile('^(?P<label>.*) (?P<matcher>notin|in)\s?\((?P<values>.*)\)$')
629+
labelRegex = re.compile(r'^(?P<label>.*) (?P<matcher>notin|in)\s?\((?P<values>.*)\)$')
630630

631631
queries = parse_qs(query)
632632
if 'labelSelector' in queries:

rootfs/scheduler/resources/pod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ def _handle_long_image_pulling(self, reason, pod):
623623
if getattr(self, '_handle_long_image_pulling_applied', False):
624624
return 0
625625

626-
if reason is not 'Pulling':
626+
if reason != 'Pulling':
627627
return 0
628628

629629
# last event should be Pulling in this case

0 commit comments

Comments
 (0)