opentf-toolkit-nightly 0.58.0.dev1152__py3-none-any.whl → 0.58.0.dev1159__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2021 Henix, Henix.fr
1
+ # Copyright (c) 2021-2024 Henix, Henix.fr
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -23,13 +23,19 @@ import ntpath
23
23
  import os
24
24
  import re
25
25
 
26
- from opentf.commons import EXECUTIONRESULT, make_event, make_uuid
26
+ from opentf.commons import (
27
+ EXECUTIONRESULT,
28
+ WORKFLOWRESULT,
29
+ make_event,
30
+ make_uuid,
31
+ )
27
32
  from opentf.toolkit import core
28
33
 
29
34
  ## workflow commands
30
35
 
31
36
  SETOUTPUT_COMMAND = re.compile(r'^::set-output\s+name=([a-zA-Z_][a-zA-Z0-9_-]*)::(.*)$')
32
37
  ATTACH_COMMAND = re.compile(r'^::attach(\s+.*?)?::(.*?)\s*$')
38
+ UPLOAD_COMMAND = re.compile(r'^::upload(\s+.*?)?::(.*?)\s*$')
33
39
  DEBUG_COMMAND = re.compile(r'^::debug::(.*)$')
34
40
  WARNING_COMMAND = re.compile(r'^::warning(\s+(.*)+)?::(.*)$')
35
41
  ERROR_COMMAND = re.compile(r'^::error(\s+(.*)+)?::(.*)$')
@@ -174,10 +180,12 @@ def _add_default_variables(
174
180
 
175
181
 
176
182
  def _make_attachment_url(
177
- metadata: Dict[str, Any], remote: str, separator: str
183
+ metadata: Dict[str, Any], remote: str, separator: str, workflow_result: bool = False
178
184
  ) -> Tuple[str, Dict[str, Any]]:
179
185
  uuid = make_uuid()
180
- url = f'/tmp/{metadata["job_id"]}-{uuid}_{metadata["step_sequence_id"]}_{remote.split(separator)[-1]}'
186
+ prefix = metadata['workflow_id'] if workflow_result else metadata['job_id']
187
+ suffix = 'WR' if workflow_result else metadata['step_sequence_id']
188
+ url = f'/tmp/{prefix}-{uuid}_{suffix}_{remote.split(separator)[-1]}'
181
189
  return url, {'uuid': uuid}
182
190
 
183
191
 
@@ -207,6 +215,43 @@ def _as_log(line: str, jobstate: JobState):
207
215
  return mask(line, jobstate).rstrip()
208
216
 
209
217
 
218
+ def process_upload(result: Dict[str, Any]):
219
+ """Process ExecutionResult event containing .metadata.upload flag.
220
+
221
+ Dispatch attachments between ExecutionResult and WorkflowResult events,
222
+ publish WorkflowResult.
223
+ """
224
+
225
+ def _filter_items(key: str):
226
+ metadata = {}
227
+ items = [item for item in result['attachments'] if item[pos:].startswith(key)]
228
+ if items:
229
+ metadata = {
230
+ k: v for k, v in result['metadata']['attachments'].items() if k in items
231
+ }
232
+ return items, metadata
233
+
234
+ del result['metadata']['upload']
235
+ pos = len('/tmp/')
236
+ upload, upload_metadata = _filter_items(result['metadata']['workflow_id'])
237
+ attach, attach_metadata = _filter_items(result['metadata']['job_id'])
238
+
239
+ if attach:
240
+ result['attachments'] = attach
241
+ result['metadata']['attachments'] = attach_metadata
242
+ else:
243
+ del result['attachments']
244
+ del result['metadata']['attachments']
245
+
246
+ metadata = {
247
+ 'attachments': upload_metadata,
248
+ 'name': result['metadata'].get('step_id'),
249
+ 'namespace': result['metadata']['namespace'],
250
+ 'workflow_id': result['metadata']['workflow_id'],
251
+ }
252
+ return make_event(WORKFLOWRESULT, metadata=metadata, attachments=upload)
253
+
254
+
210
255
  def process_output(
211
256
  event: Dict[str, Any],
212
257
  resp: int,
@@ -225,6 +270,7 @@ def process_output(
225
270
  - stdout: a list of strings
226
271
  - stderr: a list of strings
227
272
  - jobstate: a JobState object
273
+ - context: a dictionary, channelhandler context
228
274
  - attach: a function copying a remote file to a local path
229
275
  - put: a function copying a local file to a remote environment
230
276
 
@@ -253,7 +299,9 @@ def process_output(
253
299
  if is_windows:
254
300
  remote = ntpath.normpath(remote)
255
301
  try:
256
- attachment_url, details = _make_attachment_url(metadata, remote, separator)
302
+ attachment_url, details = _make_attachment_url(
303
+ metadata, remote, separator, upload
304
+ )
257
305
  if args:
258
306
  for parameter in args.strip().split(','):
259
307
  if '=' not in parameter:
@@ -299,6 +347,7 @@ def process_output(
299
347
  attachments: List[str] = []
300
348
  attachments_metadata = {}
301
349
 
350
+ upload = False
302
351
  for line in stdout:
303
352
  # Parsing stdout for workflow commands
304
353
  if jobstate.stop_command:
@@ -308,6 +357,9 @@ def process_output(
308
357
 
309
358
  if wcmd := ATTACH_COMMAND.match(line):
310
359
  resp = _attach(wcmd.group(2), wcmd.group(1))
360
+ elif wcmd := UPLOAD_COMMAND.match(line):
361
+ upload = True
362
+ resp = _attach(wcmd.group(2), wcmd.group(1))
311
363
  elif wcmd := PUT_FILE_COMMAND.match(line):
312
364
  resp = _putfile(wcmd.group(2), wcmd.group(1))
313
365
  elif wcmd := SETOUTPUT_COMMAND.match(line):
@@ -323,6 +375,7 @@ def process_output(
323
375
  logs.append(mask(line, jobstate).rstrip())
324
376
 
325
377
  result = make_event(EXECUTIONRESULT, metadata=metadata, status=resp)
378
+
326
379
  if outputs:
327
380
  result['outputs'] = outputs
328
381
  if logs:
@@ -330,7 +383,8 @@ def process_output(
330
383
  if attachments:
331
384
  result['attachments'] = attachments
332
385
  result['metadata']['attachments'] = attachments_metadata
333
-
386
+ if upload:
387
+ result['metadata']['upload'] = resp
334
388
  return result
335
389
 
336
390
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentf-toolkit-nightly
3
- Version: 0.58.0.dev1152
3
+ Version: 0.58.0.dev1159
4
4
  Summary: OpenTestFactory Orchestrator Toolkit
5
5
  Home-page: https://gitlab.com/henixdevelopment/open-source/opentestfactory/python-toolkit
6
6
  Author: Martin Lafaix
@@ -55,10 +55,10 @@ opentf/schemas/opentestfactory.org/v1beta2/ServiceConfig.json,sha256=rEvK2YWL5lG
55
55
  opentf/scripts/launch_java_service.sh,sha256=S0jAaCuv2sZy0Gf2NGBuPX-eD531rcM-b0fNyhmzSjw,2423
56
56
  opentf/scripts/startup.py,sha256=c5fhYUy_Nk6z-eo0kW0mG56452dcIw9mzb9trljZYZ4,21453
57
57
  opentf/toolkit/__init__.py,sha256=mYeJPZ92ulbTBItqEsZgF4nnuRh6G19QPY3Jxc92ifc,23028
58
- opentf/toolkit/channels.py,sha256=6xcVKHUK2FdyVKIQmPQbakngfVuQDzCcD_lInOdKpro,17171
58
+ opentf/toolkit/channels.py,sha256=bAUo0FRNljkjgTkWqSJljsNeMSX21LLLZP-TS4cw1oo,18996
59
59
  opentf/toolkit/core.py,sha256=6nud1vqcfjs9swZu_Z-rbvdbejtrlSjOd8eZXIF0ChE,9795
60
- opentf_toolkit_nightly-0.58.0.dev1152.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
61
- opentf_toolkit_nightly-0.58.0.dev1152.dist-info/METADATA,sha256=Grat47-RomgGC_3UgANOXeGfrKWCNLp_9pNSHvF6PTk,1940
62
- opentf_toolkit_nightly-0.58.0.dev1152.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
63
- opentf_toolkit_nightly-0.58.0.dev1152.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
64
- opentf_toolkit_nightly-0.58.0.dev1152.dist-info/RECORD,,
60
+ opentf_toolkit_nightly-0.58.0.dev1159.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
61
+ opentf_toolkit_nightly-0.58.0.dev1159.dist-info/METADATA,sha256=lSM8fNhAWfNcilR8k_1NoQdtn6kuSQrrksoRdn3D9w0,1940
62
+ opentf_toolkit_nightly-0.58.0.dev1159.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
63
+ opentf_toolkit_nightly-0.58.0.dev1159.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
64
+ opentf_toolkit_nightly-0.58.0.dev1159.dist-info/RECORD,,