Merge lp:~chris.gagnon/qa-coverage-dashboard/only-get-last-build-from-jenkins into lp:qa-coverage-dashboard

Proposed by Chris Gagnon on 2014-05-13
Status: Merged
Merged at revision: 773
Proposed branch: lp:~chris.gagnon/qa-coverage-dashboard/only-get-last-build-from-jenkins
Merge into: lp:qa-coverage-dashboard
Diff against target: 299 lines (+146/-49)
4 files modified
gaps/management/commands/c2dconfigutils/cu2dOutputCi.py (+10/-6)
gaps/management/commands/jenkins_pull_coverage.py (+14/-1)
gaps/tests/test_jenkins_pull_coverage.py (+113/-38)
gaps/util/add.py (+9/-4)
To merge this branch: bzr merge lp:~chris.gagnon/qa-coverage-dashboard/only-get-last-build-from-jenkins
Reviewer Review Type Date Requested Status
Allan LeSage (community) 2014-05-13 Approve on 2014-05-19
gaps 2014-05-13 Pending
Review via email: mp+219281@code.launchpad.net
To post a comment you must log in.
770. By Chris Gagnon on 2014-05-13

clean up if statement

771. By Chris Gagnon on 2014-05-13

Update doc string

Allan LeSage (allanlesage) wrote :

I like the tests, they're good. I personally like when assertions go like this: assertEqual(42, my_var) , but apparently there's no consensus on that. A couple of things:

* Can we not test those integers as strings?
* For ll. 68-71, I think you can not do the conditional and just pass through the var.

Otherwise looks good.

review: Needs Fixing
772. By Chris Gagnon on 2014-05-19

dont convert decimal to string in tests, don't use if statment in option

773. By Chris Gagnon on 2014-05-19

fix text conflict

Allan LeSage (allanlesage) wrote :

