Merge lp:~therve/landscape-client/detect-task-changes into lp:~landscape/landscape-client/trunk

Proposed by Thomas Herve
Status: Merged
Merged at revision: 633
Proposed branch: lp:~therve/landscape-client/detect-task-changes
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 97 lines (+36/-6)
2 files modified
landscape/package/reporter.py (+10/-5)
landscape/package/tests/test_reporter.py (+26/-1)
To merge this branch: bzr merge lp:~therve/landscape-client/detect-task-changes
Reviewer Review Type Date Requested Status
Christopher Armstrong (community) Approve
Chris Glass (community) Approve
Review via email: mp+151030@code.launchpad.net

Description of the change

OK, here's the change. I'm not sure it fixes everything that Andreas saw, but I believe it's a first step: what I observers is that the reporter was translation hash to ids, but then didn't declare those installed/available. Looking at the changes we made recently, it's clear it's related to the check we're making on the local package state. I added an additional state when we handle a task, it's bit clunky but it fixes the problem.

To post a comment you must log in.
Revision history for this message
Chris Glass (tribaal) wrote :

Looks good! +1

[1]
+ touch_file(self.check_stamp_file)

I think this and the related assertTrue don't really test that the code detected changes, maybe something like the following would?

touch_file(self.check_stamp_file)
time_touched = os.stat(self.check_stamp_file).st_mtime

...

time_modified = os.stat(self.check_stamp_file).st_mtime
self.assertTrue(time_modified > time_touched)

review: Approve
Revision history for this message
Christopher Armstrong (radix) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/package/reporter.py'
2--- landscape/package/reporter.py 2013-02-28 10:09:09 +0000
3+++ landscape/package/reporter.py 2013-02-28 15:23:27 +0000
4@@ -50,8 +50,11 @@
5 apt_update_filename = "/usr/lib/landscape/apt-update"
6 sources_list_filename = "/etc/apt/sources.list"
7 sources_list_directory = "/etc/apt/sources.list.d"
8+ _got_task = False
9
10 def run(self):
11+ self._got_task = False
12+
13 result = Deferred()
14
15 result.addCallback(lambda x: self.run_apt_update())
16@@ -251,8 +254,10 @@
17 def handle_task(self, task):
18 message = task.data
19 if message["type"] == "package-ids":
20+ self._got_task = True
21 return self._handle_package_ids(message)
22 if message["type"] == "resynchronize":
23+ self._got_task = True
24 return self._handle_resynchronize()
25
26 def _handle_package_ids(self, message):
27@@ -447,7 +452,7 @@
28 Check if any information regarding packages have changed, and if so
29 compute the changes and send a signal.
30 """
31- if self._package_state_has_changed():
32+ if self._got_task or self._package_state_has_changed():
33 return self._compute_packages_changes()
34 else:
35 return succeed(None)
36@@ -462,12 +467,12 @@
37
38 @return True if the status changed, False otherwise.
39 """
40+ stamp_file = self._config.detect_package_changes_stamp
41+ if not os.path.exists(stamp_file):
42+ return True
43+
44 status_file = apt_pkg.config.find_file("dir::state::status")
45 lists_dir = apt_pkg.config.find_dir("dir::state::lists")
46- stamp_file = self._config.detect_package_changes_stamp
47- if not os.path.exists(stamp_file):
48- return True
49-
50 files = [status_file, lists_dir]
51 files.extend(glob.glob("%s/*Packages" % lists_dir))
52
53
54=== modified file 'landscape/package/tests/test_reporter.py'
55--- landscape/package/tests/test_reporter.py 2013-01-04 10:50:53 +0000
56+++ landscape/package/tests/test_reporter.py 2013-02-28 15:23:27 +0000
57@@ -4,7 +4,7 @@
58 import time
59 import apt_pkg
60
61-from twisted.internet.defer import Deferred, succeed
62+from twisted.internet.defer import Deferred, succeed, inlineCallbacks
63 from twisted.internet import reactor
64
65
66@@ -943,6 +943,31 @@
67 result = self.reporter.detect_packages_changes()
68 return result.addCallback(got_result)
69
70+ @inlineCallbacks
71+ def test_detect_packages_after_tasks(self):
72+ """
73+ When the L{PackageReporter} got a task to handle, it forces itself to
74+ detect package changes, not checking the local state of package.
75+ """
76+ message_store = self.broker_service.message_store
77+ message_store.set_accepted_types(["packages"])
78+
79+ self.store.set_hash_ids({HASH1: 1, HASH2: 2, HASH3: 3})
80+
81+ touch_file(self.check_stamp_file)
82+
83+ self.store.add_task("reporter",
84+ {"type": "package-ids", "ids": [123, 456],
85+ "request-id": 123})
86+
87+ yield self.reporter.handle_tasks()
88+
89+ yield self.reporter.detect_packages_changes()
90+
91+ self.assertMessages(message_store.get_pending_messages(),
92+ [{"type": "packages", "available": [(1, 3)]}])
93+ self.assertTrue(os.path.exists(self.check_stamp_file))
94+
95 def test_detect_packages_changes_with_not_locked_and_ranges(self):
96 """
97 Ranges are used when reporting changes to 3 or more not locked packages

Subscribers

People subscribed via source and target branches

to all changes: