Merge lp:~therve/landscape-client/backport-hardware-support into lp:~landscape/landscape-client/backport-12.03

Proposed by Thomas Herve
Status: Rejected
Rejected by: Thomas Herve
Proposed branch: lp:~therve/landscape-client/backport-hardware-support
Merge into: lp:~landscape/landscape-client/backport-12.03
Diff against target: 177 lines (+77/-18)
7 files modified
landscape/broker/client.py (+14/-3)
landscape/manager/config.py (+1/-1)
landscape/manager/hardwareinfo.py (+26/-0)
landscape/manager/tests/test_config.py (+2/-1)
landscape/manager/tests/test_hardwareinfo.py (+29/-0)
landscape/message_schemas.py (+5/-1)
landscape/monitor/plugin.py (+0/-12)
To merge this branch: bzr merge lp:~therve/landscape-client/backport-hardware-support
Reviewer Review Type Date Requested Status
Landscape Pending
Landscape Pending
Review via email: mp+95862@code.launchpad.net

Description of the change

Fairly trivial change, just introduce the feature, and the fix recently made.

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

I'm missing the greater picture, and would like to understand more the reason for this backport.

Also, backport-12.03 was right cut from the Ubuntu packaging branch, which doesn't feel the right workflow (tho it'd do it), as we shouldn't use a packaging branch for upstream source changes.

Unmerged revisions

41. By Thomas Herve

