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
1diff --git a/plainbox/impl/session/remote_assistant.py b/plainbox/impl/session/remote_assistant.py
2index 326f81f..907bce2 100644
3--- a/plainbox/impl/session/remote_assistant.py
4+++ b/plainbox/impl/session/remote_assistant.py
5@@ -25,7 +25,7 @@ import time
6 import sys
7 from collections import namedtuple
8 from threading import Thread, Lock
9-from subprocess import DEVNULL, CalledProcessError, check_call
10+from subprocess import DEVNULL, CalledProcessError, check_call, check_output
11
12 from plainbox.impl.execution import UnifiedRunner
13 from plainbox.impl.session.assistant import SessionAssistant
14@@ -186,6 +186,16 @@ class RemoteSessionAssistant():
15 self._last_response = response
16 self._state = Running
17
18+ def _prepare_display_without_psutil(self):
19+ try:
20+ value = check_output(
21+ 'strings /proc/*/environ 2>/dev/null | '
22+ 'grep -m 1 -oP "(?<=DISPLAY=).*"',
23+ shell=True, universal_newlines=True).rstrip()
24+ return {'DISPLAY': value}
25+ except CalledProcessError:
26+ return None
27+
28 def prepare_extra_env(self):
29 # If possible also set the DISPLAY env var
30 # i.e when a user desktop session is running
31@@ -195,6 +205,9 @@ class RemoteSessionAssistant():
32 p_user = psutil.Process(p).username()
33 except psutil.AccessDenied:
34 continue
35+ except AttributeError:
36+ # psutil < 4.0.0 doesn't provide Process.environ()
37+ return self._prepare_display_without_psutil()
38 if ("DISPLAY" in p_environ and p_user != 'gdm'): # gdm uses :1024
39 return {'DISPLAY': p_environ['DISPLAY']}
40 break

Subscribers

People subscribed via source and target branches