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
=== modified file 'checkbox-ng/checkbox_ng/launcher.py'
--- checkbox-ng/checkbox_ng/launcher.py 2016-03-08 19:51:40 +0000
+++ checkbox-ng/checkbox_ng/launcher.py 2016-03-15 13:15:32 +0000
@@ -51,6 +51,7 @@
5151
52 config_filename = config.Variable(52 config_filename = config.Variable(
53 section="config",53 section="config",
54 default="canonical-certification.conf",
54 help_text=_("Name of custom configuration file"))55 help_text=_("Name of custom configuration file"))
5556
56 def get_concrete_launcher(self):57 def get_concrete_launcher(self):
5758
=== modified file 'checkbox-ng/docs/launcher-tutorial.rst'
--- checkbox-ng/docs/launcher-tutorial.rst 2016-03-08 19:19:16 +0000
+++ checkbox-ng/docs/launcher-tutorial.rst 2016-03-15 13:15:32 +0000
@@ -69,6 +69,10 @@
69This field is a list; use commas or spaces to seperate stock reports. The69This field is a list; use commas or spaces to seperate stock reports. The
70default value: ``text, certification, submission_files``.70default value: ``text, certification, submission_files``.
7171
72When using ``certification`` stock report, ``secure_id`` might be overriden by
73the launcher. To do this define ``secure_id`` in a ``transport:c3`` section
74(this is the transport that's used by the ``certification`` stock reports).
75
72Launcher section example:76Launcher section example:
7377
74::78::
@@ -78,6 +82,13 @@
78 launcher_version = 182 launcher_version = 1
79 stock_reports = text83 stock_reports = text
8084
85Launcher using all defaults with overriden secure_id:
86
87::
88
89 [transport:c3]
90 secure_id = 001122334455667788
91
81Providers section92Providers section
82=================93=================
8394
8495
=== modified file 'checkbox-ng/launchers/checkbox-cli'
--- checkbox-ng/launchers/checkbox-cli 2016-03-14 22:39:29 +0000
+++ checkbox-ng/launchers/checkbox-cli 2016-03-15 13:15:32 +0000
@@ -39,6 +39,7 @@
39from guacamole.ingredients import cmdtree39from guacamole.ingredients import cmdtree
40from guacamole.recipes.cmd import CommandRecipe40from guacamole.recipes.cmd import CommandRecipe
4141
42from checkbox_ng.certification import InvalidSecureIDError
42from checkbox_ng.launcher import DefaultLauncherDefinition43from checkbox_ng.launcher import DefaultLauncherDefinition
43from checkbox_ng.launcher import LauncherDefinition44from checkbox_ng.launcher import LauncherDefinition
44from plainbox.abc import IJobResult45from plainbox.abc import IJobResult
@@ -98,23 +99,29 @@
98 def late_init(self, context):99 def late_init(self, context):
99 if not context.args.launcher:100 if not context.args.launcher:
100 # launcher not supplied from cli - using the default one101 # launcher not supplied from cli - using the default one
101 context.cmd_toplevel.launcher = DefaultLauncherDefinition()102 launcher = DefaultLauncherDefinition()
102 return103 config_filename = launcher.config_filename
103 try:104 else:
104 with open(context.args.launcher,105 try:
105 'rt', encoding='UTF-8') as stream:106 with open(context.args.launcher,
106 first_line = stream.readline()107 'rt', encoding='UTF-8') as stream:
107 if not first_line.startswith("#!"):108 first_line = stream.readline()
108 stream.seek(0)109 if not first_line.startswith("#!"):
109 text = stream.read()110 stream.seek(0)
110 except IOError as exc:111 text = stream.read()
111 _logger.error(_("Unable to load launcher definition: %s"), exc)112 except IOError as exc:
112 raise SystemExit(1)113 _logger.error(_("Unable to load launcher definition: %s"), exc)
113114 raise SystemExit(1)
114 generic_launcher = LauncherDefinition()115 generic_launcher = LauncherDefinition()
115 generic_launcher.read_string(text)116 generic_launcher.read_string(text)
116 launcher = generic_launcher.get_concrete_launcher()117 config_filename = generic_launcher.config_filename
117 launcher.read_string(text)118 launcher = generic_launcher.get_concrete_launcher()
119 configs = [
120 '/etc/xdg/{}'.format(config_filename),
121 os.path.expanduser('~/.config/{}'.format(config_filename))]
122 if context.args.launcher:
123 configs.append(context.args.launcher)
124 launcher.read(configs)
118 if launcher.problem_list:125 if launcher.problem_list:
119 _logger.error(_("Unable to start launcher because of errors:"))126 _logger.error(_("Unable to start launcher because of errors:"))
120 for problem in launcher.problem_list:127 for problem in launcher.problem_list:
@@ -227,8 +234,8 @@
227 self.launcher.restart_strategy)234 self.launcher.restart_strategy)
228 kwargs = copy.deepcopy(self.launcher.restart)235 kwargs = copy.deepcopy(self.launcher.restart)
229 # [restart] section has the kwargs for the strategy initializer236 # [restart] section has the kwargs for the strategy initializer
230 # and the 'alternative_strategy' which is not one, let's pop it237 # and the 'strategy' which is not one, let's pop it
231 kwargs.pop('alternative_strategy')238 kwargs.pop('strategy')
232 strategy = cls(**kwargs)239 strategy = cls(**kwargs)
233 ctx.sa.use_alternate_restart_strategy(strategy)240 ctx.sa.use_alternate_restart_strategy(strategy)
234241
@@ -644,7 +651,9 @@
644 self.launcher.exporters['hexr'] = {651 self.launcher.exporters['hexr'] = {
645 'unit': '2013.com.canonical.plainbox::hexr'}652 'unit': '2013.com.canonical.plainbox::hexr'}
646 self.launcher.transports['c3'] = {653 self.launcher.transports['c3'] = {
647 'type': 'certification'}654 'type': 'certification',
655 'secure_id': self.launcher.transports.get('c3', {}).get(
656 'secure_id', None)}
648 self.launcher.reports['upload to certification'] = {657 self.launcher.reports['upload to certification'] = {
649 'transport': 'c3', 'exporter': 'hexr'}658 'transport': 'c3', 'exporter': 'hexr'}
650 elif report == 'certification-staging':659 elif report == 'certification-staging':
@@ -706,11 +715,10 @@
706 else:715 else:
707 url = ('https://certification.canonical.com/'716 url = ('https://certification.canonical.com/'
708 'submissions/submit/')717 'submissions/submit/')
709 if 'secure_id' in self.launcher.transports[transport]:718 secure_id = self.launcher.transports[transport].get(
710 secure_id = self.launcher.transports[transport]['secure_id']719 'secure_id', None)
711 else:720 if not secure_id:
712 secure_id = input(self.C.BLUE(_('Enter secure-id:')))721 secure_id = input(self.C.BLUE(_('Enter secure-id:')))
713
714 options = "secure_id={}".format(secure_id)722 options = "secure_id={}".format(secure_id)
715 self.transports[transport] = cls(url, options)723 self.transports[transport] = cls(url, options)
716724
@@ -734,9 +742,9 @@
734 exporter_id = self.launcher.exporters[params['exporter']]['unit']742 exporter_id = self.launcher.exporters[params['exporter']]['unit']
735 done_sending = False743 done_sending = False
736 while not done_sending:744 while not done_sending:
737 self._create_transport(params['transport'])
738 transport = self.transports[params['transport']]
739 try:745 try:
746 self._create_transport(params['transport'])
747 transport = self.transports[params['transport']]
740 result = self.ctx.sa.export_to_transport(748 result = self.ctx.sa.export_to_transport(
741 exporter_id, transport)749 exporter_id, transport)
742 if result and 'url' in result:750 if result and 'url' in result:
@@ -745,21 +753,31 @@
745 _logger.warning(753 _logger.warning(
746 _("Problem occured when submitting %s report: %s"),754 _("Problem occured when submitting %s report: %s"),
747 name, exc)755 name, exc)
748 if self.is_interactive:756 if self._retry_dialog():
749 message = _("Do you want to retry?")757 # let's remove current transport, so in next
750 cmd = self._pick_action_cmd([758 # iteration it will be "rebuilt", so if some parts
751 Action('y', _("yes"), 'y'),759 # were user-provided, checkbox will ask for them
752 Action('n', _("no"), 'n')760 # again
753 ], message)761 self.transports.pop(params['transport'])
754 if cmd == 'y':762 continue
755 # let's remove current transport, so in next763 except InvalidSecureIDError:
756 # iteration it will be "rebuilt", so if some parts764 _logger.warning(_("Invalid secure_id"))
757 # were user-provided, checkbox will ask for them765 if self._retry_dialog():
758 # again766 self.launcher.transports['c3'].pop('secure_id')
759 self.transports.pop(params['transport'])767 continue
760 continue
761 done_sending = True768 done_sending = True
762769
770 def _retry_dialog(self):
771 if self.is_interactive:
772 message = _("Do you want to retry?")
773 cmd = self._pick_action_cmd([
774 Action('y', _("yes"), 'y'),
775 Action('n', _("no"), 'n')
776 ], message)
777 if cmd == 'y':
778 return True
779 return False
780
763 def register_arguments(self, parser):781 def register_arguments(self, parser):
764 parser.add_argument(782 parser.add_argument(
765 'launcher', metavar=_('LAUNCHER'), nargs='?',783 'launcher', metavar=_('LAUNCHER'), nargs='?',

Subscribers

People subscribed via source and target branches