Merge lp:~zyga/checkbox/misc into lp:checkbox

Proposed by Zygmunt Krynicki
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: 3936
Merged at revision: 3932
Proposed branch: lp:~zyga/checkbox/misc
Merge into: lp:checkbox
Diff against target: 220 lines (+71/-13)
5 files modified
plainbox/plainbox/impl/runner.py (+1/-1)
plainbox/plainbox/impl/secure/providers/test_v1.py (+12/-2)
plainbox/plainbox/impl/secure/providers/v1.py (+7/-7)
plainbox/plainbox/impl/session/state.py (+26/-0)
plainbox/plainbox/impl/transport.py (+25/-3)
To merge this branch: bzr merge lp:~zyga/checkbox/misc
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+266696@code.launchpad.net

Description of the change

A few small support patches for the hwcollect branch. I wanted to have them separate so that it's easier to iterate.

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

all good! +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plainbox/plainbox/impl/runner.py'
2--- plainbox/plainbox/impl/runner.py 2015-05-28 09:37:32 +0000
3+++ plainbox/plainbox/impl/runner.py 2015-08-03 09:26:20 +0000
4@@ -207,7 +207,7 @@
5 Initialize the JobRunnerUIDelegate.
6
7 :param ui:
8- (optional) an instnace of IJobRunnerUI to delegate events to
9+ (optional) an instance of IJobRunnerUI to delegate events to
10 """
11 self.ui = ui
12
13
14=== modified file 'plainbox/plainbox/impl/secure/providers/test_v1.py'
15--- plainbox/plainbox/impl/secure/providers/test_v1.py 2015-07-14 08:20:55 +0000
16+++ plainbox/plainbox/impl/secure/providers/test_v1.py 2015-08-03 09:26:20 +0000
17@@ -809,12 +809,22 @@
18 fake_content = [
19 PlugIn(self.JOBS_DIR + "/path/to/jobs1.txt", (
20 "id: a2\n"
21+ "plugin: shell\n"
22+ "command: true\n"
23 "\n"
24- "id: a1\n")),
25+ "id: a1\n"
26+ "plugin: shell\n"
27+ "command: true\n"
28+ )),
29 PlugIn(self.JOBS_DIR + "/path/to/jobs2.txt", (
30 "id: a3\n"
31+ "plugin: shell\n"
32+ "command: true\n"
33 "\n"
34- "id: a4\n"))]
35+ "id: a4\n"
36+ "plugin: shell\n"
37+ "command: true\n"
38+ ))]
39 fake_problems = [IOError("first problem"), OSError("second problem")]
40 with self.provider.fake(fake_content, fake_problems):
41 job_list = self.provider.job_list
42
43=== modified file 'plainbox/plainbox/impl/secure/providers/v1.py'
44--- plainbox/plainbox/impl/secure/providers/v1.py 2015-07-14 08:20:55 +0000
45+++ plainbox/plainbox/impl/secure/providers/v1.py 2015-08-03 09:26:20 +0000
46@@ -73,8 +73,8 @@
47 """
48
49 def __init__(self, filename, text, load_time, provider, *,
50- validate=True, validation_kwargs=None,
51- check=False, context=None):
52+ validate=False, validation_kwargs=None,
53+ check=True, context=None):
54 start_time = now()
55 try:
56 # Inspect the file
57@@ -207,8 +207,8 @@
58 # NOTE: This version of __init__() exists solely so that provider can
59 # default to None. This is still used in some places and must be supported.
60 def __init__(self, filename, text, load_time, provider=None, *,
61- validate=True, validation_kwargs=None,
62- check=False, context=None):
63+ validate=False, validation_kwargs=None,
64+ check=True, context=None):
65 super().__init__(
66 filename, text, load_time, provider, validate=validate,
67 validation_kwargs=validation_kwargs, check=check, context=context)
68@@ -731,8 +731,8 @@
69
70 def __init__(self, name, namespace, version, description, secure,
71 gettext_domain, units_dir, jobs_dir, whitelists_dir, data_dir,
72- bin_dir, locale_dir, base_dir, *, validate=True,
73- validation_kwargs=None, check=False, context=None):
74+ bin_dir, locale_dir, base_dir, *, validate=False,
75+ validation_kwargs=None, check=True, context=None):
76 """
77 Initialize a provider with a set of meta-data and directories.
78
79@@ -844,7 +844,7 @@
80
81 @classmethod
82 def from_definition(cls, definition, secure, *,
83- validate=True, validation_kwargs=None, check=False,
84+ validate=False, validation_kwargs=None, check=True,
85 context=None):
86 """
87 Initialize a provider from Provider1Definition object
88
89=== modified file 'plainbox/plainbox/impl/session/state.py'
90--- plainbox/plainbox/impl/session/state.py 2015-04-16 20:49:41 +0000
91+++ plainbox/plainbox/impl/session/state.py 2015-08-03 09:26:20 +0000
92@@ -34,6 +34,7 @@
93 from plainbox.impl.session.jobs import JobState
94 from plainbox.impl.session.jobs import UndesiredJobReadinessInhibitor
95 from plainbox.impl.unit.job import JobDefinition
96+from plainbox.impl.unit.unit_with_id import UnitWithId
97 from plainbox.impl.unit.testplan import TestPlanUnitSupport
98 from plainbox.vendor import morris
99
100@@ -260,6 +261,7 @@
101 # the SessionState)
102 self._state.on_unit_added.connect(self.on_unit_added)
103 self._state.on_unit_removed.connect(self.on_unit_removed)
104+ self._unit_id_map = {}
105
106 @property
107 def device(self):
108@@ -425,6 +427,26 @@
109 # NOTE: no need to fire the on_unit_removed() signal because the state
110 # object and we've connected it to will fire our version.
111
112+ def get_unit(self, unit_id, kind_name=None):
113+ """
114+ Get an unit with a specific identifier.
115+
116+ :param unit_id:
117+ The identifier of the unit to find
118+ :param kind_name:
119+ (optional) Name of the type of unit. By default units of any type
120+ can be found. Unit kind is the value of the ``unit.Meta.name``
121+ attribute. Using this argument allows the caller to quickly find
122+ only units of a particular type without having to do the filtering
123+ on their side.
124+ :raises KeyError:
125+ If the matching unit does not exists.
126+ """
127+ unit = self._unit_id_map[unit_id]
128+ if kind_name is not None and unit.Meta.name != kind_name:
129+ raise KeyError(unit_id)
130+ return unit
131+
132 def get_ctrl_for_job(self, job):
133 """
134 Get the execution controller most applicable to run this job.
135@@ -472,6 +494,8 @@
136 logger.debug(_("Unit %s added to context %s"), unit, self)
137 if unit.Meta.name == 'job':
138 self.on_job_added(unit)
139+ if isinstance(unit, UnitWithId):
140+ self._unit_id_map[unit.id] = unit
141
142 @morris.signal
143 def on_job_added(self, job):
144@@ -482,6 +506,8 @@
145 def on_unit_removed(self, unit):
146 """ Signal sent whenever a unit is removed from the context. """
147 logger.debug(_("Unit %s removed from context %s"), unit, self)
148+ if isinstance(unit, UnitWithId):
149+ del self._unit_id_map[unit.id]
150
151 def compute_shared(self, cache_key, func, *args, **kwargs):
152 """
153
154=== modified file 'plainbox/plainbox/impl/transport.py'
155--- plainbox/plainbox/impl/transport.py 2014-09-13 11:37:17 +0000
156+++ plainbox/plainbox/impl/transport.py 2015-08-03 09:26:20 +0000
157@@ -18,6 +18,8 @@
158 # along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
159
160 """
161+Shared code for test data transports..
162+
163 :mod:`plainbox.impl.transport` -- shared code for test data transports
164 ======================================================================
165
166@@ -28,24 +30,32 @@
167
168 from collections import OrderedDict
169 from logging import getLogger
170-
171 import pkg_resources
172+import re
173
174 from plainbox.abc import ISessionStateTransport
175 from plainbox.i18n import gettext as _
176+from plainbox.impl.secure.config import Unset
177+
178+import requests
179
180
181 logger = getLogger("plainbox.transport")
182
183
184 class TransportError(Exception):
185+
186 """
187- Base class for problems encountered by the any ISessionStateTransport
188- during execution.
189+ Base class for any problems related to transports.
190+
191+ This class acts the base exception for any and all problems encountered by
192+ the any ISessionStateTransport during execution. Typically this is raised
193+ from .send() that failed in some way.
194 """
195
196
197 class TransportBase(ISessionStateTransport):
198+
199 """
200 Base class for transports that send test data somewhere.
201
202@@ -62,6 +72,18 @@
203 """
204
205 def __init__(self, where, option_string):
206+ """
207+ Initialize the transport base class.
208+
209+ :param where:
210+ A generalized form of "destination". This can be a file name, an
211+ URL or anything appropriate for the given transport.
212+ :param option_string:
213+ Additional options appropriate for the transport, encoded as a
214+ comma-separated list of key=value pairs.
215+ :raises ValueError:
216+ If the option string is malformed.
217+ """
218 self.url = where
219 # parse option string only if there's at least one k=v pair
220 self.options = {}

Subscribers

People subscribed via source and target branches