|
1 | | -import json |
2 | 1 | import os |
3 | 2 |
|
4 | 3 | from metaflow import ( |
|
28 | 27 | } |
29 | 28 |
|
30 | 29 |
|
31 | | -def find_param_in_parameters(parameters, name): |
32 | | - for param in parameters: |
33 | | - splits = param.split(" ") |
34 | | - try: |
35 | | - idx = splits.index("--" + name) |
36 | | - return splits[idx + 1] |
37 | | - except ValueError: |
38 | | - continue |
39 | | - return None |
40 | | - |
41 | | - |
42 | | -def audit(run, parameters, configs, stdout_path): |
43 | | - # We should only have one run here |
44 | | - if len(run) != 1: |
45 | | - raise RuntimeError("Expected only one run; got %d" % len(run)) |
46 | | - run = run[0] |
47 | | - |
48 | | - # Check successful run |
49 | | - if not run.successful: |
50 | | - raise RuntimeError("Run was not successful") |
51 | | - |
52 | | - if configs: |
53 | | - # We should have one config called "config" |
54 | | - if len(configs) != 1 or not configs.get("config"): |
55 | | - raise RuntimeError("Expected one config called 'config'") |
56 | | - config = json.loads(configs["config"]) |
57 | | - else: |
58 | | - config = default_config |
59 | | - |
60 | | - if len(parameters) > 1: |
61 | | - expected_tokens = parameters[-1].split() |
62 | | - if len(expected_tokens) < 8: |
63 | | - raise RuntimeError("Unexpected parameter list: %s" % str(expected_tokens)) |
64 | | - expected_token = expected_tokens[7] |
65 | | - else: |
66 | | - expected_token = "" |
67 | | - |
68 | | - # Check that we have the proper project name |
69 | | - if f"project:{config['project_name']}" not in run.tags: |
70 | | - raise RuntimeError("Project name is incorrect.") |
71 | | - |
72 | | - # Check the start step that all values are properly set. We don't need |
73 | | - # to check end step as it would be a duplicate |
74 | | - start_task_data = run["start"].task.data |
75 | | - |
76 | | - assert start_task_data.trigger_param == expected_token |
77 | | - for param in config["parameters"]: |
78 | | - value = find_param_in_parameters(parameters, param["name"]) or param["default"] |
79 | | - if not hasattr(start_task_data, param["name"]): |
80 | | - raise RuntimeError(f"Missing parameter {param['name']}") |
81 | | - if getattr(start_task_data, param["name"]) != value: |
82 | | - raise RuntimeError( |
83 | | - f"Parameter {param['name']} has incorrect value %s versus %s expected" |
84 | | - % (getattr(start_task_data, param["name"]), value) |
85 | | - ) |
86 | | - assert ( |
87 | | - start_task_data.flow_level |
88 | | - == config["flow_add_environment"]["vars"]["FLOW_LEVEL"] |
89 | | - ) |
90 | | - assert ( |
91 | | - start_task_data.step_level |
92 | | - == config["step_add_environment"]["vars"]["STEP_LEVEL"] |
93 | | - ) |
94 | | - assert ( |
95 | | - start_task_data.step_level_2 |
96 | | - == config["step_add_environment_2"]["vars"]["STEP_LEVEL_2"] |
97 | | - ) |
98 | | - |
99 | | - return None |
100 | | - |
101 | | - |
102 | 30 | class ModifyFlow(FlowMutator): |
103 | 31 | def mutate(self, mutable_flow): |
104 | 32 | steps = ["start", "end"] |
|
0 commit comments