Merge ~sylvain-pineau/checkbox-ng:remote-hide-resource-and-attachment into checkbox-ng:master

Proposed by Sylvain Pineau
Status: Merged
Approved by: Sylvain Pineau
Approved revision: 6d54b3dcd7705c4a1fa6c7d8dec09165696dd131
Merged at revision: 3073bf4fc7e58b727b0e9c5dbef0b20b5b6ad089
Proposed branch: ~sylvain-pineau/checkbox-ng:remote-hide-resource-and-attachment
Merge into: checkbox-ng:master
Diff against target: 151 lines (+50/-10)
2 files modified
checkbox_ng/launcher/master.py (+6/-1)
plainbox/impl/session/remote_assistant.py (+44/-9)
Reviewer Review Type Date Requested Status
Maciej Kisielewski (community) Approve
Review via email: mp+381027@code.launchpad.net

Description of the change

Hide support for hide-resource-and-attachment for remote launchers

See commit for details.

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

LGTM, +1

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/master.py b/checkbox_ng/launcher/master.py
2index 9009266..1565b4a 100644
3--- a/checkbox_ng/launcher/master.py
4+++ b/checkbox_ng/launcher/master.py
5@@ -83,6 +83,9 @@ class SimpleUI(NormalUI, MainLoopStage):
6 def red_text(text, end='\n'):
7 print(SimpleUI.C.RED(text), end=end, file=sys.stderr)
8
9+ def black_text(text, end='\n'):
10+ print(SimpleUI.C.BLACK(text), end=end, file=sys.stdout)
11+
12 def horiz_line():
13 print(SimpleUI.C.WHITE('-' * 80))
14
15@@ -420,8 +423,10 @@ class RemoteMaster(ReportsStage, MainLoopStage):
16 for line in payload.splitlines():
17 if line.startswith('stderr'):
18 SimpleUI.red_text(line[6:])
19- else:
20+ elif line.startswith('stdout'):
21 SimpleUI.green_text(line[6:])
22+ else:
23+ SimpleUI.black_text(line[6:])
24 if state == 'running':
25 time.sleep(0.5)
26 while True:
27diff --git a/plainbox/impl/session/remote_assistant.py b/plainbox/impl/session/remote_assistant.py
28index 7185bb9..c93e7df 100644
29--- a/plainbox/impl/session/remote_assistant.py
30+++ b/plainbox/impl/session/remote_assistant.py
31@@ -74,13 +74,17 @@ class BufferedUI(SilentUI):
32 self.lock = Lock()
33 self._output = io.StringIO()
34
35+ def _ignore_program_output(self, stream_name, line):
36+ pass
37+
38 def got_program_output(self, stream_name, line):
39 with self.lock:
40 try:
41 self._output.write(stream_name + line.decode("UTF-8"))
42 except UnicodeDecodeError:
43 # Don't start a slave->master transfer for binary attachments
44- pass
45+ self._output.write("hidden(Hiding binary test output)\n")
46+ self.got_program_output = self._ignore_program_output
47
48 def get_output(self):
49 """Returns all the output queued up since previous call."""
50@@ -90,12 +94,26 @@ class BufferedUI(SilentUI):
51 return output
52
53
54+class RemoteSilentUI(SilentUI):
55+ """SilentUI + fake get_output."""
56+
57+ def __init__(self):
58+ super().__init__()
59+ self._msg = "hidden(Command output hidden)"
60+
61+ def get_output(self):
62+ msg = self._msg
63+ self._msg = ''
64+ return msg
65+
66+
67 class BackgroundExecutor(Thread):
68- def __init__(self, sa, job_id, real_run):
69+ def __init__(self, sa, job_id, real_run, ui=RemoteSilentUI()):
70 super().__init__()
71 self._sa = sa
72 self._job_id = job_id
73 self._real_run = real_run
74+ self._ui = ui
75 self._builder = None
76 self._started_real_run = False
77 self._sa.session_change_lock.acquire()
78@@ -111,8 +129,7 @@ class BackgroundExecutor(Thread):
79
80 def run(self):
81 self._started_real_run = True
82- self._builder = self._real_run(
83- self._job_id, self._sa.buffered_ui, False)
84+ self._builder = self._real_run(self._job_id, self._ui, False)
85 _logger.debug("Finished running")
86
87 def outcome(self):
88@@ -131,7 +148,7 @@ class RemoteSessionAssistant():
89 self._sudo_password = None
90 self._session_change_lock = Lock()
91 self._operator_lock = Lock()
92- self.buffered_ui = BufferedUI()
93+ self._ui = BufferedUI()
94 self._input_piping = os.pipe()
95 self._passwordless_sudo = is_passwordless_sudo()
96 self.terminate_cb = None
97@@ -316,6 +333,22 @@ class RemoteSessionAssistant():
98 self.session_change_lock.release()
99 self._state = TestsSelected
100
101+ def _get_ui_for_job(self, job):
102+ show_out = True
103+ if self._launcher.output == 'hide-resource-and-attachment':
104+ if job.plugin in ('local', 'resource', 'attachment'):
105+ show_out = False
106+ elif self._launcher.output in ['hide', 'hide-automated']:
107+ if job.plugin in ('shell', 'local', 'resource', 'attachment'):
108+ show_out = False
109+ if 'suppress-output' in job.get_flag_set():
110+ show_out = False
111+ if show_out:
112+ self._ui = BufferedUI()
113+ else:
114+ self._ui = RemoteSilentUI()
115+ return self._ui
116+
117 @allowed_when(TestsSelected)
118 def run_job(self, job_id):
119 """
120@@ -356,7 +389,8 @@ class RemoteSessionAssistant():
121 if self._current_comments != "":
122 result_builder.comments = self._current_comments
123 return result_builder
124- self._be = BackgroundExecutor(self, job_id, skipped_builder)
125+ self._be = BackgroundExecutor(
126+ self, job_id, skipped_builder)
127 yield from self.interact(
128 Interaction('skip', job.verification, self._be))
129 if job.command:
130@@ -376,7 +410,8 @@ class RemoteSessionAssistant():
131 print(_('Sorry, try again.'))
132 assert(self._sudo_password is not None)
133 self._state = Running
134- self._be = BackgroundExecutor(self, job_id, self._sa.run_job)
135+ ui = self._get_ui_for_job(job)
136+ self._be = BackgroundExecutor(self, job_id, self._sa.run_job, ui)
137 else:
138 def undecided_builder(*args, **kwargs):
139 return JobResultBuilder(outcome=IJobResult.OUTCOME_UNDECIDED)
140@@ -406,9 +441,9 @@ class RemoteSessionAssistant():
141 # either return [done, running, awaiting response]
142 # TODO: handle awaiting_response (reading from stdin by the job)
143 if self._be and self._be.is_alive():
144- return ('running', self.buffered_ui.get_output())
145+ return ('running', self._ui.get_output())
146 else:
147- return ('done', self.buffered_ui.get_output())
148+ return ('done', self._ui.get_output())
149
150 def get_remote_api_version(self):
151 return self.REMOTE_API_VERSION

Subscribers

People subscribed via source and target branches