Merge lp:~kissiel/checkbox/fix-1556337-conf-files-ignored into lp:checkbox

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 4279
Merged at revision: 4275
Proposed branch: lp:~kissiel/checkbox/fix-1556337-conf-files-ignored
Merge into: lp:checkbox
Diff against target: 193 lines (+69/-39)
3 files modified
checkbox-ng/checkbox_ng/launcher.py (+1/-0)
checkbox-ng/docs/launcher-tutorial.rst (+11/-0)
checkbox-ng/launchers/checkbox-cli (+57/-39)
To merge this branch: bzr merge lp:~kissiel/checkbox/fix-1556337-conf-files-ignored
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+288986@code.launchpad.net

Description of the change

This MR fixes a problem where config files where ignored.

Now the cascade is back. ~/.config contents override /etc/xdg/ contents and launcher contents override both.

Note that config files are expected to use the same syntax as launchers.

bb124e0 checkbox-ng:launchers: fix handling of alternative strategies
44e4432 checkbox-ng:launchers: support config files in /etc/xdg and ~/.config/
c607367 checkbox-ng:launchers: handle invalid secure_ids gracefully
1de2867 checkbox-ng:launchers: make secure_id overridable by launchers/config
88af98b checkbox-ng:docs: add info about supplying secure_id for stock reports
7f99d7f checkbox-ng:launchers: handle config_filename var

To post a comment you must log in.
4277. By Maciej Kisielewski

checkbox-ng:launchers: make secure_id overridable by launchers/config

This lets users use secure_id for stock reports, so only

[transport:c3]
secure_id = my_magic_sid

is needed.

Signed-off-by: Maciej Kisielewski <email address hidden>

4278. By Maciej Kisielewski

checkbox-ng:docs: add info about supplying secure_id for stock reports

Signed-off-by: Maciej Kisielewski <email address hidden>

4279. By Maciej Kisielewski

checkbox-ng:launchers: handle config_filename var

Signed-off-by: Maciej Kisielewski <email address hidden>

Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

