Merge ~sylvain-pineau/checkbox-ng:more-remote-fixes into checkbox-ng:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 819be75ccbdc6b76d0d05622c9c1f12795defae4
Merged at revision: 47229249ed71df88e7c8c0f9feec054fb60be4d9
Proposed branch: ~sylvain-pineau/checkbox-ng:more-remote-fixes
Merge into: checkbox-ng:master
Diff against target: 81 lines (+22/-21)
2 files modified
checkbox_ng/launcher/slave.py (+2/-1)
plainbox/impl/session/remote_assistant.py (+20/-20)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+418023@code.launchpad.net

Description of the change

Two more patches for remote:

1. Ensure that the future services installed via snap install hooks will select the appropriate restart strategy (must be RemoteDebRestartStrategy)

2. XDG_SESSION_TYPE is added to the extra env var for jobs requiring a different command on wayland sessions.

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

Looks good, totally landable. The shell invocation to extract XDG_SESSION_TYPE using bash chain bothered me, so I proposed python version instead below

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

Excellent idea, I've reworked my patches accordingly

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_ng/launcher/slave.py b/checkbox_ng/launcher/slave.py
2index c7e79df..c184371 100644
3--- a/checkbox_ng/launcher/slave.py
4+++ b/checkbox_ng/launcher/slave.py
5@@ -116,8 +116,9 @@ class RemoteSlave():
6 SessionAssistantSlave.session_assistant = RemoteSessionAssistant(
7 lambda s: [sys.argv[0] + 'service'])
8 snap_data = os.getenv('SNAP_DATA')
9+ snap_rev = os.getenv('SNAP_REVISION')
10 remote_restart_strategy_debug = os.getenv('REMOTE_RESTART_DEBUG')
11- if snap_data or remote_restart_strategy_debug or ctx.args.resume:
12+ if (snap_data and snap_rev) or ctx.args.resume:
13 if remote_restart_strategy_debug:
14 strategy = RemoteSnappyRestartStrategy(debug=True)
15 else:
16diff --git a/plainbox/impl/session/remote_assistant.py b/plainbox/impl/session/remote_assistant.py
17index 5763e49..e3c6c11 100644
18--- a/plainbox/impl/session/remote_assistant.py
19+++ b/plainbox/impl/session/remote_assistant.py
20@@ -27,7 +27,6 @@ from collections import namedtuple
21 from contextlib import suppress
22 from tempfile import SpooledTemporaryFile
23 from threading import Thread, Lock
24-from subprocess import CalledProcessError, check_output
25
26 from plainbox.impl.execution import UnifiedRunner
27 from plainbox.impl.session.assistant import SessionAssistant
28@@ -211,26 +210,26 @@ class RemoteSessionAssistant():
29 self._last_response = response
30 self._state = Running
31
32+ def _set_envvar_from_proc(self, name):
33+ for path in os.listdir('/proc/'):
34+ with suppress(Exception):
35+ env = open(
36+ os.path.join('/proc/', path, 'environ')).read().split('\0')
37+ for key, val in [item.split('=') for item in env]:
38+ if key == name:
39+ return val
40+ return ''
41+
42 def _prepare_display_without_psutil(self):
43- try:
44- display_value = check_output(
45- 'strings /proc/*/environ 2>/dev/null | '
46- 'grep -m 1 -oP "(?<=DISPLAY=).*"',
47- shell=True, universal_newlines=True).rstrip()
48- xauth_value = check_output(
49- 'strings /proc/*/environ 2>/dev/null | '
50- 'grep -m 1 -oP "(?<=XAUTHORITY=).*"',
51- shell=True, universal_newlines=True).rstrip()
52- uid = pwd.getpwnam(self._normal_user).pw_uid
53- return {
54- 'DISPLAY': display_value,
55- 'XAUTHORITY': xauth_value,
56- 'XDG_RUNTIME_DIR': '/run/user/{}'.format(uid),
57- 'DBUS_SESSION_BUS_ADDRESS':
58- 'unix:path=/run/user/{}/bus'.format(uid)
59- }
60- except CalledProcessError:
61- return {}
62+ uid = pwd.getpwnam(self._normal_user).pw_uid
63+ return {
64+ 'DISPLAY': self._set_envvar_from_proc('DISPLAY'),
65+ 'XAUTHORITY': self._set_envvar_from_proc('XAUTHORITY'),
66+ 'XDG_SESSION_TYPE': self._set_envvar_from_proc('XDG_SESSION_TYPE'),
67+ 'XDG_RUNTIME_DIR': '/run/user/{}'.format(uid),
68+ 'DBUS_SESSION_BUS_ADDRESS':
69+ 'unix:path=/run/user/{}/bus'.format(uid)
70+ }
71
72 def prepare_extra_env(self):
73 # If possible also set the DISPLAY env var
74@@ -257,6 +256,7 @@ class RemoteSessionAssistant():
75 return {
76 'DISPLAY': p_environ['DISPLAY'],
77 'XAUTHORITY': p_environ['XAUTHORITY'],
78+ 'XDG_SESSION_TYPE': p_environ['XDG_SESSION_TYPE'],
79 'XDG_RUNTIME_DIR': '/run/user/{}'.format(uid),
80 'DBUS_SESSION_BUS_ADDRESS':
81 'unix:path=/run/user/{}/bus'.format(uid)

Subscribers

People subscribed via source and target branches