opentf-toolkit-nightly 0.59.0.dev1188__py3-none-any.whl → 0.59.0.dev1204__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.
@@ -68,6 +68,7 @@ REASON_STATUS = {
68
68
  'Created': 201,
69
69
  'Accepted': 202,
70
70
  'NoContent': 204,
71
+ 'PartialContent': 206,
71
72
  'BadRequest': 400,
72
73
  'Unauthorized': 401,
73
74
  'PaymentRequired': 402,
@@ -75,6 +76,7 @@ REASON_STATUS = {
75
76
  'NotFound': 404,
76
77
  'AlreadyExists': 409,
77
78
  'Conflict': 409,
79
+ 'RangeNotSatisfiable': 416,
78
80
  'Invalid': 422,
79
81
  'TooManyRequests': 429, # https://datatracker.ietf.org/doc/html/rfc6585
80
82
  'InternalError': 500,
@@ -0,0 +1,116 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2019-09/schema#",
3
+ "title": "JSON SCHEMA for opentestfactory.org/v1 ExecutionResult manifests",
4
+ "type": "object",
5
+ "properties": {
6
+ "apiVersion": {
7
+ "const": "opentestfactory.org/v1"
8
+ },
9
+ "kind": {
10
+ "const": "ExecutionResult"
11
+ },
12
+ "metadata": {
13
+ "type": "object",
14
+ "properties": {
15
+ "name": {
16
+ "type": "string"
17
+ },
18
+ "workflow_id": {
19
+ "type": "string"
20
+ },
21
+ "job_id": {
22
+ "type": "string"
23
+ },
24
+ "job_origin": {
25
+ "type": "array",
26
+ "items": {
27
+ "type": "string"
28
+ }
29
+ },
30
+ "step_id": {
31
+ "type": "string"
32
+ },
33
+ "step_origin": {
34
+ "type": "array",
35
+ "items": {
36
+ "type": "string"
37
+ }
38
+ },
39
+ "step_origin_status": {
40
+ "type": "object",
41
+ "patternProperties": {
42
+ "^[a-zA-Z0-9-]+$": {
43
+ "type": "number"
44
+ }
45
+ }
46
+ },
47
+ "step_sequence_id": {
48
+ "type": "number"
49
+ },
50
+ "labels": {
51
+ "type": "object",
52
+ "patternProperties": {
53
+ "^([a-zA-Z0-9-.]+/)?[a-zA-Z0-9]([a-zA-Z0-9._-]*[a-zA-Z0-9])?$": {
54
+ "type": "string"
55
+ }
56
+ },
57
+ "minProperties": 1,
58
+ "additionalProperties": false
59
+ },
60
+ "attachments": {
61
+ "type": "object",
62
+ "minProperties": 1
63
+ }
64
+ },
65
+ "additionalProperties": true,
66
+ "required": [
67
+ "name",
68
+ "workflow_id",
69
+ "job_id",
70
+ "step_id",
71
+ "step_sequence_id"
72
+ ]
73
+ },
74
+ "attachments": {
75
+ "type": "array",
76
+ "items": {
77
+ "type": "string"
78
+ },
79
+ "minItems": 1
80
+ },
81
+ "outputs": {
82
+ "type": "object",
83
+ "patternProperties": {
84
+ "^[a-zA-Z_][a-zA-Z0-9_-]+$": {
85
+ "type": "string"
86
+ }
87
+ },
88
+ "minProperties": 1,
89
+ "additionalProperties": false
90
+ },
91
+ "logs": {
92
+ "type": "array",
93
+ "items": {
94
+ "type": "string"
95
+ }
96
+ },
97
+ "status": {
98
+ "type": "number"
99
+ },
100
+ "variables": {
101
+ "type": "object",
102
+ "patternProperties": {
103
+ "^[a-zA-Z0-9_]+$": {
104
+ "type": "string"
105
+ }
106
+ },
107
+ "minProperties": 1
108
+ }
109
+ },
110
+ "required": [
111
+ "apiVersion",
112
+ "kind",
113
+ "metadata"
114
+ ],
115
+ "additionalProperties": false
116
+ }
@@ -96,6 +96,15 @@
96
96
  },
