2
# Copyright 2012-2013 Canonical Ltd.
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License version 3, as
6
# published by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16
from django.db import models
18
from common.models import (
25
class SmokeImage(DashboardBaseModel):
27
db_table = 'smoke_images'
29
build_number = models.CharField(max_length=200)
30
release = models.CharField(max_length=200)
31
flavor = models.CharField(max_length=200)
32
arch = models.CharField(max_length=200)
33
variant = models.CharField(max_length=200)
35
def __unicode__(self):
36
return "{} {} {} {}".format(
43
def get_sum(self, field):
45
objs = self.smokeresult_set.aggregate(models.Sum(field))
50
return objs['{}__sum'.format(field)]
54
return self.get_sum('pass_count')
58
return self.get_sum('fail_count')
61
def error_count(self):
62
return self.get_sum('error_count')
65
def total_count(self):
66
return self.get_sum('total_count')
70
agg_data = SmokeResult.objects.filter(
74
models.Sum('pass_count'),
75
models.Sum('total_count'),
78
if agg_data['total_count__sum'] == 0:
81
return float(100) * agg_data['pass_count__sum'] / agg_data['total_count__sum']
85
return Bug.objects.filter(build_bugs__smokeresult__image=self)
88
class SmokeResult(DashboardBaseModel):
90
db_table = 'smoke_results'
91
image = models.ForeignKey(SmokeImage)
92
jenkins_build = models.ForeignKey(JenkinsBuild)
93
name = models.CharField(max_length=255)
94
fail_count = models.IntegerField()
95
error_count = models.IntegerField(null=False, default=0)
96
pass_count = models.IntegerField()
97
total_count = models.IntegerField()
98
ran_at = models.DateTimeField('date run')
100
def __unicode__(self):
101
return "{} - {}".format(
108
return self.jenkins_build.bugs.all()
112
return self.jenkins_build.bugs.count()
116
return self.smokelog_set.all()
120
return self.smokelog_set.count()
124
if self.total_count == 0:
127
return self.pass_count / self.total_count
129
class SmokeLog(DashboardBaseModel):
131
db_table = "smoke_logs"
133
result = models.ForeignKey(SmokeResult)
134
display_name = models.CharField(max_length=255, null=True)
135
path = models.TextField()
137
class SmokeResultBug(DashboardBaseModel):
139
db_table = "smoke_result_bugs"
141
bug = models.ForeignKey(Bug)
142
result = models.ForeignKey(SmokeResult)