mirror of https://github.com/sipwise/repoapi.git
* Dockerfile: add screen and refresh due new requirements * create settings/test.py just for tests - celery in memory ( no need of server ) - files in RESULTS * repoapi/tasks.py for celery tasks - download console.txt and job.json from jenkins when a JenkinsBuildInfo is created * repoapi.ini: - fire worker from uwsgi http://uwsgi-docs.readthedocs.io/en/latest/AttachingDaemons.html Change-Id: Ib23c45194878a6fdbbe547058013e39516ea2d17changes/73/7073/7
parent
a432b044d8
commit
e88f585942
@ -0,0 +1,19 @@
|
||||
# Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
|
||||
from __future__ import absolute_import
|
||||
|
||||
# This will make sure the app is always imported when
|
||||
# Django starts so that shared_task will use this app.
|
||||
from .celery import app as celery_app # noqa
|
@ -0,0 +1,30 @@
|
||||
# Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import os
|
||||
from celery import Celery
|
||||
|
||||
# set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'repoapi.settings.prod')
|
||||
# pylint: disable=C0413
|
||||
from django.conf import settings # noqa
|
||||
|
||||
app = Celery('repoapi')
|
||||
|
||||
# Using a string here means the worker will not have to
|
||||
# pickle the object when using Windows.
|
||||
app.config_from_object('django.conf:settings')
|
||||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
@ -0,0 +1,70 @@
|
||||
# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||
import os
|
||||
# pylint: disable=W0401,W0614
|
||||
from .common import *
|
||||
|
||||
BASE_DIR = os.path.dirname(
|
||||
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
os.environ.setdefault('RESULTS', '/tmp')
|
||||
RESULTS_DIR = os.environ['RESULTS']
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = ')+0h68-(g30hg1awc6!y65cwws6j^qd5=&pc2@h430=9x@bf%2'
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = True
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
TESTING_APPS = [
|
||||
'django_jenkins',
|
||||
]
|
||||
INSTALLED_APPS.extend(TESTING_APPS)
|
||||
INSTALLED_APPS.extend(PROJECT_APPS)
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
|
||||
}
|
||||
}
|
||||
|
||||
# django-jenkins
|
||||
JENKINS_TASKS = (
|
||||
'django_jenkins.tasks.run_pylint',
|
||||
'django_jenkins.tasks.run_flake8',
|
||||
)
|
||||
PYLINT_RCFILE = 'pylint.cfg'
|
||||
|
||||
DJANGO_LOG_LEVEL = 'DEBUG'
|
||||
|
||||
JENKINS_URL = "http://localhost"
|
||||
GERRIT_URL = "https://gerrit.local/{}"
|
||||
GITWEB_URL = "https://git.local/gitweb/?p={}.git;a=commit;h={}"
|
||||
WORKFRONT_CREDENTIALS = os.path.join(BASE_DIR, '.workfront.ini')
|
||||
|
||||
# celery
|
||||
BROKER_BACKEND = 'memory'
|
||||
CELERY_ALWAYS_EAGER = True
|
||||
JBI_BASEDIR = os.path.join(RESULTS_DIR, 'jbi_files')
|
@ -0,0 +1,24 @@
|
||||
# Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
|
||||
from __future__ import absolute_import
|
||||
|
||||
from celery import shared_task
|
||||
from .utils import jenkins_get_console, jenkins_get_job
|
||||
|
||||
|
||||
@shared_task
|
||||
def get_jbi_files(jobname, buildnumber):
|
||||
jenkins_get_console(jobname, buildnumber)
|
||||
jenkins_get_job(jobname, buildnumber)
|
@ -0,0 +1,74 @@
|
||||
# Copyright (C) 2015 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from django.test import TestCase
|
||||
from django.conf import settings
|
||||
from repoapi.models import JenkinsBuildInfo
|
||||
from repoapi.utils import JBI_CONSOLE_URL, JBI_JOB_URL
|
||||
from mock import patch, call
|
||||
|
||||
class TestJBICelery(TestCase):
|
||||
|
||||
def get_defaults(self):
|
||||
defaults = {
|
||||
'tag': "edc90cd9-37f3-4613-9748-ed05a32031c2",
|
||||
'projectname': "real-fake",
|
||||
'jobname': "real-fake-gerrit",
|
||||
'buildnumber': 1,
|
||||
'result': "SUCCESS",
|
||||
'job_url': "https://jenkins.mgm.sipwise.com/job/real-fake-gerrit/",
|
||||
'param_tag': "none",
|
||||
'param_branch': "master",
|
||||
'param_release': "none",
|
||||
'param_distribution': "wheezy",
|
||||
'param_ppa': "gerrit_MT10339_review2054",
|
||||
'git_commit_msg': "7fg4567 TT#0001 whatever",
|
||||
}
|
||||
return defaults
|
||||
|
||||
def setUp(self):
|
||||
if not os.path.exists(settings.JBI_BASEDIR):
|
||||
os.makedirs(settings.JBI_BASEDIR)
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists(settings.JBI_BASEDIR):
|
||||
shutil.rmtree(settings.JBI_BASEDIR)
|
||||
|
||||
@patch('repoapi.utils.dlfile')
|
||||
def test_jbi_path_creation(self, dlfile):
|
||||
param = self.get_defaults()
|
||||
jbi = JenkinsBuildInfo.objects.create(**param)
|
||||
base_path = os.path.join(settings.JBI_BASEDIR,
|
||||
jbi.jobname, str(jbi.buildnumber))
|
||||
self.assertTrue(os.path.exists(settings.JBI_BASEDIR), settings.JBI_BASEDIR)
|
||||
self.assertTrue(os.path.exists(base_path))
|
||||
path = os.path.join(base_path, 'console.txt')
|
||||
url = JBI_CONSOLE_URL.format(
|
||||
settings.JENKINS_URL,
|
||||
jbi.jobname,
|
||||
jbi.buildnumber
|
||||
)
|
||||
calls = [call(url, path),]
|
||||
url = JBI_JOB_URL.format(
|
||||
settings.JENKINS_URL,
|
||||
jbi.jobname,
|
||||
jbi.buildnumber
|
||||
)
|
||||
path = os.path.join(base_path, 'job.json')
|
||||
calls.append(call(url, path))
|
||||
dlfile.assert_has_calls(calls)
|
Loading…
Reference in new issue