[PATCH v2 04/10] models: Add 'check' model
Stephen Finucane
stephen.finucane at intel.com
Fri Oct 2 00:52:28 AEST 2015
From: Stephen Finucane <stephenfinucane at hotmail.com>
This will represent the status of tests executed (or executing) against
a patch. This includes a suitable migration and admin view.
Signed-off-by: Stephen Finucane <stephenfinucane at hotmail.com>
---
lib/sql/grant-all.mysql.sql | 5 ++--
lib/sql/grant-all.postgres.sql | 11 ++++---
lib/sql/migration/016-add-status-model.sql | 6 ++++
patchwork/admin.py | 11 ++++++-
patchwork/migrations/0003_add_check_model.py | 33 ++++++++++++++++++++
patchwork/models.py | 45 ++++++++++++++++++++++++++++
6 files changed, 104 insertions(+), 7 deletions(-)
create mode 100644 lib/sql/migration/016-add-status-model.sql
create mode 100644 patchwork/migrations/0003_add_check_model.py
diff --git a/lib/sql/grant-all.mysql.sql b/lib/sql/grant-all.mysql.sql
index 6a3d547..7d5be4f 100644
--- a/lib/sql/grant-all.mysql.sql
+++ b/lib/sql/grant-all.mysql.sql
@@ -25,15 +25,16 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_emailoptout TO 'www-data'@loca
GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_patchchangenotification TO 'www-data'@localhost;
GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_tag TO 'www-data'@localhost;
GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_patchtag TO 'www-data'@localhost;
+GRANT SELECT, UPDATE, INSERT, DELETE ON patchwork_check TO 'www-data'@localhost;
--- allow the mail user (in this case, 'nobody') to add patches
+-- allow the mail user (in this case, 'nobody') to add patches and checkes
GRANT INSERT, SELECT ON patchwork_patch TO 'nobody'@localhost;
GRANT INSERT, SELECT ON patchwork_comment TO 'nobody'@localhost;
GRANT INSERT, SELECT ON patchwork_person TO 'nobody'@localhost;
+GRANT INSERT, SELECT ON patchwork_check TO 'nobody'@localhost;
GRANT INSERT, SELECT, UPDATE, DELETE ON patchwork_patchtag TO 'nobody'@localhost;
GRANT SELECT ON patchwork_project TO 'nobody'@localhost;
GRANT SELECT ON patchwork_state TO 'nobody'@localhost;
GRANT SELECT ON patchwork_tag TO 'nobody'@localhost;
COMMIT;
-
diff --git a/lib/sql/grant-all.postgres.sql b/lib/sql/grant-all.postgres.sql
index 477e10a..d5c9b22 100644
--- a/lib/sql/grant-all.postgres.sql
+++ b/lib/sql/grant-all.postgres.sql
@@ -25,7 +25,8 @@ GRANT SELECT, UPDATE, INSERT, DELETE ON
patchwork_emailoptout,
patchwork_patchchangenotification,
patchwork_tag,
- patchwork_patchtag
+ patchwork_patchtag,
+ patchwork_check
TO "www-data";
GRANT SELECT, UPDATE ON
auth_group_id_seq,
@@ -49,13 +50,15 @@ GRANT SELECT, UPDATE ON
patchwork_userprofile_maintainer_projects_id_seq,
patchwork_tag_id_seq,
patchwork_patchtag_id_seq
+ patchwork_check_id_seq
TO "www-data";
-- allow the mail user (in this case, 'nobody') to add patches
GRANT INSERT, SELECT ON
patchwork_patch,
patchwork_comment,
- patchwork_person
+ patchwork_person,
+ patchwork_check
TO "nobody";
GRANT INSERT, SELECT, UPDATE, DELETE ON
patchwork_patchtag
@@ -69,8 +72,8 @@ GRANT UPDATE, SELECT ON
patchwork_patch_id_seq,
patchwork_person_id_seq,
patchwork_comment_id_seq,
- patchwork_patchtag_id_seq
+ patchwork_patchtag_id_seq,
+ patchwork_check_id_seq
TO "nobody";
COMMIT;
-
diff --git a/lib/sql/migration/016-add-status-model.sql b/lib/sql/migration/016-add-status-model.sql
new file mode 100644
index 0000000..60dac41
--- /dev/null
+++ b/lib/sql/migration/016-add-status-model.sql
@@ -0,0 +1,6 @@
+BEGIN;
+CREATE TABLE `patchwork_check` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `date` datetime NOT NULL, `state` smallint NOT NULL, `target_url` varchar(200) NULL, `description` longtext NULL, `context` varchar(255) NULL, `patch_id` integer NOT NULL, `user_id` integer NOT NULL);
+ALTER TABLE `patchwork_check` ADD CONSTRAINT `patchwork_check_patch_id_32968640b7a49ecf_fk_patchwork_patch_id` FOREIGN KEY (`patch_id`) REFERENCES `patchwork_patch` (`id`);
+ALTER TABLE `patchwork_check` ADD CONSTRAINT `patchwork_check_user_id_72be31b021e2a9db_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);
+
+COMMIT;
diff --git a/patchwork/admin.py b/patchwork/admin.py
index 04a8ff8..d32edba 100644
--- a/patchwork/admin.py
+++ b/patchwork/admin.py
@@ -20,7 +20,7 @@
from django.contrib import admin
from patchwork.models import (
- Project, Person, UserProfile, State, Patch, Comment, Bundle, Tag)
+ Project, Person, UserProfile, State, Patch, Comment, Bundle, Tag, Check)
class ProjectAdmin(admin.ModelAdmin):
@@ -74,6 +74,15 @@ class CommentAdmin(admin.ModelAdmin):
admin.site.register(Comment, CommentAdmin)
+class CheckAdmin(admin.ModelAdmin):
+ list_display = ('patch', 'user', 'state', 'target_url',
+ 'description', 'context')
+ exclude = ('date', )
+ search_fields = ('patch__name', 'project__name')
+ date_hierarchy = 'date'
+admin.site.register(Check, CheckAdmin)
+
+
class BundleAdmin(admin.ModelAdmin):
list_display = ('name', 'owner', 'project', 'public')
list_filter = ('public', 'project')
diff --git a/patchwork/migrations/0003_add_check_model.py b/patchwork/migrations/0003_add_check_model.py
new file mode 100644
index 0000000..50bd72b
--- /dev/null
+++ b/patchwork/migrations/0003_add_check_model.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import datetime
+from django.conf import settings
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('patchwork', '0002_fix_patch_state_default_values'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Check',
+ fields=[
+ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+ ('date', models.DateTimeField(default=datetime.datetime.now)),
+ ('state', models.SmallIntegerField(default=0, help_text=b'The state of the check.', choices=[(0, b'pending'), (1, b'success'), (2, b'warning'), (3, b'fail')])),
+ ('target_url', models.URLField(help_text=b'The target URL to associate with this check. This should be specific to the patch.', null=True, blank=True)),
+ ('description', models.TextField(help_text=b'A brief description of the check.', null=True, blank=True)),
+ ('context', models.CharField(default=b'default', max_length=255, null=True, help_text=b'A label to discern check from checks of other testing systems.', blank=True)),
+ ('patch', models.ForeignKey(to='patchwork.Patch')),
+ ('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ },
+ bases=(models.Model,),
+ ),
+ ]
diff --git a/patchwork/models.py b/patchwork/models.py
index eb9a700..0d36a32 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -1,5 +1,6 @@
# Patchwork - automated patch tracking system
# Copyright (C) 2008 Jeremy Kerr <jk at ozlabs.org>
+# Copyright (C) 2015 Intel Corporation
#
# This file is part of the Patchwork package.
#
@@ -414,6 +415,50 @@ class BundlePatch(models.Model):
ordering = ['order']
+class Check(models.Model):
+ """Check for a patch.
+
+ Checks store the results of any tests executed (or executing) for a
+ given patch. This is useful, for example, when using a continuous
+ integration (CI) system to test patches.
+ """
+ STATE_PENDING = 0
+ STATE_SUCCESS = 1
+ STATE_WARNING = 2
+ STATE_FAIL = 3
+ STATE_CHOICES = (
+ (STATE_PENDING, 'pending'),
+ (STATE_SUCCESS, 'success'),
+ (STATE_WARNING, 'warning'),
+ (STATE_FAIL, 'fail'),
+ )
+
+ patch = models.ForeignKey(Patch)
+ user = models.ForeignKey(User)
+ date = models.DateTimeField(default=datetime.datetime.now)
+
+ state = models.SmallIntegerField(
+ choices=STATE_CHOICES, default=STATE_PENDING,
+ help_text='The state of the check.')
+ target_url = models.URLField(
+ blank=True, null=True,
+ help_text='The target URL to associate with this check. This should'
+ ' be specific to the patch.')
+ description = models.TextField(
+ blank=True, null=True, help_text='A brief description of the check.')
+ context = models.CharField(
+ max_length=255, default='default', blank=True, null=True,
+ help_text='A label to discern check from checks of other testing '
+ 'systems.')
+
+ def __repr__(self):
+ return "<Check id='%d' context='%s' state='%s'" % (
+ self.id, self.context, self.get_state_display())
+
+ def __unicode__(self):
+ return ('%s (%s)' % (self.context, self.get_state_display()))
+
+
class EmailConfirmation(models.Model):
validity = datetime.timedelta(days=settings.CONFIRMATION_VALIDITY_DAYS)
type = models.CharField(max_length=20, choices=[
--
2.0.0
More information about the Patchwork
mailing list