97
97
  "status": {
98
98
  "type": "number"
99
+ },
100
+ "variables": {
101
+ "type": "object",
102
+ "patternProperties": {
103
+ "^[a-zA-Z0-9_]+$": {
104
+ "type": "string"
105
+ }
106
+ },
107
+ "minProperties": 1
99
108
  }
100
109
  },
101
110
  "required": [
@@ -128,6 +128,10 @@ MOVE_TO_WORKSPACE = 3
128
128
 
129
129
  HOOKS_ANNOTATIONS = 'opentestfactory.org/hooks'
130
130
 
131
+ OPENTF_VARIABLES_TYPE = 'application/vnd.opentestfactory.opentf-variables'
132
+ OPENTF_VARIABLES_REGEX = re.compile(r'^(export|set)\s(\"?.+)$')
133
+ OPENTF_VARIABLES_NAME_REGEX = re.compile(r'^[a-zA-Z0-9_]+$')
134
+
131
135
  ## os helpers
132
136
 
133
137
 
@@ -219,6 +223,43 @@ def _as_log(line: str, jobstate: JobState):
219
223
  return mask(line, jobstate).rstrip()
220
224
 
221
225
 
226
+ def _get_opentf_variables(path: str) -> Dict[str, str]:
227
+ variables = {}
228
+ with open(path, 'r') as f:
229
+ for line in f.readlines():
230
+ if '=' not in line:
231
+ continue
232
+ line = line.strip()
233
+ if set_export := OPENTF_VARIABLES_REGEX.match(line):
234
+ line = set_export.group(2)
235
+ if line.startswith('"'):
236
+ line = line[1:-1]
237
+ key, _, value = line.partition('=')
238
+ if OPENTF_VARIABLES_NAME_REGEX.match(key):
239
+ variables[key] = value
240
+ return variables
241
+
242
+
243
+ def process_opentf_variables(result: Dict[str, Any]) -> None:
244
+ """Process OPENTF_VARIABLES attachment if available.
245
+
246
+ If OPENTF_VARIABLES is in the attachments, move its content to
247
+ the variables field of the result.
248
+ """
249
+ if attachments := result['metadata'].get('attachments'):
250
+ variables = {}
251
+ for path, data in attachments.copy().items():
252
+ if data.get('type') == OPENTF_VARIABLES_TYPE:
253
+ variables = _get_opentf_variables(path)
254
+ del result['metadata']['attachments'][path]
255
+ result['attachments'].remove(path)
256
+ if not result['metadata']['attachments']:
257
+ del result['metadata']['attachments']
258
+ if not result['attachments']:
259
+ del result['attachments']
260
+ result['variables'] = variables
261
+
262
+
222
263
  def process_upload(result: Dict[str, Any]):
223
264
  """Process ExecutionResult event containing .metadata.upload flag.
224
265
 
@@ -275,8 +316,8 @@ def process_output(
275
316
  - stderr: a list of strings
276
317
  - jobstate: a JobState object
277
318
  - context: a dictionary, channelhandler context
278
- - attach: a function copying a remote file to a local path
279
- - put: a function copying a local file to a remote environment
319
+ - _get: a function copying a remote file to a local path
320
+ - _put: a function copying a local file to a remote environment
280
321
 
281
322
  # Returned value
282
323
 
@@ -394,6 +435,17 @@ def process_output(
394
435
  return result
395
436
 
396
437
 
438
+ def _attach_opentf_variables(runner_os: str, script: List[str]):
439
+ if runner_os == 'windows':
440
+ script.append(
441
+ f'@if exist "%OPENTF_VARIABLES%" echo ::attach type={OPENTF_VARIABLES_TYPE}::%OPENTF_VARIABLES%'
442
+ )
443
+ else:
444
+ script.append(
445
+ f'if [ -f "$OPENTF_VARIABLES" ]; then echo "::attach type={OPENTF_VARIABLES_TYPE}::"$OPENTF_VARIABLES""; fi'
446
+ )
447
+
448
+
397
449
  def _export_opentf_workspace(runner_os: str, workspace: str, script: List[str]) -> None:
398
450
  opentf_workspace = WORKSPACE_TEMPLATE[runner_os].format(workspace=workspace)
399
451
  if runner_os == 'windows':
@@ -465,10 +517,18 @@ def _make_prolog(
465
517
  script: List[str],
466
518
  command: Dict[str, Any],
467
519
  ) -> None:
520
+ local_variables_names = (
521
+ command['metadata'].get('annotations', {}).get('local_variables_names', [])
522
+ )
468
523
  for name, value in command.get('variables', {}).items():
469
- script.append(VARIABLE_MAKER[runner_os](name, value))
524
+ if name not in local_variables_names:
525
+ script.append(VARIABLE_MAKER[runner_os](name, value))
470
526
 
471
527
  script.append(PROLOG_SCRIPTS[runner_os][LOAD_VARIABLES])
528
+ for name, value in command.get('variables', {}).items():
529
+ if name in local_variables_names:
530
+ script.append(VARIABLE_MAKER[runner_os](name, value))
531
+
472
532
  if step_sequence_id == CHANNEL_RELEASE:
473
533
  # on windows, the script ends if it is removed, so script
474
534
  # removal should be the last operation
@@ -570,6 +630,7 @@ def make_script(
570
630
  _maybe_create_workspace(metadata, runner_os, step_sequence_id, script)
571
631
  _make_prolog(runner_os, job_id, step_sequence_id, root, script, command)
572
632
  _maybe_change_directory(command, runner_os, script, prefix)
633
+ _attach_opentf_variables(runner_os, script)
573
634
 
574
635
  if command.get('shell') in (None, SHELL_DEFAULT[runner_os]):
575
636
  script += command['scripts']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: opentf-toolkit-nightly
3
- Version: 0.59.0.dev1188
3
+ Version: 0.59.0.dev1204
4
4
  Summary: OpenTestFactory Orchestrator Toolkit
5
5
  Home-page: https://gitlab.com/henixdevelopment/open-source/opentestfactory/python-toolkit
6
6
  Author: Martin Lafaix
@@ -1,4 +1,4 @@
1
- opentf/commons/__init__.py,sha256=JYQXTyvKTcU2Blu6AUzR0FfEHSqSUrqldqLDpSf_K_k,22520
1
+ opentf/commons/__init__.py,sha256=JLif958eOnOeJSQ6bLF-Dpr_aFJ3JtxHrjvUe_KbzEc,22579
2
2
  opentf/commons/auth.py,sha256=bM2Z3kxm2Wku1lKXaRAIg37LHvXWAXIZIqjplDfN2P8,15899
3
3
  opentf/commons/config.py,sha256=dyus4K5Zdmcftc3Y9Z1YRkzA1KwiRLHoeAlg2_A49QM,7876
4
4
  opentf/commons/datasources.py,sha256=GSbjrYnZQup2B3r7T7l3C_o6R2jS13nQiu6dRitoenk,26194
@@ -9,6 +9,7 @@ opentf/commons/selectors.py,sha256=DEpLgRAr5HXSpSYI4liXP2hLUTvOSexFa9Vfa1xIQTk,7
9
9
  opentf/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  opentf/schemas/abac.opentestfactory.org/v1alpha1/Policy.json,sha256=JXsfNAPSEYggeyaDutSQBeG38o4Bmcr70dPLWWeqIh8,2105
11
11
  opentf/schemas/opentestfactory.org/v1/ExecutionCommand.json,sha256=UtmAlTaYdPSZDeQnx-ocX8IonyEPWoNmgDkHwQwQxWE,4126
12
+ opentf/schemas/opentestfactory.org/v1/ExecutionResult.json,sha256=u0n-WYXNX9d0cEyu2D4tegU35k2Gf3eA6PGs9Uz4QDg,3275
12
13
  opentf/schemas/opentestfactory.org/v1/GeneratorResult.json,sha256=sOwieyDWi6UZR7X29R9IjOR87ruSRQ4U6CM2_yT81Zk,16607
13
14
  opentf/schemas/opentestfactory.org/v1/ProviderCommand.json,sha256=EU4kvEKxlqpH2IkLZ1HdBealuG6C0YzPkAtI7dNrfHg,4427
14
15
  opentf/schemas/opentestfactory.org/v1/ProviderResult.json,sha256=Ej4zhCE3rCqCGKcaeAoIHwSJTV_7fw-rAxhJ52qA-Gs,9641
@@ -23,7 +24,7 @@ opentf/schemas/opentestfactory.org/v1alpha1/ChannelHandlerHooks.json,sha256=6K6m
23
24
  opentf/schemas/opentestfactory.org/v1alpha1/EventBusConfig.json,sha256=2aIYtA07qRoauKNy-MH25Kzg1l1Q1fjY9_4YIvlyYgw,2174
24
25
  opentf/schemas/opentestfactory.org/v1alpha1/ExecutionCommand.json,sha256=Tsqy0imNqO6Qg6B_Yw-4OeNer3xpURv-ZDaYUoZ-l1c,2702
25
26
  opentf/schemas/opentestfactory.org/v1alpha1/ExecutionError.json,sha256=tz8ZggvjSkP2S9ln77Js03LkTnMCTuRVkC1Z3w8uI8k,1347
26
- opentf/schemas/opentestfactory.org/v1alpha1/ExecutionResult.json,sha256=aF9PbJADupP_m_TfNRqpeayi1_nCj5Ll2_vDCcJWMkY,3050
27
+ opentf/schemas/opentestfactory.org/v1alpha1/ExecutionResult.json,sha256=UeWc4TfRY3G1CnMapFxXWRunaXzZdxOIle3DxURSf-A,3287
27
28
  opentf/schemas/opentestfactory.org/v1alpha1/GeneratorCommand.json,sha256=uxbqDhP4newgz-85TnGKbchx448QEQ8WB5PXpcJy2ME,1754
28
29
  opentf/schemas/opentestfactory.org/v1alpha1/GeneratorResult.json,sha256=LkHLGt2uam1Q5Ux0zP_O9oFgxBMCjD3Th3BsfsXxd1g,6633
29
30
  opentf/schemas/opentestfactory.org/v1alpha1/InsightCollector.json,sha256=emE0My2cYBRnfA8L3_eY8yOXbSErV4TlwmQbRCgT4O8,16770
@@ -55,10 +56,10 @@ opentf/schemas/opentestfactory.org/v1beta2/ServiceConfig.json,sha256=rEvK2YWL5lG
55
56
  opentf/scripts/launch_java_service.sh,sha256=S0jAaCuv2sZy0Gf2NGBuPX-eD531rcM-b0fNyhmzSjw,2423
56
57
  opentf/scripts/startup.py,sha256=sggwEpMx7PTaSgYzs-2uCF5YZzpsncMyTlfF_G60CrE,21518
57
58
  opentf/toolkit/__init__.py,sha256=mYeJPZ92ulbTBItqEsZgF4nnuRh6G19QPY3Jxc92ifc,23028
58
- opentf/toolkit/channels.py,sha256=DUP3tBSp7sjq49SwglobG92MO2zX0vdiHGYx0ms30yA,19182
59
+ opentf/toolkit/channels.py,sha256=2t33EAenmkCJj6Tc4QO-LZDz-nztvsj2I9usqDlNXco,21603
59
60
  opentf/toolkit/core.py,sha256=cscUkwdwvLkerqMRL05dgtKJ42QbBQQc28kRBiyZM9o,9883
60
- opentf_toolkit_nightly-0.59.0.dev1188.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
61
- opentf_toolkit_nightly-0.59.0.dev1188.dist-info/METADATA,sha256=wCEqDnUU3H8feYLwG7l-pNY3pDtb_tRyItBXs2khRpo,1940
62
- opentf_toolkit_nightly-0.59.0.dev1188.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
63
- opentf_toolkit_nightly-0.59.0.dev1188.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
64
- opentf_toolkit_nightly-0.59.0.dev1188.dist-info/RECORD,,
61
+ opentf_toolkit_nightly-0.59.0.dev1204.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
62
+ opentf_toolkit_nightly-0.59.0.dev1204.dist-info/METADATA,sha256=K-yDvUZOfq-_b5kb4uNqbLervQNJXcr_SKeYHUDsbXA,1940
63
+ opentf_toolkit_nightly-0.59.0.dev1204.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
64
+ opentf_toolkit_nightly-0.59.0.dev1204.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
65
+ opentf_toolkit_nightly-0.59.0.dev1204.dist-info/RECORD,,