Backport hardware support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'landscape/broker/client.py'
2--- landscape/broker/client.py 2010-04-21 19:58:10 +0000
3+++ landscape/broker/client.py 2012-03-05 09:27:18 +0000
4@@ -41,6 +41,18 @@
5 """An alias for the C{client} attribute."""
6 return self.client
7
8+ def call_on_accepted(self, type, callable, *args, **kwargs):
9+ """
10+ Register a callback fired upon a C{message-type-acceptance-changed}.
11+ """
12+
13+ def acceptance_changed(acceptance):
14+ if acceptance:
15+ return callable(*args, **kwargs)
16+
17+ self.client.reactor.call_on(("message-type-acceptance-changed", type),
18+ acceptance_changed)
19+
20
21 class BrokerClient(object):
22 """Basic plugin registry for clients that have to deal with the broker.
23@@ -53,13 +65,12 @@
24 defined by sub-classes.
25 @ivar broker: A reference to a connected L{RemoteBroker}, it must be set
26 by the connecting machinery at service startup.
27+
28+ @param reactor: A L{TwistedReactor}.
29 """
30 name = "client"
31
32 def __init__(self, reactor):
33- """
34- @param reactor: A L{TwistedReactor}.
35- """
36 super(BrokerClient, self).__init__()
37 self.reactor = reactor
38 self.broker = None
39
40=== modified file 'landscape/manager/config.py'
41--- landscape/manager/config.py 2011-07-18 15:16:18 +0000
42+++ landscape/manager/config.py 2012-03-05 09:27:18 +0000
43@@ -5,7 +5,7 @@
44
45
46 ALL_PLUGINS = ["ProcessKiller", "PackageManager", "UserManager",
47- "ShutdownManager", "Eucalyptus", "AptSources"]
48+ "ShutdownManager", "Eucalyptus", "AptSources", "HardwareInfo"]
49
50
51 class ManagerConfiguration(Configuration):
52
53=== added file 'landscape/manager/hardwareinfo.py'
54--- landscape/manager/hardwareinfo.py 1970-01-01 00:00:00 +0000
55+++ landscape/manager/hardwareinfo.py 2012-03-05 09:27:18 +0000
56@@ -0,0 +1,26 @@
57+import os
58+
59+from twisted.internet.utils import getProcessOutput
60+
61+from landscape.manager.plugin import ManagerPlugin
62+
63+
64+class HardwareInfo(ManagerPlugin):
65+ """A plugin to retrieve hardware information."""
66+
67+ message_type = "hardware-info"
68+ run_interval = 60 * 60 * 24
69+ run_immediately = True
70+ command = "/usr/bin/lshw"
71+
72+ def run(self):
73+ self.call_on_accepted(self.message_type, self.send_message)
74+
75+ def send_message(self):
76+ result = getProcessOutput(
77+ self.command, args=["-xml", "-quiet"], env=os.environ, path=None)
78+ return result.addCallback(self._got_output)
79+
80+ def _got_output(self, output):
81+ message = {"type": self.message_type, "data": output}
82+ return self.registry.broker.send_message(message)
83
84=== modified file 'landscape/manager/tests/test_config.py'
85--- landscape/manager/tests/test_config.py 2011-07-18 15:16:18 +0000
86+++ landscape/manager/tests/test_config.py 2012-03-05 09:27:18 +0000
87@@ -12,7 +12,8 @@
88 def test_plugin_factories(self):
89 """By default all plugins are enabled."""
90 self.assertEqual(["ProcessKiller", "PackageManager", "UserManager",
91- "ShutdownManager", "Eucalyptus", "AptSources"],
92+ "ShutdownManager", "Eucalyptus", "AptSources",
93+ "HardwareInfo"],
94 ALL_PLUGINS)
95 self.assertEqual(ALL_PLUGINS, self.config.plugin_factories)
96
97
98=== added file 'landscape/manager/tests/test_hardwareinfo.py'
99--- landscape/manager/tests/test_hardwareinfo.py 1970-01-01 00:00:00 +0000
100+++ landscape/manager/tests/test_hardwareinfo.py 2012-03-05 09:27:18 +0000
101@@ -0,0 +1,29 @@
102+from landscape.tests.helpers import LandscapeTest, ManagerHelper
103+
104+from landscape.manager.hardwareinfo import HardwareInfo
105+
106+
107+class HardwareInfoTests(LandscapeTest):
108+ helpers = [ManagerHelper]
109+
110+ def setUp(self):
111+ super(HardwareInfoTests, self).setUp()
112+ self.info = HardwareInfo()
113+ self.info.command = "/bin/echo"
114+ self.manager.add(self.info)
115+
116+ service = self.broker_service
117+ service.message_store.set_accepted_types(["hardware-info"])
118+
119+ def test_message(self):
120+ """
121+ L{HardwareInfo} sends the output of its command when running.
122+ """
123+ deferred = self.info.send_message()
124+
125+ def check(ignored):
126+ self.assertMessages(
127+ self.broker_service.message_store.get_pending_messages(),
128+ [{"data": u"-xml -quiet\n", "type": "hardware-info"}])
129+
130+ return deferred.addCallback(check)
131
132=== modified file 'landscape/message_schemas.py'
133--- landscape/message_schemas.py 2011-07-18 15:16:18 +0000
134+++ landscape/message_schemas.py 2012-03-05 09:27:18 +0000
135@@ -99,6 +99,10 @@
136 )})
137
138
139+HARDWARE_INFO = Message("hardware-info", {
140+ "data": utf8})
141+
142+
143 LOAD_AVERAGE = Message("load-average", {
144 "load-averages": List(Tuple(Int(), Float())),
145 })
146@@ -386,7 +390,7 @@
147 message_schemas = {}
148 for schema in [ACTIVE_PROCESS_INFO, COMPUTER_UPTIME, CLIENT_UPTIME,
149 OPERATION_RESULT, COMPUTER_INFO, DISTRIBUTION_INFO,
150- HARDWARE_INVENTORY, LOAD_AVERAGE, MEMORY_INFO,
151+ HARDWARE_INVENTORY, HARDWARE_INFO, LOAD_AVERAGE, MEMORY_INFO,
152 RESYNCHRONIZE, MOUNT_ACTIVITY, MOUNT_INFO, FREE_SPACE,
153 REGISTER, REGISTER_CLOUD_VM, TEMPERATURE, PROCESSOR_INFO,
154 USERS, PACKAGES, PACKAGE_LOCKS,
155
156=== modified file 'landscape/monitor/plugin.py'
157--- landscape/monitor/plugin.py 2011-01-14 10:11:04 +0000
158+++ landscape/monitor/plugin.py 2012-03-05 09:27:18 +0000
159@@ -36,18 +36,6 @@
160 """An alias for the C{client} attribute."""
161 return self.client
162
163- def call_on_accepted(self, type, callable, *args, **kwargs):
164- """
165- Register a callback fired upon a C{message-type-acceptance-changed}.
166- """
167-
168- def acceptance_changed(acceptance):
169- if acceptance:
170- return callable(*args, **kwargs)
171-
172- self.monitor.reactor.call_on(("message-type-acceptance-changed",
173- type), acceptance_changed)
174-
175
176 class DataWatcher(MonitorPlugin):
177 """

Subscribers

People subscribed via source and target branches

to all changes: