Merge lp:~doanac/qa-dashboard/smoke-image-unique into lp:qa-dashboard

Proposed by Andy Doan
Status: Merged
Approved by: Andy Doan
Approved revision: 742
Merged at revision: 742
Proposed branch: lp:~doanac/qa-dashboard/smoke-image-unique
Merge into: lp:qa-dashboard
Diff against target: 64 lines (+28/-1)
2 files modified
smokeng/models.py (+14/-1)
smokeng/tests.py (+14/-0)
To merge this branch: bzr merge lp:~doanac/qa-dashboard/smoke-image-unique
Reviewer Review Type Date Requested Status
Joe Talbott Approve
PS Jenkins bot continuous-integration Approve
Paul Larson Approve
Review via email: mp+218336@code.launchpad.net

Commit message

dashboard api: remove race condition

The dashboard itself is changing to prevent the creation of duplicate
SmokeImage objects. We'll now get this as an http exception when trying
to create an object. We need to handle that by then doing a GET call
to find the SmokeImage created by the other thread that won the race.

Description of the change

This is the backend change needed by:

  https://code.launchpad.net/~doanac/ubuntu-test-cases/ttouch-race/+merge/218335

See commit-message for dirty details

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:741
http://s-jenkins.ubuntu-ci:8080/job/dashboard-ci/324/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/dashboard-ci/324/rebuild

review: Approve (continuous-integration)
Revision history for this message
Paul Larson (pwlars) wrote :

Looks sane to me, but I'll let someone with more familiarity in the dashboard have the final say.

review: Approve
Revision history for this message
Joe Talbott (joetalbott) wrote :

L28 - Doesn't this code get called when there is an existing entry as well? I haven't read the context but it looks like this is in the save() override and my assumption is that save on an existing object instance would raise the DBError here.

review: Needs Information
742. By Andy Doan

code-review catch by josepht

The save method was only working if you changed the object in a
certain way. This fixes the check

Revision history for this message
Andy Doan (doanac) wrote :

On 05/06/2014 06:28 AM, Joe Talbott wrote:
> Review: Needs Information
>
> L28 - Doesn't this code get called when there is an existing entry as well? I haven't read the context but it looks like this is in the save() override and my assumption is that save on an existing object instance would raise the DBError here.
>
Good catch. In my testing I was always changing something like the
"variant". So it became a new SmokeImage object. However, the code
didn't work if you changed a flag like "publish". This fixes things.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:742
http://s-jenkins.ubuntu-ci:8080/job/dashboard-ci/325/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/dashboard-ci/325/rebuild

review: Approve (continuous-integration)
Revision history for this message
Joe Talbott (joetalbott) wrote :

This looks okay to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'smokeng/models.py'
2--- smokeng/models.py 2014-02-18 15:31:31 +0000
3+++ smokeng/models.py 2014-05-06 16:26:55 +0000
4@@ -18,7 +18,7 @@
5
6 from collections import Counter
7
8-from django.db import models
9+from django.db import models, DatabaseError
10
11 from common.models import (
12 DashboardBaseModel,
13@@ -52,6 +52,19 @@
14 '''ensure we have build_number parts'''
15 if not self.build_id:
16 split_build_number(self, False)
17+
18+ # make sure we don't have the same image. It would have made more
19+ # to have proper primary-keys for this table, but it would make for
20+ # weird migration. This is safest and easiest to test for
21+ qs = SmokeImage.objects.filter(
22+ build_number=self.build_number,
23+ release=self.release,
24+ flavor=self.flavor,
25+ arch=self.arch,
26+ variant=self.variant,
27+ )
28+ if qs.count() != 0 and qs[0].id != self.id:
29+ raise DatabaseError('Duplicate image exists')
30 return super(SmokeImage, self).save(**kwargs)
31
32 def __unicode__(self):
33
34=== modified file 'smokeng/tests.py'
35--- smokeng/tests.py 2014-02-27 16:08:17 +0000
36+++ smokeng/tests.py 2014-05-06 16:26:55 +0000
37@@ -24,6 +24,7 @@
38 smokeng.api # just to silence pep8 warnings. this does nothing
39
40 from django.core.urlresolvers import reverse
41+from django.db import DatabaseError
42 from django.test import TestCase
43 from django.test.client import Client
44 from django.contrib.auth.models import (
45@@ -1010,6 +1011,19 @@
46 self.assertEqual(params['release'], obj['release'])
47 self.assertEqual(params['build_number'], obj['rootfs_id'])
48
49+ def testImageAddDuplicate(self):
50+ '''ensure we don't allow duplicate images to be created.'''
51+ params = {
52+ 'build_number': 'build_number',
53+ 'release': 'release',
54+ 'flavor': 'flavor',
55+ 'variant': 'variant',
56+ 'arch': 'arch',
57+ }
58+ self._post('/smokeng/api/v1/image/', params)
59+ with self.assertRaises(DatabaseError):
60+ self._post('/smokeng/api/v1/image/', params)
61+
62 def testResultAdd(self):
63 params = {
64 'ran_at': datetime.datetime.now().isoformat(),

Subscribers

People subscribed via source and target branches