Merge ~kissiel/checkbox-ng:fix-1966045-crash-on-startup into checkbox-ng:master

Proposed by Maciej Kisielewski
Status: Merged
Approved by: Maciej Kisielewski
Approved revision: 27efa7f5f9eeb6c9d4c6d3a9b4614f673ec9a911
Merged at revision: 511e6f6e7f2e29ed994dabfba614097d722caa08
Proposed branch: ~kissiel/checkbox-ng:fix-1966045-crash-on-startup
Merge into: checkbox-ng:master
Diff against target: 116 lines (+36/-10)
4 files modified
checkbox_ng/launcher/subcommands.py (+3/-3)
plainbox/impl/session/assistant.py (+17/-1)
plainbox/impl/session/remote_assistant.py (+3/-3)
plainbox/impl/session/restart.py (+13/-3)
Reviewer Review Type Date Requested Status
Jonathan Cave (community) Approve
Review via email: mp+417573@code.launchpad.net

Description of the change

Fix the problem behind traceback on Checkbox startup.

Instead of reverting the bad patch, with this MR I'm adding an arg that informs the restart strategy detection function of what kind of session the operator runs.

The local session behavior is unchanged. The local nature of those session is just made more explicit.

I also allowed myself to change the titles and types of remote sessions to 'remote' instead of 'checkbox-slave'. Thanks to heuristic I placed in SessionAssistant we don't _need_ to bump the Remote API version - all the detection happens on the service side and on its call tree.

I left the old naming so existing sessions can be supported. I also changed the title and descriptions future sessions will get, and this change also doesn't need a RAPI change, because if there is a checkbox remote/service version mismatch, then:

older service and newer controller: new names and description and old behavior will be used
newer service and older controller: old names and description + new behavior will be used

Tested on running on combinations of remote/services and local sessions.

To post a comment you must log in.
Revision history for this message
Jonathan Cave (jocave) wrote :

27efa7f - happy with this change, they are reasonable defaults that can be easily superseded with settings from launcher etc

87b736e - Tested that I could indeed now start a new session. Also tested that with old controller side and fixed service side to confirm no need for remote API bump.

Thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_ng/launcher/subcommands.py b/checkbox_ng/launcher/subcommands.py
2index b4f4350..69f4a4a 100644
3--- a/checkbox_ng/launcher/subcommands.py
4+++ b/checkbox_ng/launcher/subcommands.py
5@@ -258,13 +258,13 @@ class Launcher(MainLoopStage, ReportsStage):
6 _logger.warning(_(
7 'Using automatically detected restart strategy'))
8 try:
9- strategy = detect_restart_strategy()
10+ strategy = detect_restart_strategy(session_type='local')
11 except LookupError as exc:
12 _logger.warning(exc)
13 _logger.warning(_('Automatic restart disabled!'))
14 strategy = None
15 else:
16- strategy = detect_restart_strategy()
17+ strategy = detect_restart_strategy(session_type='local')
18 if strategy:
19 # gluing the command with pluses b/c the middle part
20 # (launcher path) is optional
21@@ -737,7 +737,7 @@ class Run(MainLoopStage):
22 self.exporter, transport, self.exporter_opts)
23
24 def _configure_restart(self):
25- strategy = detect_restart_strategy()
26+ strategy = detect_restart_strategy(session_type='local')
27 snap_name = os.getenv('SNAP_NAME')
28 if snap_name:
29 # NOTE: This implies that any snap wishing to include a
30diff --git a/plainbox/impl/session/assistant.py b/plainbox/impl/session/assistant.py
31index b2d6991..7afe1a9 100644
32--- a/plainbox/impl/session/assistant.py
33+++ b/plainbox/impl/session/assistant.py
34@@ -245,7 +245,23 @@ class SessionAssistant:
35 """
36 UsageExpectation.of(self).enforce()
37 if self._restart_strategy is None:
38- self._restart_strategy = detect_restart_strategy(self)
39+ # 'checkbox-slave' is deprecated, it's here so people can resume
40+ # old session, the next if statement can be changed to just checking
41+ # for 'remote' title
42+ # session_type = 'remote' if self._metadata.title == 'remote'
43+ # else 'local'
44+ # with the next release or when we do inclusive naming refactor
45+ # or roughly after April of 2022
46+ # TODO: REMOTE API RAPI:
47+ # this heuristic of guessing session type from the title
48+ # should be changed to a proper arg/flag with the Remote API bump
49+ remote_titles = ('remote', 'checkbox-slave')
50+ if self._metadata and self._metadata.title in remote_titles:
51+ session_type = 'remote'
52+ else:
53+ session_type = 'local'
54+ self._restart_strategy = detect_restart_strategy(
55+ self, session_type=session_type)
56 self._restart_cmd_callback = cmd_callback
57 # Prevent second call to this method and to the
58 # use_alternate_restart_strategy() method.
59diff --git a/plainbox/impl/session/remote_assistant.py b/plainbox/impl/session/remote_assistant.py
60index 86f1a83..5763e49 100644
61--- a/plainbox/impl/session/remote_assistant.py
62+++ b/plainbox/impl/session/remote_assistant.py
63@@ -267,9 +267,9 @@ class RemoteSessionAssistant():
64 def start_session(self, configuration):
65 self._reset_sa()
66 _logger.info("start_session: %r", configuration)
67- session_title = 'checkbox-slave'
68- session_desc = 'checkbox-slave session'
69- session_type = 'checkbox-slave'
70+ session_title = 'remote'
71+ session_desc = 'remote session'
72+ session_type = 'remote'
73
74 self._launcher = load_configs()
75 if configuration['launcher']:
76diff --git a/plainbox/impl/session/restart.py b/plainbox/impl/session/restart.py
77index 2cc9c8b..0aa67b4 100644
78--- a/plainbox/impl/session/restart.py
79+++ b/plainbox/impl/session/restart.py
80@@ -259,7 +259,7 @@ class RemoteDebRestartStrategy(RemoteSnappyRestartStrategy):
81 subprocess.call(['systemctl', 'disable', self.service_name])
82
83
84-def detect_restart_strategy(session=None) -> IRestartStrategy:
85+def detect_restart_strategy(session=None, session_type=None) -> IRestartStrategy:
86 """
87 Detect the restart strategy for the current environment.
88 :param session:
89@@ -270,7 +270,12 @@ def detect_restart_strategy(session=None) -> IRestartStrategy:
90 When no such object can be found.
91 """
92 # debian and unconfined checkbox-ng.service
93- if session_type == "checkbox-slave":
94+ # 'checkbox-slave' is deprecated, it's here so people can resume old
95+ # session, but the next line should become:
96+ # session_type == 'remote':
97+ # with the next release or when we do inclusive naming refactor
98+ # or roughly after April of 2022
99+ if session_type in ('remote', 'checkbox-slave'):
100 try:
101 subprocess.run(
102 ['systemctl', 'is-active', '--quiet', 'checkbox-ng.service'],
103@@ -310,7 +315,12 @@ def detect_restart_strategy(session=None) -> IRestartStrategy:
104 snap_data = os.getenv('SNAP_DATA')
105 if snap_data:
106 # Classic snaps w/ remote service enabled and in use
107- if session_type == "checkbox-slave":
108+ # 'checkbox-slave' is deprecated, it's here so people can resume old
109+ # session, but the next line should become:
110+ # session_type == 'remote':
111+ # with the next release or when we do inclusive naming refactor
112+ # or roughly after April of 2022
113+ if session_type in ('remote', 'checkbox-slave'):
114 try:
115 slave_status = subprocess.check_output(
116 ['snapctl', 'get', 'slave'],

Subscribers

People subscribed via source and target branches