Merge ~sylvain-pineau/checkbox-ng:no_psutil_xenial into checkbox-ng:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 2ef5e54c0c3b4afcdbdd305059f7d5162ba5c689
Merged at revision: 0047bc92718de117ec880c445f015776c76d995c
Proposed branch: ~sylvain-pineau/checkbox-ng:no_psutil_xenial
Merge into: checkbox-ng:master
Diff against target: 40 lines (+14/-1)
1 file modified
plainbox/impl/session/remote_assistant.py (+14/-1)
Reviewer Review Type Date Requested Status
Devices Certification Bot Needs Fixing
Maciej Kisielewski Approve
Taihsiang Ho Approve
Review via email: mp+375138@code.launchpad.net

Description of the change

Close your eyes and click approve...

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

tested on a remote xenial system with the following launcher:

[launcher]
app_id = com.canonical.certification:checkbox-test
launcher_version = 1
stock_reports = text, submission_files

[test plan]
unit = com.canonical.certification::graphics-integrated-gpu-cert-manual
forced = yes

[daemon]
normal_user = u

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

One change I would like to see is making the distinction on "startup" and selecting the appropriate function for future use, like so:

# global scope

try:
    import psutil
    if psutil.__version__ < (...):
        throw Something()
    prep_display = _prep_disp_using_psutil
except ( ImportError, Someting):
    prep_display = _prep_disp_using_proc

This way we don't go deep into psutil use exception as a code flow.

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

setting the display must be done when starting/resuming the session not when the service starts (i.e at import time)

Revision history for this message
Taihsiang Ho (tai271828) wrote :

The merge request is good to me, though I love Maciej's idea as well. Thanks for the quick fix.

review: Approve
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Right. But I would still prefer for this not to be run every time the DISPLAY value is needed.
Also, I think _prepare_display_without_psutil can be made non-member (doesn't use self)

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

checking psutil.__version__ would require a version comparison import such as distutils since the req is 4.0.0. I don't think it worths the effort and catching the AttributeError is probably a good compromise. Keep in mind that this DISPLAY madness is just a one-time operation (session start or session resume).

Regarding member vs non-member, let's say that I prefer to hide it from globals...

Revision history for this message
Maciej Kisielewski (kissiel) wrote :

Mmm, indeed. It's called once per stack bring-up, great!

I disagree on the placement of both DISPLAY-getting functions, but not to a point where I would block this from landing.

+1

review: Approve
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

[xenial] [13:29:39] starting container
Device project added to xenial-testing
[bionic] [13:29:40] starting container
Device project added to bionic-testing
[xenial] [13:29:47] provisioning container
[bionic] [13:29:53] provisioning container
[bionic] [13:31:12] Unable to provision requirements in container!
[bionic] output: https://paste.ubuntu.com/p/dmCDq64Rnq/
[bionic] [13:31:15] Fixing file permissions in source directory
[bionic] Destroying failed container to reclaim resources
[xenial] [13:31:47] Unable to provision requirements in container!
[xenial] output: https://paste.ubuntu.com/p/QVPX8VvHxB/
[xenial] [13:31:49] Fixing file permissions in source directory
[xenial] Destroying failed container to reclaim resources

review: Needs Fixing
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :

The merge was fine but running tests failed.

[xenial] [13:42:04] starting container
Device project added to xenial-testing
[bionic] [13:42:06] starting container
Device project added to bionic-testing
[xenial] [13:42:13] provisioning container
[bionic] [13:42:18] provisioning container
[bionic] [13:43:38] Unable to provision requirements in container!
[bionic] output: https://paste.ubuntu.com/p/JyJgBDSNmM/
[bionic] [13:43:41] Fixing file permissions in source directory
[bionic] Destroying failed container to reclaim resources
[xenial] [13:45:53] Unable to provision requirements in container!
[xenial] output: https://paste.ubuntu.com/p/8fvRfJT2Q7/
[xenial] [13:45:56] Fixing file permissions in source directory
[xenial] Destroying failed container to reclaim resources

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/plainbox/impl/session/remote_assistant.py b/plainbox/impl/session/remote_assistant.py
index 326f81f..907bce2 100644
--- a/plainbox/impl/session/remote_assistant.py
+++ b/plainbox/impl/session/remote_assistant.py
@@ -25,7 +25,7 @@ import time
25import sys25import sys
26from collections import namedtuple26from collections import namedtuple
27from threading import Thread, Lock27from threading import Thread, Lock
28from subprocess import DEVNULL, CalledProcessError, check_call28from subprocess import DEVNULL, CalledProcessError, check_call, check_output
2929
30from plainbox.impl.execution import UnifiedRunner30from plainbox.impl.execution import UnifiedRunner
31from plainbox.impl.session.assistant import SessionAssistant31from plainbox.impl.session.assistant import SessionAssistant
@@ -186,6 +186,16 @@ class RemoteSessionAssistant():
186 self._last_response = response186 self._last_response = response
187 self._state = Running187 self._state = Running
188188
189 def _prepare_display_without_psutil(self):
190 try:
191 value = check_output(
192 'strings /proc/*/environ 2>/dev/null | '
193 'grep -m 1 -oP "(?<=DISPLAY=).*"',
194 shell=True, universal_newlines=True).rstrip()
195 return {'DISPLAY': value}
196 except CalledProcessError:
197 return None
198
189 def prepare_extra_env(self):199 def prepare_extra_env(self):
190 # If possible also set the DISPLAY env var200 # If possible also set the DISPLAY env var
191 # i.e when a user desktop session is running201 # i.e when a user desktop session is running
@@ -195,6 +205,9 @@ class RemoteSessionAssistant():
195 p_user = psutil.Process(p).username()205 p_user = psutil.Process(p).username()
196 except psutil.AccessDenied:206 except psutil.AccessDenied:
197 continue207 continue
208 except AttributeError:
209 # psutil < 4.0.0 doesn't provide Process.environ()
210 return self._prepare_display_without_psutil()
198 if ("DISPLAY" in p_environ and p_user != 'gdm'): # gdm uses :1024211 if ("DISPLAY" in p_environ and p_user != 'gdm'): # gdm uses :1024
199 return {'DISPLAY': p_environ['DISPLAY']}212 return {'DISPLAY': p_environ['DISPLAY']}
200 break213 break

Subscribers

People subscribed via source and target branches