Merge lp:~bjornt/landscape-client/send-apt-sources into lp:~landscape/landscape-client/trunk

Proposed by Björn Tillenius
Status: Merged
Approved by: Alberto Donato
Approved revision: 363
Merged at revision: 358
Proposed branch: lp:~bjornt/landscape-client/send-apt-sources
Merge into: lp:~landscape/landscape-client/trunk
Diff against target: 91 lines (+62/-1)
2 files modified
landscape/package/reporter.py (+4/-0)
landscape/package/tests/test_reporter.py (+58/-1)
To merge this branch: bzr merge lp:~bjornt/landscape-client/send-apt-sources
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
Free Ekanayaka (community) Approve
Review via email: mp+71040@code.launchpad.net

Description of the change

Report a package reporter error to the server if no APT sources are configure, to trigger a PackageReporterAlert.

To post a comment you must log in.
Revision history for this message
Free Ekanayaka (free.ekanayaka) wrote :

Great, +1!

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

Looks good! +1

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 2011-07-06 12:34:11 +0000
3+++ landscape/package/reporter.py 2011-08-10 14:57:35 +0000
4@@ -199,6 +199,10 @@
5 logging.debug("'%s' exited with status %d (out='%s', err='%s'" % (
6 self.smart_update_filename, code, out, err))
7 touch_file(self._config.smart_update_stamp_filename)
8+ if not smart_failed and not self._facade.get_channels():
9+ code = 1
10+ err = "There are no APT sources configured in %s or %s." % (
11+ self.sources_list_filename, self.sources_list_directory)
12 deferred = self._broker.call_if_accepted(
13 "package-reporter-result", self.send_result, code, err)
14 deferred.addCallback(lambda ignore: (out, err, code))
15
16=== modified file 'landscape/package/tests/test_reporter.py'
17--- landscape/package/tests/test_reporter.py 2011-07-05 05:09:11 +0000
18+++ landscape/package/tests/test_reporter.py 2011-08-10 14:57:35 +0000
19@@ -662,7 +662,7 @@
20 reactor.callWhenRunning(do_test)
21 return deferred
22
23- def test_run_smart_update_report_failures(self):
24+ def test_run_smart_update_report_smart_failure(self):
25 """
26 If L{PackageReporter.run_smart_update} fails, a message is sent to the
27 server reporting the error, to be able to fix the problem centrally.
28@@ -687,6 +687,63 @@
29 reactor.callWhenRunning(do_test)
30 return deferred
31
32+ def test_run_smart_update_report_no_sources(self):
33+ """
34+ L{PackageReporter.run_smart_update} reports a failure if smart
35+ succeeds but there are no APT sources defined. Smart doesn't
36+ fail if there are no sources, but we fake a failure in order to
37+ re-use the PackageReporterAlert on the server.
38+ """
39+ self.facade.reset_channels()
40+ message_store = self.broker_service.message_store
41+ message_store.set_accepted_types(["package-reporter-result"])
42+ self.reporter.smart_update_filename = self.makeFile(
43+ "#!/bin/sh\necho -n error >&2\necho -n output\nexit 0")
44+ os.chmod(self.reporter.smart_update_filename, 0755)
45+ deferred = Deferred()
46+
47+ def do_test():
48+ result = self.reporter.run_smart_update()
49+
50+ def callback(ignore):
51+ error = "There are no APT sources configured in %s or %s." % (
52+ self.reporter.sources_list_filename,
53+ self.reporter.sources_list_directory)
54+ self.assertMessages(message_store.get_pending_messages(),
55+ [{"type": "package-reporter-result",
56+ "code": 1, "err": error}])
57+ result.addCallback(callback)
58+ result.chainDeferred(deferred)
59+
60+ reactor.callWhenRunning(do_test)
61+ return deferred
62+
63+ def test_run_smart_update_report_smart_failure_no_sources(self):
64+ """
65+ If L{PackageReporter.run_smart_update} fails and there are no
66+ APT sources configured, the Smart error takes precedence.
67+ """
68+ self.facade.reset_channels()
69+ message_store = self.broker_service.message_store
70+ message_store.set_accepted_types(["package-reporter-result"])
71+ self.reporter.smart_update_filename = self.makeFile(
72+ "#!/bin/sh\necho -n error >&2\necho -n output\nexit 2")
73+ os.chmod(self.reporter.smart_update_filename, 0755)
74+ deferred = Deferred()
75+
76+ def do_test():
77+ result = self.reporter.run_smart_update()
78+
79+ def callback(ignore):
80+ self.assertMessages(message_store.get_pending_messages(),
81+ [{"type": "package-reporter-result",
82+ "code": 2, "err": u"error"}])
83+ result.addCallback(callback)
84+ result.chainDeferred(deferred)
85+
86+ reactor.callWhenRunning(do_test)
87+ return deferred
88+
89 def test_run_smart_update_report_success(self):
90 """
91 L{PackageReporter.run_smart_update} also reports success to be able to

Subscribers

People subscribed via source and target branches

to all changes: