Merge lp:~gmb/launchpad/not-nullify-bwa.result-bug-546774 into lp:launchpad/db-devel

Proposed by Graham Binns
Status: Merged
Approved by: Graham Binns
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~gmb/launchpad/not-nullify-bwa.result-bug-546774
Merge into: lp:launchpad/db-devel
Diff against target: 185 lines (+51/-14)
7 files modified
database/schema/patch-2207-47-0.sql (+6/-0)
lib/lp/bugs/doc/bug-watch-activity.txt (+9/-5)
lib/lp/bugs/interfaces/bugwatch.py (+14/-0)
lib/lp/bugs/model/bugwatch.py (+6/-1)
lib/lp/bugs/scripts/checkwatches/scheduler.py (+4/-4)
lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt (+8/-2)
lib/lp/bugs/tests/test_bugwatch.py (+4/-2)
To merge this branch: bzr merge lp:~gmb/launchpad/not-nullify-bwa.result-bug-546774
Reviewer Review Type Date Requested Status
Björn Tillenius (community) db Approve
Gavin Panella (community) code Approve
Stuart Bishop (community) db Approve
Review via email: mp+22934@code.launchpad.net

Commit message

Make BugWatchActivity.result NOT NULL and add a default SYNC_SUCCESS BugWatchActivityStatus.

Description of the change

This branch adds a DB patch to make BugWatchActivity.result NOT NULL,
updates all existing BugWatchActivity's with a NULL result to have a
result of BugWatchActivityStatus.SYNC_SUCCESS, which is now our base
success status.

== database/schema/patch-2207-99-0.sql ==

 - This patch updates all existing BugWatchActivity records with a NULL
   result to have a result value of 9, which corresponds with
   BugWatchActivityStatus.SYNC_SUCCESS.
 - The patch also makes BugWatchActivity.result NOT NULL.

== lib/lp/bugs/doc/bug-watch-activity.txt ==

 - I've updated the tests to account for the fact that
   BugWatchActivity.result can't now be None.

== lib/lp/bugs/interfaces/bugwatch.py ==

 - I've added a SYNC_SUCCESS status to BugWatchActivityStatus.
 - I've added a list of BugWatchActivityStatuses considered successful
   which we can use in queries and so on. We plan to expand this later.

== lib/lp/bugs/model/bugwatch.py ==

 - I've updated addActivity() so that it now sets the result of the new
   BugWatchActivity entry to SYNC_SUCCESS if no other value is
   specified.

== lib/lp/bugs/scripts/checkwatches/scheduler.py ==

 - I've updated the scheduler query to query for activity without a
   success status rather than just querying for result is not null.

== lib/lp/bugs/tests/test_bugwatch.py ==

 - I've updated the test to ensure that the scheduler treats success
   results correctly (i.e. by ignoring them when it calculates when next
   to check the watch).

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good. Approved as patch-2207-47-0.sql

review: Approve (db)
Revision history for this message
Gavin Panella (allenap) :
review: Approve (code)
Revision history for this message
Björn Tillenius (bjornt) :
review: Approve (db)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'database/schema/patch-2207-47-0.sql'
2--- database/schema/patch-2207-47-0.sql 1970-01-01 00:00:00 +0000
3+++ database/schema/patch-2207-47-0.sql 2010-04-08 09:52:48 +0000
4@@ -0,0 +1,6 @@
5+SET client_min_messages=ERROR;
6+
7+UPDATE BugWatchActivity SET result = 9 WHERE result IS NULL;
8+ALTER TABLE BugWatchActivity ALTER COLUMN result SET NOT NULL;
9+
10+INSERT INTO LaunchpadDatabaseRevision VALUES (2207, 47, 0);
11
12=== modified file 'lib/lp/bugs/doc/bug-watch-activity.txt'
13--- lib/lp/bugs/doc/bug-watch-activity.txt 2010-03-22 14:28:03 +0000
14+++ lib/lp/bugs/doc/bug-watch-activity.txt 2010-04-08 09:52:48 +0000
15@@ -50,11 +50,14 @@
16 >>> activity.activity_date
17 datetime.datetime...
18
19+The BugWatchActivity's result will be BugWatchActivityStatus.SYNC_SUCCEEDED.
20+
21+ >>> print activity.result.title
22+ Synchronisation succeeded
23+
24 The other fields on the BugWatchActivity record, which aren't required,
25 will all be None.
26
27- >>> print activity.result
28- None
29 >>> print activity.message
30 None
31 >>> print activity.oops_id
32@@ -83,12 +86,13 @@
33 >>> print bug_watch.activity.count()
34 2
35
36-The most recent activity entry will have a result of None since it was
37+The most recent activity entry will have a result of
38+BugWatchActivityStatus.SYNC_SUCCEEDED since it was
39 successful.
40
41 >>> most_recent_activity = bug_watch.activity.first()
42- >>> print most_recent_activity.result
43- None
44+ >>> print most_recent_activity.result.title
45+ Synchronisation succeeded
46
47 Its message will also be empty
48
49
50=== modified file 'lib/lp/bugs/interfaces/bugwatch.py'
51--- lib/lp/bugs/interfaces/bugwatch.py 2010-03-23 12:55:05 +0000
52+++ lib/lp/bugs/interfaces/bugwatch.py 2010-04-08 09:52:48 +0000
53@@ -8,6 +8,7 @@
54 __metaclass__ = type
55
56 __all__ = [
57+ 'BUG_WATCH_ACTIVITY_SUCCESS_STATUSES',
58 'BugWatchActivityStatus',
59 'IBugWatch',
60 'IBugWatchActivity',
61@@ -93,6 +94,19 @@
62 Launchpad cannot import the status of private remote bugs.
63 """)
64
65+ SYNC_SUCCEEDED = DBItem(9, """
66+ Synchronisation succeeded
67+
68+ The remote bug's status was successfully synchronised to Launchpad.
69+ """)
70+
71+
72+# The set of BugWatchActivityStatuses that are considered to indicate
73+# success.
74+BUG_WATCH_ACTIVITY_SUCCESS_STATUSES = [
75+ BugWatchActivityStatus.SYNC_SUCCEEDED,
76+ ]
77+
78
79 class IBugWatch(IHasBug):
80 """A bug on a remote system."""
81
82=== modified file 'lib/lp/bugs/model/bugwatch.py'
83--- lib/lp/bugs/model/bugwatch.py 2010-03-23 12:55:05 +0000
84+++ lib/lp/bugs/model/bugwatch.py 2010-04-08 09:52:48 +0000
85@@ -282,7 +282,12 @@
86 """See `IBugWatch`."""
87 activity = BugWatchActivity()
88 activity.bug_watch = self
89- activity.result = result
90+ if result is None:
91+ # If no result is passed we assume that the activity
92+ # succeded and set the result field accordingly.
93+ activity.result = BugWatchActivityStatus.SYNC_SUCCEEDED
94+ else:
95+ activity.result = result
96 if message is not None:
97 activity.message = unicode(message)
98 if oops_id is not None:
99
100=== modified file 'lib/lp/bugs/scripts/checkwatches/scheduler.py'
101--- lib/lp/bugs/scripts/checkwatches/scheduler.py 2010-03-26 14:33:46 +0000
102+++ lib/lp/bugs/scripts/checkwatches/scheduler.py 2010-04-08 09:52:48 +0000
103@@ -10,12 +10,11 @@
104
105 import transaction
106
107-from storm.expr import Not
108-
109 from canonical.database.sqlbase import sqlvalues
110 from canonical.launchpad.utilities.looptuner import TunableLoop
111 from canonical.launchpad.interfaces import IMasterStore
112
113+from lp.bugs.interfaces.bugwatch import BUG_WATCH_ACTIVITY_SUCCESS_STATUSES
114 from lp.bugs.model.bugwatch import BugWatch
115
116
117@@ -70,7 +69,7 @@
118 FROM (SELECT 1
119 FROM bugwatchactivity
120 WHERE bugwatchactivity.bug_watch = bug_watch.id
121- AND bugwatchactivity.result IS NOT NULL
122+ AND bugwatchactivity.result NOT IN (%s)
123 ORDER BY bugwatchactivity.id DESC
124 LIMIT %s) AS recent_failures
125 ) AS recent_failure_count
126@@ -80,7 +79,8 @@
127 ) AS counts
128 WHERE BugWatch.id = counts.id
129 """ % sqlvalues(
130- self.delay_coefficient, self.max_sample_size, chunk_size)
131+ self.delay_coefficient, BUG_WATCH_ACTIVITY_SUCCESS_STATUSES,
132+ self.max_sample_size, chunk_size)
133 self.transaction.begin()
134 result = self.store.execute(query)
135 self.log.debug("Scheduled %s watches" % result.rowcount)
136
137=== modified file 'lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt'
138--- lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt 2010-03-22 10:36:53 +0000
139+++ lib/lp/bugs/stories/bugwatches/xx-bugwatch-errors.txt 2010-04-08 09:52:48 +0000
140@@ -54,11 +54,17 @@
141 The Mozilla.org Bug Tracker bug #900 appears not to exist. Check
142 that the bug number is correct.
143
144-We can observe this for each of the BugWatchActivityStatus values:
145+We can observe this for each of the BugWatchActivityStatus failure values:
146
147+ >>> from lp.bugs.interfaces.bugwatch import (
148+ ... BUG_WATCH_ACTIVITY_SUCCESS_STATUSES)
149 >>> from lp.bugs.tests.externalbugtracker import (
150 ... set_bugwatch_error_type)
151- >>> for item in sorted(BugWatchActivityStatus.items):
152+
153+ >>> failure_values = [
154+ ... value for value in sorted(BugWatchActivityStatus.items) if
155+ ... value not in BUG_WATCH_ACTIVITY_SUCCESS_STATUSES]
156+ >>> for item in failure_values:
157 ... set_bugwatch_error_type(watch, item)
158 ... user_browser.open('http://bugs.launchpad.dev/thunderbird/+bug/12')
159 ... for tag in find_tags_by_class(user_browser.contents,
160
161=== modified file 'lib/lp/bugs/tests/test_bugwatch.py'
162--- lib/lp/bugs/tests/test_bugwatch.py 2010-03-26 14:49:24 +0000
163+++ lib/lp/bugs/tests/test_bugwatch.py 2010-04-08 09:52:48 +0000
164@@ -16,10 +16,9 @@
165 from zope.component import getUtility
166
167 from canonical.launchpad.ftests import login, ANONYMOUS
168+from canonical.launchpad.scripts.garbo import BugWatchActivityPruner
169 from canonical.launchpad.scripts.logger import QuietFakeLogger
170 from canonical.launchpad.webapp import urlsplit
171-from canonical.launchpad.scripts.garbo import BugWatchActivityPruner
172-from canonical.launchpad.scripts.logger import QuietFakeLogger
173 from canonical.testing import (
174 DatabaseFunctionalLayer, LaunchpadFunctionalLayer, LaunchpadZopelessLayer)
175
176@@ -496,6 +495,9 @@
177 # If a watch has been checked and has never failed its next
178 # check will be scheduled for 24 hours after its last check.
179 now = datetime.now(utc)
180+ # Add some succesful activity to ensure that successful activity
181+ # is handled correctly.
182+ self.bug_watch.addActivity()
183 self.bug_watch.lastchecked = now
184 self.bug_watch.next_check = None
185 transaction.commit()

Subscribers

People subscribed via source and target branches

to status/vote changes: