diff --git a/build/test/test_utils.py b/build/test/test_utils.py
index 810c1d8..fbd74d1 100644
--- a/build/test/test_utils.py
+++ b/build/test/test_utils.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017 The Sipwise Team - http://sipwise.com
+# Copyright (C) 2017-2020 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
@@ -14,12 +14,12 @@
# with this program. If not, see .
import re
-from django.conf import settings
from django.test import override_settings
from django.test import SimpleTestCase
from mock import patch
from build import exceptions as err
+from build.conf import settings
from build.utils import get_common_release
from build.utils import get_simple_release
from build.utils import ReleaseConfig
diff --git a/build/views.py b/build/views.py
index a356255..cb26318 100644
--- a/build/views.py
+++ b/build/views.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017 The Sipwise Team - http://sipwise.com
+# Copyright (C) 2017-2020 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
@@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
import django_filters
-from django.conf import settings
from django.http import JsonResponse
from django.shortcuts import get_object_or_404
from rest_framework import generics
@@ -25,6 +24,7 @@ from rest_framework_api_key.permissions import HasAPIAccess
from . import models
from . import serializers
from . import tasks
+from .conf import settings
from repoapi.serializers import JenkinsBuildInfoSerializer as JBISerializer
diff --git a/release_changed/models.py b/release_changed/models.py
index 9777ad2..b7a9178 100644
--- a/release_changed/models.py
+++ b/release_changed/models.py
@@ -14,6 +14,18 @@
# with this program. If not, see .
from django.db import models
+from .conf import settings # noqa
+
+# This is needed due to:
+#
+# AppConf classes depend on being imported during startup of the Django
+# process. Even though there are multiple modules loaded automatically, only
+# the models modules (usually the models.py file of your app) are guaranteed
+# to be loaded at startup. Therefore it’s recommended to put your AppConf
+# subclass(es) there, too.
+#
+# https://django-appconf.readthedocs.io/en/latest/
+
class ReleaseChanged(models.Model):
VMTYPE_CHOICES = (("CE", "spce"), ("PRO", "sppro"))
diff --git a/release_dashboard/test/test_rest.py b/release_dashboard/test/test_rest.py
index 17b7781..34c6eba 100644
--- a/release_dashboard/test/test_rest.py
+++ b/release_dashboard/test/test_rest.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2017 The Sipwise Team - http://sipwise.com
+# Copyright (C) 2017-2020 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
@@ -12,7 +12,6 @@
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
-from django.conf import settings
from django.test import override_settings
from django.urls import reverse
from mock import call
@@ -21,6 +20,7 @@ from rest_framework import status
from rest_framework.test import APITestCase
from release_dashboard import models
+from release_dashboard.conf import settings
from repoapi.test.base import APIAuthenticatedTestCase
diff --git a/repoapi/celery.py b/repoapi/celery.py
index 96185db..65049ff 100644
--- a/repoapi/celery.py
+++ b/repoapi/celery.py
@@ -25,7 +25,7 @@ app = Celery("repoapi")
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
-app.config_from_object("django.conf:settings", namespace="CELERY")
+app.config_from_object("repoapi.conf:settings", namespace="CELERY")
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
diff --git a/repoapi/models/__init__.py b/repoapi/models/__init__.py
index c9ecd2d..05a18bc 100644
--- a/repoapi/models/__init__.py
+++ b/repoapi/models/__init__.py
@@ -1,22 +1,26 @@
-# Copyright (C) 2015 The Sipwise Team - http://sipwise.com
-
+# Copyright (C) 2015-2020 The Sipwise Team - http://sipwise.com
+#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
-
+#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
-
+#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
from django.db.models import signals
-from django.conf import settings
-from .jbi import JenkinsBuildInfo, jbi_manage
-from .gri import GerritRepoInfo, gerrit_repo_manage
-from .wni import WorkfrontNoteInfo, workfront_note_manage
+
+from .gri import gerrit_repo_manage
+from .gri import GerritRepoInfo # noqa
+from .jbi import jbi_manage
+from .jbi import JenkinsBuildInfo
+from .wni import workfront_note_manage
+from .wni import WorkfrontNoteInfo # noqa
+from repoapi.conf import settings
post_save = signals.post_save.connect
post_save(jbi_manage, sender=JenkinsBuildInfo)
diff --git a/repoapi/models/jbi.py b/repoapi/models/jbi.py
index 9961e73..1d93b10 100644
--- a/repoapi/models/jbi.py
+++ b/repoapi/models/jbi.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2015 The Sipwise Team - http://sipwise.com
+# Copyright (C) 2015-2020 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
@@ -19,10 +19,10 @@ from datetime import datetime
from datetime import timedelta
from urllib.parse import urlparse
-from django.conf import settings
from django.db import models
from django.forms.models import model_to_dict
+from repoapi.conf import settings
from repoapi.tasks import get_jbi_files
logger = logging.getLogger(__name__)
diff --git a/repoapi/models/wni.py b/repoapi/models/wni.py
index 2d8c3c1..80d527c 100644
--- a/repoapi/models/wni.py
+++ b/repoapi/models/wni.py
@@ -1,28 +1,29 @@
-# Copyright (C) 2015 The Sipwise Team - http://sipwise.com
-
+# Copyright (C) 2015-2020 The Sipwise Team - http://sipwise.com
+#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
-
+#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
-
+#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see .
import logging
import re
from django.db import models
-from django.conf import settings
-from repoapi import utils
+
from release_dashboard.utils.build import is_ngcp_project
+from repoapi import utils
+from repoapi.conf import settings
logger = logging.getLogger(__name__)
workfront_re = re.compile(r"TT#(\d+)")
-workfront_re_branch = re.compile('^mr[0-9]+\.[0-9]+\.[0-9]+$')
+workfront_re_branch = re.compile(r"^mr[0-9]+\.[0-9]+\.[0-9]+$")
commit_re = re.compile(r"^(\w{7}) ")
@@ -62,8 +63,9 @@ class WorkfrontNoteInfo(models.Model):
def workfront_release_target(instance, wid):
if not is_ngcp_project(instance.projectname):
- logger.info("%s not a NGCP project, skip release_target",
- instance.projectname)
+ logger.info(
+ "%s not a NGCP project, skip release_target", instance.projectname
+ )
return
branch = instance.param_branch
if workfront_re_branch.search(branch):
@@ -82,15 +84,14 @@ def workfront_note_add(instance, message, release_target=False):
if not instance.gerrit_eventtype:
change = WorkfrontNoteInfo.getCommit(instance.git_commit_msg)
url = settings.GITWEB_URL.format(instance.projectname, change)
- eventtype = 'git-commit'
+ eventtype = "git-commit"
else:
change = instance.gerrit_change
url = settings.GERRIT_URL.format(instance.gerrit_change)
eventtype = instance.gerrit_eventtype
note, created = wni.get_or_create(
- workfront_id=wid,
- gerrit_change=change,
- eventtype=eventtype)
+ workfront_id=wid, gerrit_change=change, eventtype=eventtype
+ )
if created:
if not utils.workfront_note_send(wid, "%s %s " % (message, url)):
logger.error("remove related WorkfrontNoteInfo")
@@ -106,16 +107,19 @@ def workfront_note_manage(sender, **kwargs):
"""
if kwargs["created"]:
instance = kwargs["instance"]
- if instance.jobname.endswith("-get-code") and \
- instance.result == "SUCCESS":
+ if instance.result != "SUCCESS":
+ return
+ if instance.jobname.endswith("-get-code"):
set_release_target = True
- if instance.gerrit_eventtype == 'change-merged':
+ if instance.gerrit_eventtype == "change-merged":
msg = "%s.git[%s] review merged"
- elif instance.gerrit_eventtype == 'patchset-created':
+ elif instance.gerrit_eventtype == "patchset-created":
msg = "%s.git[%s] review created"
set_release_target = False
else:
msg = "%s.git[%s] commit created"
- workfront_note_add(instance, msg % (instance.projectname,
- instance.param_branch),
- set_release_target)
+ workfront_note_add(
+ instance,
+ msg % (instance.projectname, instance.param_branch),
+ set_release_target,
+ )
diff --git a/repoapi/test/base.py b/repoapi/test/base.py
index d549001..e4db632 100644
--- a/repoapi/test/base.py
+++ b/repoapi/test/base.py
@@ -29,12 +29,12 @@ JBI_BASEDIR = mkdtemp(dir=os.environ.get("RESULTS"))
@override_settings(DEBUG=True, JBI_BASEDIR=JBI_BASEDIR)
class BaseTest(TestCase):
def setUp(self):
- from django.conf import settings
+ from repoapi.conf import settings
mkpath(settings.JBI_BASEDIR, verbose=True)
def tearDown(self):
- from django.conf import settings
+ from repoapi.conf import settings
if os.path.exists(settings.JBI_BASEDIR):
remove_tree(settings.JBI_BASEDIR, verbose=True)
diff --git a/repoapi/test/test_conf.py b/repoapi/test/test_conf.py
new file mode 100644
index 0000000..a0b9df2
--- /dev/null
+++ b/repoapi/test/test_conf.py
@@ -0,0 +1,27 @@
+# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program. If not, see .
+from django.test import SimpleTestCase
+
+
+class TestRepoAPIConf(SimpleTestCase):
+ def test_django_settings(self):
+ from django.conf import settings
+
+ self.assertIsNotNone(settings.RELEASE_CHANGED_JOBS)
+
+ def test_repoapi_settings(self):
+ from repoapi.conf import settings
+
+ self.assertIsNotNone(settings.RELEASE_CHANGED_JOBS)