On 14. 6. 2024 20:32, Jeremy Spewock wrote:
On Mon, Jun 10, 2024 at 3:37 PM Nicholas Pratte <[email protected]> wrote:

<snip>

-def load_config(config_file_path: Path) -> Configuration:
+def load_config(node_config_file_path: Path, exec_config_file_path: Path) -> 
Configuration:
      """Load DTS test run configuration from a file.

-    Load the YAML test run configuration file
+    Load both the YAML testbed and execution configuration files
      and :download:`the configuration file schema <conf_yaml_schema.json>`,
-    validate the test run configuration file, and create a test run 
configuration object.
+    validate both configuration files to create a test run configuration 
object.

      The YAML test run configuration file is specified in the 
:option:`--config-file` command line
      argument or the :envvar:`DTS_CFG_FILE` environment variable.

      Args:
-        config_file_path: The path to the YAML test run configuration file.
+        node_config_file_path: The path to the testbed configuration YAML file.
+        exec_config_file_path: The path to the execution configuration YAML 
file.

      Returns:
          The parsed test run configuration.
      """
-    with open(config_file_path, "r") as f:
-        config_data = yaml.safe_load(f)
+    with open(node_config_file_path, "r") as f:
+        node_config_data = yaml.safe_load(f)
+    with open(exec_config_file_path, "r") as f:
+        execution_config_data = yaml.safe_load(f)

      schema_path = os.path.join(Path(__file__).parent.resolve(), 
"conf_yaml_schema.json")

      with open(schema_path, "r") as f:
          schema = json.load(f)
-    config = warlock.model_factory(schema, name="_Config")(config_data)
-    config_obj: Configuration = Configuration.from_dict(dict(config))  # type: 
ignore[arg-type]
+    config = {
+        **dict(warlock.model_factory(schema, 
name="_Config")(node_config_data)),
+        **dict(warlock.model_factory(schema, 
name="_Config")(execution_config_data)),
+    }
+    if "nodes" not in config or "executions" not in config:
+        raise ConfigurationError(
+            f"{'node' if 'nodes' not in config else 'execution'} data not 
configured."
+        )
+    config_obj: Configuration = Configuration.from_dict(config)  # type: 
ignore[arg-type]
      return config_obj

There is an alternative approach to this that I currently have
implemented on a separate local branch. Essentially, both configs are
merged together before being validated by the schema, effectively
removing the need to change the schema at all as well as the above
assertion that both nodes and executions are in the two config files.
However, using this alternative method might mean that there is no added
control that prevents users from making funky errors when creating
both config files. I could also just be overthinking or missing
something.

That's an interesting idea and on one hand it makes the schema a
little less confusing because it wouldn't need to say "oneOf" when
both of the attributes are actually required for DTS to run, but on
the other it removes the ability for developers to know if they made a
mistake without actually running DTS. Making it a runtime error
wouldn't be the worst thing since it would at least be very early in
the run that the error is shown, but it loses some of its purpose I
feel if your IDE doesn't also show you some of the errors before
actually using the config. I could go either way on it personally.


Since we're splitting the file, we can also split the schema. I like splitting the schema since it'll be much clearer which files the schemas describe (if we have everything in one schema, we have to carefully look for which parts describe which file). It's also going to be easier to maintain.

Reply via email to