Thanks a lot for the fix, tested ok.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox-ng/checkbox_ng/launcher.py'
2--- checkbox-ng/checkbox_ng/launcher.py 2016-03-08 19:51:40 +0000
3+++ checkbox-ng/checkbox_ng/launcher.py 2016-03-15 13:15:32 +0000
4@@ -51,6 +51,7 @@
5
6 config_filename = config.Variable(
7 section="config",
8+ default="canonical-certification.conf",
9 help_text=_("Name of custom configuration file"))
10
11 def get_concrete_launcher(self):
12
13=== modified file 'checkbox-ng/docs/launcher-tutorial.rst'
14--- checkbox-ng/docs/launcher-tutorial.rst 2016-03-08 19:19:16 +0000
15+++ checkbox-ng/docs/launcher-tutorial.rst 2016-03-15 13:15:32 +0000
16@@ -69,6 +69,10 @@
17 This field is a list; use commas or spaces to seperate stock reports. The
18 default value: ``text, certification, submission_files``.
19
20+When using ``certification`` stock report, ``secure_id`` might be overriden by
21+the launcher. To do this define ``secure_id`` in a ``transport:c3`` section
22+(this is the transport that's used by the ``certification`` stock reports).
23+
24 Launcher section example:
25
26 ::
27@@ -78,6 +82,13 @@
28 launcher_version = 1
29 stock_reports = text
30
31+Launcher using all defaults with overriden secure_id:
32+
33+::
34+
35+ [transport:c3]
36+ secure_id = 001122334455667788
37+
38 Providers section
39 =================
40
41
42=== modified file 'checkbox-ng/launchers/checkbox-cli'
43--- checkbox-ng/launchers/checkbox-cli 2016-03-14 22:39:29 +0000
44+++ checkbox-ng/launchers/checkbox-cli 2016-03-15 13:15:32 +0000
45@@ -39,6 +39,7 @@
46 from guacamole.ingredients import cmdtree
47 from guacamole.recipes.cmd import CommandRecipe
48
49+from checkbox_ng.certification import InvalidSecureIDError
50 from checkbox_ng.launcher import DefaultLauncherDefinition
51 from checkbox_ng.launcher import LauncherDefinition
52 from plainbox.abc import IJobResult
53@@ -98,23 +99,29 @@
54 def late_init(self, context):
55 if not context.args.launcher:
56 # launcher not supplied from cli - using the default one
57- context.cmd_toplevel.launcher = DefaultLauncherDefinition()
58- return
59- try:
60- with open(context.args.launcher,
61- 'rt', encoding='UTF-8') as stream:
62- first_line = stream.readline()
63- if not first_line.startswith("#!"):
64- stream.seek(0)
65- text = stream.read()
66- except IOError as exc:
67- _logger.error(_("Unable to load launcher definition: %s"), exc)
68- raise SystemExit(1)
69-
70- generic_launcher = LauncherDefinition()
71- generic_launcher.read_string(text)
72- launcher = generic_launcher.get_concrete_launcher()
73- launcher.read_string(text)
74+ launcher = DefaultLauncherDefinition()
75+ config_filename = launcher.config_filename
76+ else:
77+ try:
78+ with open(context.args.launcher,
79+ 'rt', encoding='UTF-8') as stream:
80+ first_line = stream.readline()
81+ if not first_line.startswith("#!"):
82+ stream.seek(0)
83+ text = stream.read()
84+ except IOError as exc:
85+ _logger.error(_("Unable to load launcher definition: %s"), exc)
86+ raise SystemExit(1)
87+ generic_launcher = LauncherDefinition()
88+ generic_launcher.read_string(text)
89+ config_filename = generic_launcher.config_filename
90+ launcher = generic_launcher.get_concrete_launcher()
91+ configs = [
92+ '/etc/xdg/{}'.format(config_filename),
93+ os.path.expanduser('~/.config/{}'.format(config_filename))]
94+ if context.args.launcher:
95+ configs.append(context.args.launcher)
96+ launcher.read(configs)
97 if launcher.problem_list:
98 _logger.error(_("Unable to start launcher because of errors:"))
99 for problem in launcher.problem_list:
100@@ -227,8 +234,8 @@
101 self.launcher.restart_strategy)
102 kwargs = copy.deepcopy(self.launcher.restart)
103 # [restart] section has the kwargs for the strategy initializer
104- # and the 'alternative_strategy' which is not one, let's pop it
105- kwargs.pop('alternative_strategy')
106+ # and the 'strategy' which is not one, let's pop it
107+ kwargs.pop('strategy')
108 strategy = cls(**kwargs)
109 ctx.sa.use_alternate_restart_strategy(strategy)
110
111@@ -644,7 +651,9 @@
112 self.launcher.exporters['hexr'] = {
113 'unit': '2013.com.canonical.plainbox::hexr'}
114 self.launcher.transports['c3'] = {
115- 'type': 'certification'}
116+ 'type': 'certification',
117+ 'secure_id': self.launcher.transports.get('c3', {}).get(
118+ 'secure_id', None)}
119 self.launcher.reports['upload to certification'] = {
120 'transport': 'c3', 'exporter': 'hexr'}
121 elif report == 'certification-staging':
122@@ -706,11 +715,10 @@
123 else:
124 url = ('https://certification.canonical.com/'
125 'submissions/submit/')
126- if 'secure_id' in self.launcher.transports[transport]:
127- secure_id = self.launcher.transports[transport]['secure_id']
128- else:
129+ secure_id = self.launcher.transports[transport].get(
130+ 'secure_id', None)
131+ if not secure_id:
132 secure_id = input(self.C.BLUE(_('Enter secure-id:')))
133-
134 options = "secure_id={}".format(secure_id)
135 self.transports[transport] = cls(url, options)
136
137@@ -734,9 +742,9 @@
138 exporter_id = self.launcher.exporters[params['exporter']]['unit']
139 done_sending = False
140 while not done_sending:
141- self._create_transport(params['transport'])
142- transport = self.transports[params['transport']]
143 try:
144+ self._create_transport(params['transport'])
145+ transport = self.transports[params['transport']]
146 result = self.ctx.sa.export_to_transport(
147 exporter_id, transport)
148 if result and 'url' in result:
149@@ -745,21 +753,31 @@
150 _logger.warning(
151 _("Problem occured when submitting %s report: %s"),
152 name, exc)
153- if self.is_interactive:
154- message = _("Do you want to retry?")
155- cmd = self._pick_action_cmd([
156- Action('y', _("yes"), 'y'),
157- Action('n', _("no"), 'n')
158- ], message)
159- if cmd == 'y':
160- # let's remove current transport, so in next
161- # iteration it will be "rebuilt", so if some parts
162- # were user-provided, checkbox will ask for them
163- # again
164- self.transports.pop(params['transport'])
165- continue
166+ if self._retry_dialog():
167+ # let's remove current transport, so in next
168+ # iteration it will be "rebuilt", so if some parts
169+ # were user-provided, checkbox will ask for them
170+ # again
171+ self.transports.pop(params['transport'])
172+ continue
173+ except InvalidSecureIDError:
174+ _logger.warning(_("Invalid secure_id"))
175+ if self._retry_dialog():
176+ self.launcher.transports['c3'].pop('secure_id')
177+ continue
178 done_sending = True
179
180+ def _retry_dialog(self):
181+ if self.is_interactive:
182+ message = _("Do you want to retry?")
183+ cmd = self._pick_action_cmd([
184+ Action('y', _("yes"), 'y'),
185+ Action('n', _("no"), 'n')
186+ ], message)
187+ if cmd == 'y':
188+ return True
189+ return False
190+
191 def register_arguments(self, parser):
192 parser.add_argument(
193 'launcher', metavar=_('LAUNCHER'), nargs='?',

Subscribers

People subscribed via source and target branches