I certify this commit.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gaps/management/commands/c2dconfigutils/cu2dOutputCi.py'
2--- gaps/management/commands/c2dconfigutils/cu2dOutputCi.py 2014-03-09 01:05:53 +0000
3+++ gaps/management/commands/c2dconfigutils/cu2dOutputCi.py 2014-05-19 13:24:17 +0000
4@@ -114,9 +114,10 @@
5 'parents': None})
6 self.master_list.append(job_list)
7
8- def __call__(self, default_config_path):
9+ def __call__(self, default_config_path, just_last_build=False):
10 """Entry point for cu2d-output-ci"""
11 self.default_config_path = default_config_path
12+ self.just_last_build = just_last_build
13 set_logging(False)
14 local_path = os.path.dirname(os.path.abspath(__file__))
15 pocket_list = os.listdir('stacks')
16@@ -159,10 +160,13 @@
17 job in s for s in added_job)
18 and not str(job).startswith(
19 'generic')):
20- add.records(stack['name'],
21- param.value,
22- job,
23- 'coverage.xml',
24- )
25+ add.records(
26+ stack['name'],
27+ param.value,
28+ job,
29+ 'coverage.xml',
30+ self.just_last_build,
31+ )
32+
33 added_job.append(job)
34 print('job {}'.format(job))
35
36=== modified file 'gaps/management/commands/jenkins_pull_coverage.py'
37--- gaps/management/commands/jenkins_pull_coverage.py 2014-02-25 15:31:32 +0000
38+++ gaps/management/commands/jenkins_pull_coverage.py 2014-05-19 13:24:17 +0000
39@@ -3,6 +3,7 @@
40 import os
41
42 from django.core.management.base import BaseCommand
43+from optparse import make_option
44
45 logger = logging.getLogger('qa_dashboard')
46
47@@ -10,6 +11,15 @@
48 class Command(BaseCommand):
49 help = 'add coverage artifacts to database'
50
51+ option_list = BaseCommand.option_list + (
52+ make_option(
53+ '--last',
54+ action='store_true',
55+ dest='just_last_build',
56+ help='pull in just the last build',
57+ ),
58+ )
59+
60 def handle(self, *args, **options):
61 BASEDIR = os.path.dirname(__file__)
62
63@@ -20,4 +30,7 @@
64 from c2dconfigutils.cu2dOutputCi import OutputCi
65
66 get_coverage = OutputCi()
67- get_coverage(BASEDIR)
68+ #if options['just_last_build']:
69+ # get_coverage(BASEDIR, True)
70+ #else:
71+ get_coverage(BASEDIR, options['just_last_build'])
72
73=== modified file 'gaps/tests/test_jenkins_pull_coverage.py'
74--- gaps/tests/test_jenkins_pull_coverage.py 2014-04-18 22:55:02 +0000
75+++ gaps/tests/test_jenkins_pull_coverage.py 2014-05-19 13:24:17 +0000
76@@ -1,7 +1,3 @@
77-import datetime
78-
79-import common
80-
81 from django.test import TestCase
82
83 from gaps.models import (
84@@ -10,22 +6,39 @@
85 CoverageProject,
86 CoverageStack,
87 )
88-from gaps.util import add, jenkins_pull
89+from gaps.util import add
90
91-from mock import Mock
92+import datetime
93+import decimal
94+import mock
95 from os import path
96
97
98+def make_decimal(number):
99+ c = decimal.getcontext()
100+ c.prec = 3
101+ dec = c.create_decimal(number)
102+ return dec
103+
104+
105 class TestJenkinsPullCoverage(TestCase):
106 def setUp(self):
107 self.url_list = [
108 {
109- 'url': 'http://jenkins.qa.ubuntu.com/job/libqtdbustest-trusty'
110+ 'url': 'http://jenkins.fake/job/libqtdbustest-trusty'
111+ '-i386-ci/11/artifact/work/results/coverage.xml',
112+ 'build_id': 11,
113+ 'ran_at': datetime.datetime(
114+ 2014, 4, 18, 17, 31, 24)
115+ },
116+ {
117+ 'url': 'http://jenkins.fake/job/libqtdbustest-trusty'
118 '-i386-ci/10/artifact/work/results/coverage.xml',
119 'build_id': 10,
120 'ran_at': datetime.datetime(
121 2014, 3, 18, 17, 31, 24)
122 }
123+
124 ]
125
126 localdir = path.dirname(__file__)
127@@ -38,37 +51,99 @@
128 """Verify jenkins_get method is in common.managment"""
129 from common.management import jenkins_get # noqa
130
131- def test_jenkins_pull_coverage_add_to_database(self):
132- jenkins_pull.url_artifact_list = Mock(return_value=self.url_list)
133- common.management.jenkins_get = Mock(return_value=self.jdata)
134- add.records(
135- 'qa',
136- 'libqtdbustest',
137- 'libqtdbustest-trusty-amd64-ci',
138- 'coverage.xml',
139- )
140-
141- data_result = CoverageData.objects.filter(
142- url__contains='coverage.xml').latest('coverage_build')
143-
144- self.assertEquals(
145- data_result.url,
146- 'http://jenkins.qa.ubuntu.com/job/libqtdbustest-trusty-i386-ci'
147- '/10/artifact/work/results/coverage.xml'
148- )
149- self.assertEquals(data_result.name, 'coverage.xml')
150- self.assertEquals(data_result.xml_file, '')
151- self.assertEquals(str(data_result.branch_coverage), '0.514')
152- self.assertEquals(str(data_result.line_coverage), '0.884')
153- self.assertEquals(str(data_result.hit_count), '107')
154- self.assertEquals(str(data_result.line_count), '121')
155- self.assertEquals(str(data_result.taken_count), '75')
156- self.assertEquals(str(data_result.total_count), '146')
157-
158- build_result = CoverageBuild.objects.filter(
159- build_number='10').latest('ran_at')
160-
161- self.assertEquals(str(build_result.build_number), '10')
162+ @mock.patch('gaps.util.add.jenkins_get')
163+ @mock.patch('gaps.util.add.jenkins_pull')
164+ def test_jenkins_pull_coverage_add_to_database(self, mock_pull, mock_get):
165+ mock_get.return_value = self.jdata
166+ mock_pull.url_artifact_list.return_value = self.url_list
167+ add.records(
168+ 'qa',
169+ 'libqtdbustest',
170+ 'libqtdbustest-trusty-amd64-ci',
171+ 'coverage.xml',
172+ )
173+
174+ # There must be 2 records when getting all the builds
175+ self.assertEquals(
176+ CoverageData.objects.count(),
177+ 2
178+ )
179+
180+ data_result = CoverageData.objects.filter(
181+ url__contains='coverage.xml').latest('coverage_build')
182+
183+ self.assertEquals(
184+ data_result.url,
185+ 'http://jenkins.fake/job/libqtdbustest-trusty-i386-ci'
186+ '/11/artifact/work/results/coverage.xml'
187+ )
188+ self.assertEquals(data_result.name, 'coverage.xml')
189+ self.assertEquals(data_result.xml_file, '')
190+
191+ self.assertEquals(data_result.branch_coverage, make_decimal(0.514))
192+ self.assertEquals(data_result.line_coverage, make_decimal(.884))
193+ self.assertEquals(data_result.hit_count, 107)
194+ self.assertEquals(data_result.line_count, 121)
195+ self.assertEquals(data_result.taken_count, 75)
196+ self.assertEquals(data_result.total_count, 146)
197+
198+ build_result = CoverageBuild.objects.filter(
199+ build_number='11').latest('ran_at')
200+
201+ self.assertEquals(str(build_result.build_number), '11')
202+ self.assertEqual(build_result.build_description, 'None')
203+
204+ project_result = CoverageProject.objects.filter(
205+ name='libqtdbustest').latest('name')
206+
207+ self.assertEquals(project_result.name, 'libqtdbustest')
208+
209+ stack_result = CoverageStack.objects.filter(
210+ name='qa').latest('name')
211+
212+ self.assertEquals(stack_result.name, 'qa')
213+
214+ @mock.patch('gaps.util.add.jenkins_get')
215+ @mock.patch('gaps.util.add.jenkins_pull')
216+ def test_jenkins_pull_coverage_last_add_to_database(self,
217+ mock_pull,
218+ mock_get):
219+ mock_get.return_value = self.jdata
220+ mock_pull.url_artifact_list.return_value = self.url_list
221+ add.records(
222+ 'qa',
223+ 'libqtdbustest',
224+ 'libqtdbustest-trusty-amd64-ci',
225+ 'coverage.xml',
226+ True
227+ )
228+ # There must be only one record when getting the last build
229+ self.assertEquals(
230+ CoverageData.objects.count(),
231+ 1
232+ )
233+
234+ data_result = CoverageData.objects.filter(
235+ url__contains='coverage.xml').latest('coverage_build')
236+
237+ self.assertEquals(
238+ data_result.url,
239+ 'http://jenkins.fake/job/libqtdbustest-trusty-i386-ci'
240+ '/11/artifact/work/results/coverage.xml'
241+ )
242+ self.assertEquals(data_result.name, 'coverage.xml')
243+ self.assertEquals(data_result.xml_file, '')
244+ self.assertEquals(data_result.branch_coverage, make_decimal(0.514))
245+ self.assertEquals(data_result.line_coverage, make_decimal(0.884))
246+ self.assertEquals(data_result.hit_count, 107)
247+ self.assertEquals(data_result.line_count, 121)
248+ self.assertEquals(data_result.taken_count, 75)
249+ self.assertEquals(data_result.total_count, 146)
250+
251+ build_result = CoverageBuild.objects.filter(
252+ build_number='11').latest('ran_at')
253+
254+ self.assertEquals(str(build_result.build_number), '11')
255 self.assertEqual(build_result.build_description, 'None')
256
257 project_result = CoverageProject.objects.filter(
258
259=== modified file 'gaps/util/add.py'
260--- gaps/util/add.py 2014-04-18 21:15:24 +0000
261+++ gaps/util/add.py 2014-05-19 13:24:17 +0000
262@@ -13,13 +13,15 @@
263 logger = logging.getLogger('qa_dashboard')
264
265
266-def records(stack_name, project_name, jenkins_job_name, file_name):
267+def records(stack_name, project_name, jenkins_job_name,
268+ file_name, just_last_build=False):
269 """Adds coverage data to the database
270
271 :param stack_name: stack to get artifacts from
272 :param project name: name of project to get artifact from
273 :param jenkins_job_name: job to get artifacts from
274 :param file_name: file name of artifact
275+ :param just_last_build: get just the last build from jenkins
276 """
277 logger.debug("getting last_build")
278 last_build = [
279@@ -30,14 +32,17 @@
280 if last_build == []:
281 last_build.append(0)
282 logger.debug("last build in our database is {}".format(last_build[-1]))
283- url_list = jenkins_pull.url_artifact_list(
284+ pulled_list = jenkins_pull.url_artifact_list(
285 jenkins_job_name,
286 file_name,
287 last_build[-1]
288 )
289
290- if url_list:
291- for build_info in url_list:
292+ if pulled_list:
293+ pulled_list.sort()
294+ if just_last_build:
295+ pulled_list = [pulled_list[-1]]
296+ for build_info in pulled_list:
297 logger.debug('build info{}'.format(build_info))
298 if build_info['url'].endswith('xml'):
299 url_file = build_info['url']

Subscribers

People subscribed via source and target branches

to all changes: