Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Jul 3, 2023
1 parent 6d73b5a commit 52bb8e5
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 16 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Default container tag
CONT_TAG=suse/qac/pcw
LINE_MAX=140
FILES=ocw/lib/*.py ocw/management/commands/*.py ocw/*.py cleanup_k8s.py

.PHONY: all
all: prepare flake8 test pylint
Expand All @@ -10,15 +12,12 @@ prepare:

.PHONY: pylint
pylint:
pylint ocw/lib/*.py cleanup_k8s.py
pylint $(FILES)

LINE_MAX=140
.PHONY: flake8
flake8:
flake8 --max-line-length=$(LINE_MAX) webui
flake8 --max-line-length=$(LINE_MAX) ocw
flake8 --max-line-length=$(LINE_MAX) $(FILES)
flake8 --max-line-length=$(LINE_MAX) manage.py
flake8 --max-line-length=$(LINE_MAX) cleanup_k8s.py

.PHONY: test
test:
Expand Down
2 changes: 1 addition & 1 deletion ocw/lib/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __new__(cls, vault_namespace: str):
def client(self) -> None:
if self.__client is None:
self.__client = openstack.connect(
debug=DEBUG,
debug=bool(DEBUG),
insecure=True, # Trust the certificate
auth_url=self.get_data('auth_url'),
project_name=self.get_data('project_name'),
Expand Down
4 changes: 3 additions & 1 deletion tests/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ def load_kube_config(self, *args, **kwargs):


class MockedKubernetesClient():
def __init__(self, jobs=[]):
def __init__(self, jobs=None):
if jobs is None:
jobs = []
self.jobs = jobs
self.deleted_jobs = []

Expand Down
4 changes: 3 additions & 1 deletion tests/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def __init__(self, managed_by=None):

class FakeBlobContainer:

def __init__(self, metadata=[], name=None):
def __init__(self, metadata=None, name=None):
if metadata is None:
metadata = []
if name is None:
self.name = "sle-images"
else:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@


class MockRequest:
def __init__(self, response={}):
def __init__(self, response=None):
if response is None:
response = {}
self.response = response

def execute(self):
Expand Down
8 changes: 5 additions & 3 deletions webui/PCWConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def get(self, config_path: str, default=None):
return default
return config_pointer

def getList(self, config_path: str, default: list = []) -> list:
def getList(self, config_path: str, default: list = None) -> list:
if default is None:
default = []
return [i.strip() for i in self.get(config_path, ','.join(default)).split(',')]


Expand Down Expand Up @@ -83,7 +85,7 @@ def get_feature_property(feature: str, property: str, namespace: str = None):
def get_namespaces_for(feature: str) -> list:
if PCWConfig.has(feature):
return ConfigFile().getList(f'{feature}/namespaces', ConfigFile().getList('default/namespaces'))
return list()
return []

@staticmethod
def get_providers_for(feature: str, namespace: str):
Expand Down Expand Up @@ -114,7 +116,7 @@ def has(setting: str) -> bool:
@staticmethod
def getBoolean(config_path: str, namespace: str = None, default=False) -> bool:
if namespace:
(feature, property) = config_path.split('/')
feature, property = config_path.split('/')
setting = f'{feature}.namespace.{namespace}/{property}'
if PCWConfig.has(setting):
value = ConfigFile().get(setting)
Expand Down
6 changes: 2 additions & 4 deletions webui/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
import os
import logging.config
from django.core.management import utils
Expand Down Expand Up @@ -27,7 +26,7 @@
SECRET_KEY = utils.get_random_secret_key()

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('PCW_DEBUG', False)
DEBUG = os.getenv('PCW_DEBUG')

ALLOWED_HOSTS = ['*']

Expand Down Expand Up @@ -187,8 +186,7 @@ def build_absolute_uri(path=''):

if not base_url.startswith("http"):
base_url = f'https://{base_url}'

base_url = re.sub('/+$', '', base_url)
base_url = base_url.rstrip("/")

if len(path) == 0:
return base_url
Expand Down

0 comments on commit 52bb8e5

Please sign in to comment.