From ac317a517ba79ab1063891116298c377fd24d10a Mon Sep 17 00:00:00 2001 From: Stewart Williams <3161869-bravostuzero@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 14:54:08 +0100 Subject: [PATCH 1/6] AT1-905 bugfix: MID schemas were registered under SKA LOW prefix --- src/ska_telmodel/schema.py | 20 ++- src/ska_telmodel/tmc/examples.py | 42 +++--- src/ska_telmodel/tmc/schema.py | 21 ++- src/ska_telmodel/tmc/version.py | 31 ++-- tests/test_tmc_schemas.py | 239 ++++++++++++++++--------------- 5 files changed, 191 insertions(+), 162 deletions(-) diff --git a/src/ska_telmodel/schema.py b/src/ska_telmodel/schema.py index 18b1088f..f3efc73d 100644 --- a/src/ska_telmodel/schema.py +++ b/src/ska_telmodel/schema.py @@ -1,12 +1,12 @@ import logging -from schema import Schema, Literal, Optional, And, Or -from typing import Callable, Any -from schema import SchemaError +from typing import Callable + +from schema import Schema, Literal, Optional, And, Or, SchemaError from . import csp, sdp, mccs, tmc from .csp import examples as csp_examples -from .sdp import examples as sdp_examples from .mccs import examples as mccs_examples +from .sdp import examples as sdp_examples from .tmc import examples as tmc_examples _LOGGER = logging.getLogger("ska_telmodel") @@ -27,11 +27,15 @@ URI_SCHEMA_MAP = { mccs.MCCS_SCAN_PREFIX: mccs.get_mccs_scan_schema, mccs.MCCS_RELEASERES_PREFIX: mccs.get_mccs_releaseres_schema, # TMC schemas + tmc.TMC_LOW_ASSIGNRES_PREFIX: tmc.get_tmc_assignres_schema, + tmc.TMC_LOW_CONFIGURE_PREFIX: tmc.get_tmc_configure_schema, + tmc.TMC_LOW_RELEASERES_PREFIX: tmc.get_tmc_releaseres_schema, + tmc.TMC_LOW_SCAN_PREFIX: tmc.get_tmc_scan_schema, + tmc.TMC_LOW_ASSIGNEDRES_PREFIX: tmc.get_tmc_assignedres_schema, tmc.TMC_ASSIGNRES_PREFIX: tmc.get_tmc_assignres_schema, tmc.TMC_CONFIGURE_PREFIX: tmc.get_tmc_configure_schema, tmc.TMC_RELEASERES_PREFIX: tmc.get_tmc_releaseres_schema, tmc.TMC_SCAN_PREFIX: tmc.get_tmc_scan_schema, - tmc.TMC_ASSIGNEDRES_PREFIX: tmc.get_tmc_assignedres_schema, } # As above, but for example generation @@ -49,11 +53,15 @@ URI_EXAMPLE_MAP = { mccs.MCCS_SCAN_PREFIX: mccs_examples.get_mccs_scan_example, mccs.MCCS_RELEASERES_PREFIX: mccs_examples.get_mccs_releaseres_example, # TMC schemas + tmc.TMC_LOW_ASSIGNRES_PREFIX: tmc_examples.get_tmc_assignres_example, + tmc.TMC_LOW_CONFIGURE_PREFIX: tmc_examples.get_tmc_configure_example, + tmc.TMC_LOW_SCAN_PREFIX: tmc_examples.get_tmc_scan_example, + tmc.TMC_LOW_RELEASERES_PREFIX: tmc_examples.get_tmc_releaseres_example, + tmc.TMC_LOW_ASSIGNEDRES_PREFIX: tmc_examples.get_tmc_assignedres_example, tmc.TMC_ASSIGNRES_PREFIX: tmc_examples.get_tmc_assignres_example, tmc.TMC_CONFIGURE_PREFIX: tmc_examples.get_tmc_configure_example, tmc.TMC_SCAN_PREFIX: tmc_examples.get_tmc_scan_example, tmc.TMC_RELEASERES_PREFIX: tmc_examples.get_tmc_releaseres_example, - tmc.TMC_ASSIGNEDRES_PREFIX: tmc_examples.get_tmc_assignedres_example, } diff --git a/src/ska_telmodel/tmc/examples.py b/src/ska_telmodel/tmc/examples.py index f7fc4a9e..f4900ad5 100644 --- a/src/ska_telmodel/tmc/examples.py +++ b/src/ska_telmodel/tmc/examples.py @@ -2,7 +2,7 @@ import copy from .version import * -TMC_ASSIGNRES_1_0 = { +TMC_LOW_ASSIGNRES_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-assignresources/1.0", "subarray_id": 1, "mccs": { @@ -12,7 +12,7 @@ TMC_ASSIGNRES_1_0 = { }, } -TMC_CONFIGURE_1_0 = { +TMC_LOW_CONFIGURE_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-configure/1.0", "mccs": { "stations": [{"station_id": 1}, {"station_id": 2}], @@ -36,18 +36,18 @@ TMC_CONFIGURE_1_0 = { "tmc": {"scan_duration": 10.0}, } -TMC_RELEASERES_1_0 = { +TMC_LOW_RELEASERES_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-releaseresources/1.0", "subarray_id": 1, "release_all": True, } -TMC_SCAN_1_0 = { +TMC_LOW_SCAN_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-scan/1.0", "scan_id": 1, } -TMC_ASSIGNEDRES_1_0 = { +TMC_LOW_ASSIGNEDRES_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-assignedresources/1.0", "mccs": { "subarray_beam_ids": [1], @@ -56,7 +56,7 @@ TMC_ASSIGNEDRES_1_0 = { }, } -TMC_ASSIGNEDRES_EMPTY_1_0 = { +TMC_LOW_ASSIGNEDRES_EMPTY_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-assignedresources/1.0", "mccs": { "subarray_beam_ids": [], @@ -66,7 +66,7 @@ TMC_ASSIGNEDRES_EMPTY_1_0 = { } TMC_ASSIGNRES_2_0 = { - "interface": "https://schema.skao.in/ska-low-tmc-assignresources/2.0", + "interface": "https://schema.skao.in/ska-tmc-assignresources/2.0", "transaction_id": "txn-....-00001", "subarray_id": 1, "mccs": { @@ -77,7 +77,7 @@ TMC_ASSIGNRES_2_0 = { } TMC_CONFIGURE_2_0 = { - "interface": "https://schema.skao.in/ska-low-tmc-configure/2.0", + "interface": "https://schema.skao.in/ska-tmc-configure/2.0", "transaction_id": "txn-....-00001", "mccs": { "stations": [{"station_id": 1}, {"station_id": 2}], @@ -102,14 +102,14 @@ TMC_CONFIGURE_2_0 = { } TMC_RELEASERES_2_0 = { - "interface": "https://schema.skao.in/ska-low-tmc-releaseresources/2.0", + "interface": "https://schema.skao.in/ska-tmc-releaseresources/2.0", "transaction_id": "txn-....-00001", "subarray_id": 1, "release_all": True, } TMC_SCAN_2_0 = { - "interface": "https://schema.skao.in/ska-low-tmc-scan/2.0", + "interface": "https://schema.skao.in/ska-tmc-scan/2.0", "transaction_id": "txn-....-00001", "scan_id": 1, } @@ -120,8 +120,8 @@ def get_tmc_assignres_example(version: str): :param version: Version URI of configuration format """ - if version.startswith(tmc_assignres_uri(1, 0)): - return copy.deepcopy(TMC_ASSIGNRES_1_0) + if version.startswith(tmc_low_assignres_uri(1, 0)): + return copy.deepcopy(TMC_LOW_ASSIGNRES_1_0) if version.startswith(tmc_assignres_uri(2, 0)): return copy.deepcopy(TMC_ASSIGNRES_2_0) @@ -134,8 +134,8 @@ def get_tmc_configure_example(version: str): :param version: Version URI of configuration format """ - if version.startswith(tmc_configure_uri(1, 0)): - return copy.deepcopy(TMC_CONFIGURE_1_0) + if version.startswith(tmc_low_configure_uri(1, 0)): + return copy.deepcopy(TMC_LOW_CONFIGURE_1_0) if version.startswith(tmc_configure_uri(2, 0)): return copy.deepcopy(TMC_CONFIGURE_2_0) @@ -148,8 +148,8 @@ def get_tmc_releaseres_example(version: str): :param version: Version URI of configuration format """ - if version.startswith(tmc_releaseres_uri(1, 0)): - return copy.deepcopy(TMC_RELEASERES_1_0) + if version.startswith(tmc_low_releaseres_uri(1, 0)): + return copy.deepcopy(TMC_LOW_RELEASERES_1_0) if version.startswith(tmc_releaseres_uri(2, 0)): return copy.deepcopy(TMC_RELEASERES_2_0) @@ -162,8 +162,8 @@ def get_tmc_scan_example(version: str): :param version: Version URI of configuration format """ - if version.startswith(tmc_scan_uri(1, 0)): - return copy.deepcopy(TMC_SCAN_1_0) + if version.startswith(tmc_low_scan_uri(1, 0)): + return copy.deepcopy(TMC_LOW_SCAN_1_0) if version.startswith(tmc_scan_uri(2, 0)): return copy.deepcopy(TMC_SCAN_2_0) @@ -177,9 +177,9 @@ def get_tmc_assignedres_example(version: str, empty: bool = False): :param version: Version URI of configuration format :param empty: True if example is for empty sub-array """ - if version.startswith(tmc_assignedres_uri(1, 0)): + if version.startswith(tmc_low_assignedres_uri(1, 0)): if empty: - return copy.deepcopy(TMC_ASSIGNEDRES_EMPTY_1_0) - return copy.deepcopy(TMC_ASSIGNEDRES_1_0) + return copy.deepcopy(TMC_LOW_ASSIGNEDRES_EMPTY_1_0) + return copy.deepcopy(TMC_LOW_ASSIGNEDRES_1_0) raise ValueError(f"Could not generate example for schema {version})!") diff --git a/src/ska_telmodel/tmc/schema.py b/src/ska_telmodel/tmc/schema.py index 703ab9ec..42a0cbb3 100644 --- a/src/ska_telmodel/tmc/schema.py +++ b/src/ska_telmodel/tmc/schema.py @@ -2,11 +2,13 @@ SKA Low TMC schemas """ -from schema import Schema, Optional, And, Or, Literal, Regex -from .. import _common -from ..mccs import validators as mccs_validators from inspect import cleandoc + +from schema import Schema, Optional, And, Literal + from .version import * +from .. import _common +from ..mccs import validators as mccs_validators def get_mccs_target_subschema(version: str, strict: bool) -> dict: @@ -23,16 +25,11 @@ def get_mccs_target_subschema(version: str, strict: bool) -> dict: :param strict: strictness level :return: dict suitable for insertion in a Schema """ - default_keynames = dict( - reference_frame="reference_frame", target_name="target_name" - ) - v1_0_keynames = dict(reference_frame="system", target_name="name") - - number = check_tmc_interface_version(version, TMC_CONFIGURE_PREFIX) - if number == "1.0": - keynames = v1_0_keynames + pre_adr35_schemas = [tmc_low_configure_uri(1.0)] + if version in pre_adr35_schemas: + keynames = dict(reference_frame="system", target_name="name") else: - keynames = default_keynames + keynames = dict(reference_frame="reference_frame", target_name="target_name") return { Literal( diff --git a/src/ska_telmodel/tmc/version.py b/src/ska_telmodel/tmc/version.py index 43f2d978..1ca9e171 100644 --- a/src/ska_telmodel/tmc/version.py +++ b/src/ska_telmodel/tmc/version.py @@ -1,18 +1,28 @@ -from .._common import split_interface_version, interface_uri from functools import partial from typing import Union, List +from .._common import interface_uri + TMC_VERSION_PREFIX = "https://schema.skao.int/" -TMC_ASSIGNRES_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-assignresources/" -TMC_CONFIGURE_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-configure/" -TMC_SCAN_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-scan/" -TMC_RELEASERES_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-releaseresources/" -TMC_ASSIGNEDRES_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-assignedresources/" +# prefixes for LOW schema, which are to be merged with MID schema at some point +TMC_LOW_ASSIGNRES_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-assignresources/" +TMC_LOW_CONFIGURE_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-configure/" +TMC_LOW_SCAN_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-scan/" +TMC_LOW_RELEASERES_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-releaseresources/" +TMC_LOW_ASSIGNEDRES_PREFIX = TMC_VERSION_PREFIX + "ska-low-tmc-assignedresources/" +# prefixes for TMC schema. Just MID for PI11, to be MID+LOW eventually. +TMC_ASSIGNRES_PREFIX = TMC_VERSION_PREFIX + "ska-tmc-assignresources/" +TMC_CONFIGURE_PREFIX = TMC_VERSION_PREFIX + "ska-tmc-configure/" +TMC_SCAN_PREFIX = TMC_VERSION_PREFIX + "ska-tmc-scan/" +TMC_RELEASERES_PREFIX = TMC_VERSION_PREFIX + "ska-tmc-releaseresources/" -# JSON strings for MVP-Low for PI#10 -tmc_assignedres_uri = partial(interface_uri, TMC_ASSIGNEDRES_PREFIX) +tmc_low_assignedres_uri = partial(interface_uri, TMC_LOW_ASSIGNEDRES_PREFIX) +tmc_low_assignres_uri = partial(interface_uri, TMC_LOW_ASSIGNRES_PREFIX) +tmc_low_configure_uri = partial(interface_uri, TMC_LOW_CONFIGURE_PREFIX) +tmc_low_scan_uri = partial(interface_uri, TMC_LOW_SCAN_PREFIX) +tmc_low_releaseres_uri = partial(interface_uri, TMC_LOW_RELEASERES_PREFIX) tmc_assignres_uri = partial(interface_uri, TMC_ASSIGNRES_PREFIX) tmc_configure_uri = partial(interface_uri, TMC_CONFIGURE_PREFIX) tmc_scan_uri = partial(interface_uri, TMC_SCAN_PREFIX) @@ -20,6 +30,11 @@ tmc_releaseres_uri = partial(interface_uri, TMC_RELEASERES_PREFIX) _PREFIXES = [ + TMC_LOW_ASSIGNRES_PREFIX, + TMC_LOW_CONFIGURE_PREFIX, + TMC_LOW_SCAN_PREFIX, + TMC_LOW_RELEASERES_PREFIX, + TMC_LOW_ASSIGNEDRES_PREFIX, TMC_ASSIGNRES_PREFIX, TMC_CONFIGURE_PREFIX, TMC_SCAN_PREFIX, diff --git a/tests/test_tmc_schemas.py b/tests/test_tmc_schemas.py index 4581f1a4..60b93da3 100644 --- a/tests/test_tmc_schemas.py +++ b/tests/test_tmc_schemas.py @@ -3,18 +3,34 @@ import pytest from ska_telmodel.schema import validate, example_by_uri from ska_telmodel.tmc.version import * -version_list = [1, 2] +ASSIGNRES_SCHEMAS = [ + tmc_low_assignres_uri(1.0), + tmc_assignres_uri(2.0), +] +CONFIGURE_SCHEMAS = [ + tmc_low_configure_uri(1.0), + tmc_configure_uri(2.0), +] +SCAN_SCHEMAS = [ + tmc_low_scan_uri(1.0), + tmc_scan_uri(2.0), +] +RELEASERES_SCHEMAS = [ + tmc_low_releaseres_uri(1.0), + tmc_releaseres_uri(2.0), +] def test_tmc_versions(caplog): - assert ( check_tmc_interface_version(TMC_CONFIGURE_PREFIX + "2.0", TMC_CONFIGURE_PREFIX) == "2.0" ) assert ( - check_tmc_interface_version(TMC_CONFIGURE_PREFIX + "1.0", TMC_CONFIGURE_PREFIX) + check_tmc_interface_version( + TMC_LOW_CONFIGURE_PREFIX + "1.0", TMC_LOW_CONFIGURE_PREFIX + ) == "1.0" ) @@ -25,45 +41,45 @@ def test_tmc_versions(caplog): check_tmc_interface_version(invalid_prefix) -def test_tmc_assign_resources(): +@pytest.mark.parametrize("schema_uri", ASSIGNRES_SCHEMAS) +def test_tmc_assign_resources(schema_uri): """Test TMC resource allocation schema correctly validates the expected JSON. """ - for ver in version_list: - assign_ver = tmc_assignres_uri(ver, 0) - validate(assign_ver, example_by_uri(assign_ver), 2) + validate(schema_uri, example_by_uri(schema_uri), strictness=2) - # Check that an error is raised if 'subarray_id' is omitted - tmc_assign_erronous = example_by_uri(assign_ver) - del tmc_assign_erronous["subarray_id"] - with pytest.raises(ValueError): - validate(assign_ver, tmc_assign_erronous, 1) + # Check that an error is raised if 'subarray_id' is omitted + tmc_assign_erronous = example_by_uri(schema_uri) + del tmc_assign_erronous["subarray_id"] + with pytest.raises(ValueError): + validate(schema_uri, tmc_assign_erronous, 1) - # Try with interface version given as part of JSON object - tmc_assign_versioned = example_by_uri(assign_ver) - tmc_assign_versioned["interface"] = assign_ver - validate(None, tmc_assign_versioned, 1) + # Try with interface version given as part of JSON object + tmc_assign_versioned = example_by_uri(schema_uri) + tmc_assign_versioned["interface"] = schema_uri + validate(None, tmc_assign_versioned, 1) - # Check invalid version raises error - with pytest.raises(ValueError, match=r"Could not generate example"): - example_by_uri(TMC_ASSIGNRES_PREFIX + "0.0") + # Check invalid version raises error + schema_root, _, _ = schema_uri.rpartition("/") + with pytest.raises(ValueError, match=r"Could not generate example"): + example_by_uri(f"{schema_root}/0.0") +@pytest.mark.parametrize("schema_uri", ASSIGNRES_SCHEMAS) @pytest.mark.parametrize( "field_name, invalid_input", [("subarray_id", 50), ("subarray_id", -1)], ) -def test_tmc_assign_resources_invalid_input(field_name, invalid_input): +def test_tmc_assign_resources_invalid_input(schema_uri, field_name, invalid_input): """Test MCCS assign resources schema throws an error on invalid input.""" - for ver in version_list: - assign_ver = tmc_assignres_uri(ver, 0) - assign_json = example_by_uri(assign_ver) - assign_json[field_name] = invalid_input + assign_json = example_by_uri(schema_uri) + assign_json[field_name] = invalid_input - with pytest.raises(ValueError, match=r"should evaluate to True"): - validate(assign_ver, assign_json, 2) + with pytest.raises(ValueError, match=r"should evaluate to True"): + validate(schema_uri, assign_json, 2) +@pytest.mark.parametrize("schema_uri", ASSIGNRES_SCHEMAS) @pytest.mark.parametrize( "field_name, invalid_input", [ @@ -73,80 +89,76 @@ def test_tmc_assign_resources_invalid_input(field_name, invalid_input): ("channel_blocks", [1] * 50), ], ) -def test_tmc_assign_resources_invalid_mccs_input(field_name, invalid_input): +def test_tmc_assign_resources_invalid_mccs_input(schema_uri, field_name, invalid_input): """Test TMC assign resources schema throws an error on invalid input.""" - for ver in version_list: - assign_ver = tmc_assignres_uri(ver, 0) - assign_json = example_by_uri(assign_ver) - assign_json["mccs"][field_name] = invalid_input + assign_json = example_by_uri(schema_uri) + assign_json["mccs"][field_name] = invalid_input - with pytest.raises(ValueError, match=r"should evaluate to True"): - validate(assign_ver, assign_json, 2) + with pytest.raises(ValueError, match=r"should evaluate to True"): + validate(schema_uri, assign_json, 2) -def test_tmc_configure(): +@pytest.mark.parametrize("schema_uri", CONFIGURE_SCHEMAS) +def test_tmc_configure(schema_uri): """Test TMC configure schema correctly validates the expected JSON. """ - for ver in version_list: - configure_ver = tmc_configure_uri(ver, 0) - validate(configure_ver, example_by_uri(configure_ver), 2) + validate(schema_uri, example_by_uri(schema_uri), 2) - # Try with interface version given as part of JSON object - tmc_configure_versioned = example_by_uri(configure_ver) - tmc_configure_versioned["interface"] = configure_ver - validate(None, tmc_configure_versioned, 1) + # Try with interface version given as part of JSON object + tmc_configure_versioned = example_by_uri(schema_uri) + tmc_configure_versioned["interface"] = schema_uri + validate(None, tmc_configure_versioned, 1) - # Check invalid version raises error - with pytest.raises(ValueError, match=r"Could not generate example"): - example_by_uri(TMC_CONFIGURE_PREFIX + "0.0") + # Check invalid version raises error + schema_root, _, _ = schema_uri.rpartition("/") + with pytest.raises(ValueError, match=r"Could not generate example"): + example_by_uri(f"{schema_root}/0.0") +@pytest.mark.parametrize("schema_uri", CONFIGURE_SCHEMAS) @pytest.mark.parametrize( "field_name, invalid_input", [("stations", [{"station_id": 513}]), ("stations", [{"station_id": 1}] * 513)], ) -def test_tmc_configure_invalid_mccs_input(field_name, invalid_input): +def test_tmc_configure_invalid_mccs_input(schema_uri, field_name, invalid_input): """Test TMC configure schema throws an error on invalid input.""" - for ver in version_list: - configure_ver = tmc_configure_uri(ver, 0) - configure_json = example_by_uri(configure_ver) - configure_json["mccs"][field_name] = invalid_input + configure_json = example_by_uri(schema_uri) + configure_json["mccs"][field_name] = invalid_input - with pytest.raises(ValueError, match=r"should evaluate to True"): - validate(configure_ver, configure_json, 2) + with pytest.raises(ValueError): + validate(schema_uri, configure_json, 2) +@pytest.mark.parametrize("schema_uri", CONFIGURE_SCHEMAS) @pytest.mark.parametrize( "field_name, invalid_input", [("scan_duration", -1.0)], ) -def test_tmc_configure_invalid_tmc_input(field_name, invalid_input): +def test_tmc_configure_invalid_tmc_input(schema_uri, field_name, invalid_input): """Test TMC configure schema throws an error on invalid input.""" - for ver in version_list: - configure_ver = tmc_configure_uri(ver, 0) - configure_json = example_by_uri(configure_ver) - configure_json["tmc"][field_name] = invalid_input + configure_json = example_by_uri(schema_uri) + configure_json["tmc"][field_name] = invalid_input - with pytest.raises(ValueError, match=r"should evaluate to True"): - validate(configure_ver, configure_json, 2) + with pytest.raises(ValueError): + validate(schema_uri, configure_json, 2) +@pytest.mark.parametrize("schema_uri", CONFIGURE_SCHEMAS) @pytest.mark.parametrize( "field_name", ["tmc"], ) -def test_tmc_configure_optional_root_elements(field_name): +def test_tmc_configure_optional_root_elements(schema_uri, field_name): """Verify that optional elements can be removed from the Configure payload without triggering a validation error """ - for ver in version_list: - configure_ver = tmc_configure_uri(ver, 0) - configure_json = example_by_uri(configure_ver) - del configure_json[field_name] - validate(configure_ver, configure_json, 2) + configure_json = example_by_uri(schema_uri) + del configure_json[field_name] + validate(schema_uri, configure_json, 2) +@pytest.mark.parametrize("schema_uri", CONFIGURE_SCHEMAS) @pytest.mark.parametrize( "field_name, invalid_input", [ @@ -167,88 +179,85 @@ def test_tmc_configure_optional_root_elements(field_name): ], ) def test_tmc_configure_subarray_beam_invalid_subarray_beam_input( - field_name, invalid_input + schema_uri, field_name, invalid_input ): """Test TMC configure schema throws an error on invalid subarray beam inputs.""" - for ver in version_list: - configure_ver = tmc_configure_uri(ver, 0) - configure_json = example_by_uri(configure_ver) - configure_json["mccs"]["subarray_beams"][0][field_name] = invalid_input + configure_json = example_by_uri(schema_uri) + configure_json["mccs"]["subarray_beams"][0][field_name] = invalid_input - with pytest.raises(ValueError, match=r"should evaluate to True"): - validate(configure_ver, configure_json, 2) + with pytest.raises(ValueError, match=r"should evaluate to True"): + validate(schema_uri, configure_json, 2) -def test_tmc_release_resources(): +@pytest.mark.parametrize("schema_uri", RELEASERES_SCHEMAS) +def test_tmc_release_resources(schema_uri): """Test TMC resource release schema correctly validates the expected JSON. """ - for ver in version_list: - release_ver = tmc_releaseres_uri(ver, 0) - validate(release_ver, example_by_uri(release_ver), 2) + validate(schema_uri, example_by_uri(schema_uri), 2) - # Check that an error is raised if 'subarray_id' is omitted - tmc_release_erronous = example_by_uri(release_ver) - del tmc_release_erronous["subarray_id"] - validate(release_ver, tmc_release_erronous, 0) - with pytest.raises(ValueError): - validate(release_ver, tmc_release_erronous, 1) + # Check that an error is raised if 'subarray_id' is omitted + tmc_release_erronous = example_by_uri(schema_uri) + del tmc_release_erronous["subarray_id"] + validate(schema_uri, tmc_release_erronous, 0) + with pytest.raises(ValueError): + validate(schema_uri, tmc_release_erronous, 1) - # Try with interface version given as part of JSON object - tmc_release_versioned = example_by_uri(release_ver) - tmc_release_versioned["interface"] = release_ver - validate(None, tmc_release_versioned, 1) + # Try with interface version given as part of JSON object + tmc_release_versioned = example_by_uri(schema_uri) + tmc_release_versioned["interface"] = schema_uri + validate(None, tmc_release_versioned, 1) - # Check invalid version raises error - with pytest.raises(ValueError, match=r"Could not generate example"): - example_by_uri(TMC_RELEASERES_PREFIX + "0.0") + # Check invalid version raises error + schema_root, _, _ = schema_uri.rpartition("/") + with pytest.raises(ValueError, match=r"Could not generate example"): + example_by_uri(f"{schema_root}/0.0") +@pytest.mark.parametrize("schema_uri", RELEASERES_SCHEMAS) @pytest.mark.parametrize( "field_name, invalid_input", [("subarray_id", 50), ("subarray_id", -1)] ) -def test_tmc_release_resources_invalid_input(field_name, invalid_input): +def test_tmc_release_resources_invalid_input(schema_uri, field_name, invalid_input): """Test TMC release resources schema throws an error on invalid input.""" - for ver in version_list: - release_ver = tmc_releaseres_uri(ver, 0) - release_json = example_by_uri(release_ver) - release_json[field_name] = invalid_input + release_json = example_by_uri(schema_uri) + release_json[field_name] = invalid_input - with pytest.raises(ValueError, match=r"should evaluate to True"): - validate(release_ver, release_json, 2) + with pytest.raises(ValueError, match=r"should evaluate to True"): + validate(schema_uri, release_json, 2) -def test_tmc_scan(): +@pytest.mark.parametrize("schema_uri", SCAN_SCHEMAS) +def test_tmc_scan(schema_uri): """Test TMC scan schema correctly validates the expected JSON. """ - for ver in version_list: - scan_ver = tmc_scan_uri(ver, 0) - validate(scan_ver, example_by_uri(scan_ver), 2) + validate(schema_uri, example_by_uri(schema_uri), 2) - # Check that an error is raised if 'scan_id' is omitted - tmc_scan_erronous = example_by_uri(scan_ver) - del tmc_scan_erronous["scan_id"] - validate(scan_ver, tmc_scan_erronous, 0) - with pytest.raises(ValueError): - validate(scan_ver, tmc_scan_erronous, 1) + # Check that an error is raised if 'scan_id' is omitted + tmc_scan_erronous = example_by_uri(schema_uri) + del tmc_scan_erronous["scan_id"] + validate(schema_uri, tmc_scan_erronous, 0) + with pytest.raises(ValueError): + validate(schema_uri, tmc_scan_erronous, 1) - # Try with interface version given as part of JSON object - tmc_scan_versioned = example_by_uri(scan_ver) - tmc_scan_versioned["interface"] = scan_ver - validate(None, tmc_scan_versioned, 1) + # Try with interface version given as part of JSON object + tmc_scan_versioned = example_by_uri(schema_uri) + tmc_scan_versioned["interface"] = schema_uri + validate(None, tmc_scan_versioned, 1) - # Check invalid version raises error - with pytest.raises(ValueError, match=r"Could not generate example"): - example_by_uri(TMC_SCAN_PREFIX + "0.0") + # Check invalid version raises error + schema_root, _, _ = schema_uri.rpartition("/") + with pytest.raises(ValueError, match=r"Could not generate example"): + example_by_uri(f"{schema_root}/0.0") def test_tmc_assigned_resources(): """Test TMC assigned resources schema correctly validates the expected JSON. """ - assigned_ver = tmc_assignedres_uri(1, 0) + assigned_ver = tmc_low_assignedres_uri(1, 0) # Test with string containing allocated resources validate(assigned_ver, example_by_uri(assigned_ver), 2) @@ -263,7 +272,7 @@ def test_tmc_assigned_resources(): # Check invalid version raises error with pytest.raises(ValueError, match=r"Could not generate example"): - example_by_uri(TMC_ASSIGNEDRES_PREFIX + "0.0") + example_by_uri(TMC_LOW_ASSIGNEDRES_PREFIX + "0.0") @pytest.mark.parametrize( @@ -277,7 +286,7 @@ def test_tmc_assigned_resources(): ) def test_tmc_assigned_resources_invalid_mccs_input(field_name, invalid_input): """Test TMC assigned resources schema throws an error on invalid input.""" - assigned_ver = tmc_assignedres_uri(1, 0) + assigned_ver = tmc_low_assignedres_uri(1, 0) assigned_json = example_by_uri(assigned_ver) assigned_json["mccs"][field_name] = invalid_input -- GitLab From 2db17ad66fb412f228c0258369c99d7755291948 Mon Sep 17 00:00:00 2001 From: Stewart Williams <3161869-bravostuzero@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 15:31:16 +0100 Subject: [PATCH 2/6] AT1-905 bugfix: MCCS was not optional in SAN.configure, making it required even for MID --- src/ska_telmodel/tmc/schema.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ska_telmodel/tmc/schema.py b/src/ska_telmodel/tmc/schema.py index 42a0cbb3..927b0946 100644 --- a/src/ska_telmodel/tmc/schema.py +++ b/src/ska_telmodel/tmc/schema.py @@ -211,13 +211,15 @@ def get_tmc_configure_schema(version: str, strict: bool) -> Schema: ), ) ): str, - Literal( - "mccs", - description=cleandoc( - """ - MCCS configuration specification. - """ - ), + Optional( + Literal( + "mccs", + description=cleandoc( + """ + MCCS configuration specification. + """ + ), + ) ): { Literal( "stations", -- GitLab From ef24129068c76c192a88c46e0bb14747d1b7273e Mon Sep 17 00:00:00 2001 From: Stewart Williams <3161869-bravostuzero@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 15:45:22 +0100 Subject: [PATCH 3/6] AT1-905 bugfix: add TMC schema docs for MID --- docs/src/index.rst | 5 +++++ docs/src/ska_low_tmc_assignres.rst | 11 ----------- docs/src/ska_low_tmc_configure.rst | 11 ----------- docs/src/ska_low_tmc_releaseres.rst | 11 ----------- docs/src/ska_low_tmc_scan.rst | 11 ----------- docs/src/ska_tmc_assignres.rst | 14 ++++++++++++++ docs/src/ska_tmc_configure.rst | 14 ++++++++++++++ docs/src/ska_tmc_releaseres.rst | 14 ++++++++++++++ docs/src/ska_tmc_scan.rst | 14 ++++++++++++++ 9 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 docs/src/ska_tmc_assignres.rst create mode 100644 docs/src/ska_tmc_configure.rst create mode 100644 docs/src/ska_tmc_releaseres.rst create mode 100644 docs/src/ska_tmc_scan.rst diff --git a/docs/src/index.rst b/docs/src/index.rst index 54d6f885..9a7896a1 100644 --- a/docs/src/index.rst +++ b/docs/src/index.rst @@ -61,6 +61,11 @@ ska_low_tmc_scan ska_low_tmc_assignedres + ska_tmc_assignres + ska_tmc_configure + ska_tmc_releaseres + ska_tmc_scan + Project-name documentation HEADING ================================== diff --git a/docs/src/ska_low_tmc_assignres.rst b/docs/src/ska_low_tmc_assignres.rst index 2a499dc1..0cd61534 100644 --- a/docs/src/ska_low_tmc_assignres.rst +++ b/docs/src/ska_low_tmc_assignres.rst @@ -2,17 +2,6 @@ ska-low-tmc-assignresources =========================== -.. ska-schema:: https://schema.skao.int/ska-low-tmc-assignresources/2.0 - :auto_reference: - :auto_target: - :lift_description: - :lift_definitions: - :lift_title: - - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-assignresources/2.0 - - Example JSON. - .. ska-schema:: https://schema.skatelescope.org/ska-low-tmc-assignresources/1.0 :auto_reference: :auto_target: diff --git a/docs/src/ska_low_tmc_configure.rst b/docs/src/ska_low_tmc_configure.rst index 9dbff5b3..5bd4d48a 100644 --- a/docs/src/ska_low_tmc_configure.rst +++ b/docs/src/ska_low_tmc_configure.rst @@ -2,17 +2,6 @@ ska-low-tmc-configure ===================== -.. ska-schema:: https://schema.skao.int/ska-low-tmc-configure/2.0 - :auto_reference: - :auto_target: - :lift_description: - :lift_definitions: - :lift_title: - - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-configure/2.0 - - Example JSON. - .. ska-schema:: https://schema.skatelescope.org/ska-low-tmc-configure/1.0 :auto_reference: :auto_target: diff --git a/docs/src/ska_low_tmc_releaseres.rst b/docs/src/ska_low_tmc_releaseres.rst index dd198381..6fb52bf2 100644 --- a/docs/src/ska_low_tmc_releaseres.rst +++ b/docs/src/ska_low_tmc_releaseres.rst @@ -2,17 +2,6 @@ ska-low-tmc-releaseresources ============================ -.. ska-schema:: https://schema.skao.int/ska-low-tmc-releaseresources/2.0 - :auto_reference: - :auto_target: - :lift_description: - :lift_definitions: - :lift_title: - - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-releaseresources/2.0 - - Example JSON. - .. ska-schema:: https://schema.skatelescope.org/ska-low-tmc-releaseresources/1.0 :auto_reference: :auto_target: diff --git a/docs/src/ska_low_tmc_scan.rst b/docs/src/ska_low_tmc_scan.rst index d8c6c607..de9012f7 100644 --- a/docs/src/ska_low_tmc_scan.rst +++ b/docs/src/ska_low_tmc_scan.rst @@ -2,17 +2,6 @@ ska-low-tmc-scan ================ -.. ska-schema:: https://schema.skao.int/ska-low-tmc-scan/2.0 - :auto_reference: - :auto_target: - :lift_description: - :lift_definitions: - :lift_title: - - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-scan/2.0 - - Example JSON. - .. ska-schema:: https://schema.skatelescope.org/ska-low-tmc-scan/1.0 :auto_reference: :auto_target: diff --git a/docs/src/ska_tmc_assignres.rst b/docs/src/ska_tmc_assignres.rst new file mode 100644 index 00000000..4afbab69 --- /dev/null +++ b/docs/src/ska_tmc_assignres.rst @@ -0,0 +1,14 @@ + +ska-tmc-assignresources +======================= + +.. ska-schema:: https://schema.skao.int/ska-low-tmc-assignresources/2.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-assignresources/2.0 + + Example JSON. diff --git a/docs/src/ska_tmc_configure.rst b/docs/src/ska_tmc_configure.rst new file mode 100644 index 00000000..3f1d48d9 --- /dev/null +++ b/docs/src/ska_tmc_configure.rst @@ -0,0 +1,14 @@ + +ska-tmc-configure +================= + +.. ska-schema:: https://schema.skao.int/ska-low-tmc-configure/2.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-configure/2.0 + + Example JSON. diff --git a/docs/src/ska_tmc_releaseres.rst b/docs/src/ska_tmc_releaseres.rst new file mode 100644 index 00000000..6590f65a --- /dev/null +++ b/docs/src/ska_tmc_releaseres.rst @@ -0,0 +1,14 @@ + +ska-tmc-releaseresources +======================== + +.. ska-schema:: https://schema.skao.int/ska-low-tmc-releaseresources/2.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-releaseresources/2.0 + + Example JSON. diff --git a/docs/src/ska_tmc_scan.rst b/docs/src/ska_tmc_scan.rst new file mode 100644 index 00000000..94ea96fd --- /dev/null +++ b/docs/src/ska_tmc_scan.rst @@ -0,0 +1,14 @@ + +ska-tmc-scan +============ + +.. ska-schema:: https://schema.skao.int/ska-low-tmc-scan/2.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-scan/2.0 + + Example JSON. -- GitLab From 2edd17c2dde3c4036e138f3aee68d6bd6c7ded7d Mon Sep 17 00:00:00 2001 From: Stewart Williams <3161869-bravostuzero@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 15:48:21 +0100 Subject: [PATCH 4/6] AT1-905 bugfix: ska-low-tmc-assignresources doc example docs was requesting v2.0 --- docs/src/ska_tmc_assignres.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/ska_tmc_assignres.rst b/docs/src/ska_tmc_assignres.rst index 4afbab69..cde8119d 100644 --- a/docs/src/ska_tmc_assignres.rst +++ b/docs/src/ska_tmc_assignres.rst @@ -2,13 +2,13 @@ ska-tmc-assignresources ======================= -.. ska-schema:: https://schema.skao.int/ska-low-tmc-assignresources/2.0 +.. ska-schema:: https://schema.skao.int/ska-low-tmc-assignresources/1.0 :auto_reference: :auto_target: :lift_description: :lift_definitions: :lift_title: - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-assignresources/2.0 + .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-assignresources/1.0 Example JSON. -- GitLab From c9a0e0c935d4a081a6f3993e0807e85595210599 Mon Sep 17 00:00:00 2001 From: Stewart Williams <3161869-bravostuzero@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 15:54:10 +0100 Subject: [PATCH 5/6] AT1-905 bugfix: align TMC schema docs with example versions --- docs/src/ska_tmc_assignres.rst | 4 ++-- docs/src/ska_tmc_configure.rst | 4 ++-- docs/src/ska_tmc_releaseres.rst | 4 ++-- docs/src/ska_tmc_scan.rst | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/src/ska_tmc_assignres.rst b/docs/src/ska_tmc_assignres.rst index cde8119d..27336745 100644 --- a/docs/src/ska_tmc_assignres.rst +++ b/docs/src/ska_tmc_assignres.rst @@ -2,13 +2,13 @@ ska-tmc-assignresources ======================= -.. ska-schema:: https://schema.skao.int/ska-low-tmc-assignresources/1.0 +.. ska-schema:: https://schema.skao.int/ska-tmc-assignresources/2.0 :auto_reference: :auto_target: :lift_description: :lift_definitions: :lift_title: - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-assignresources/1.0 + .. ska-schema-example:: https://schema.skao.int/ska-tmc-assignresources/2.0 Example JSON. diff --git a/docs/src/ska_tmc_configure.rst b/docs/src/ska_tmc_configure.rst index 3f1d48d9..86ea3f54 100644 --- a/docs/src/ska_tmc_configure.rst +++ b/docs/src/ska_tmc_configure.rst @@ -2,13 +2,13 @@ ska-tmc-configure ================= -.. ska-schema:: https://schema.skao.int/ska-low-tmc-configure/2.0 +.. ska-schema:: https://schema.skao.int/ska-tmc-configure/2.0 :auto_reference: :auto_target: :lift_description: :lift_definitions: :lift_title: - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-configure/2.0 + .. ska-schema-example:: https://schema.skao.int/ska-tmc-configure/2.0 Example JSON. diff --git a/docs/src/ska_tmc_releaseres.rst b/docs/src/ska_tmc_releaseres.rst index 6590f65a..f228d15b 100644 --- a/docs/src/ska_tmc_releaseres.rst +++ b/docs/src/ska_tmc_releaseres.rst @@ -2,13 +2,13 @@ ska-tmc-releaseresources ======================== -.. ska-schema:: https://schema.skao.int/ska-low-tmc-releaseresources/2.0 +.. ska-schema:: https://schema.skao.int/ska-tmc-releaseresources/2.0 :auto_reference: :auto_target: :lift_description: :lift_definitions: :lift_title: - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-releaseresources/2.0 + .. ska-schema-example:: https://schema.skao.int/ska-tmc-releaseresources/2.0 Example JSON. diff --git a/docs/src/ska_tmc_scan.rst b/docs/src/ska_tmc_scan.rst index 94ea96fd..6aae4c48 100644 --- a/docs/src/ska_tmc_scan.rst +++ b/docs/src/ska_tmc_scan.rst @@ -2,13 +2,13 @@ ska-tmc-scan ============ -.. ska-schema:: https://schema.skao.int/ska-low-tmc-scan/2.0 +.. ska-schema:: https://schema.skao.int/ska-tmc-scan/2.0 :auto_reference: :auto_target: :lift_description: :lift_definitions: :lift_title: - .. ska-schema-example:: https://schema.skao.int/ska-low-tmc-scan/2.0 + .. ska-schema-example:: https://schema.skao.int/ska-tmc-scan/2.0 Example JSON. -- GitLab From 238c46e346c95252e37239f06d0f125bd211b0b5 Mon Sep 17 00:00:00 2001 From: Stewart Williams <3161869-bravostuzero@users.noreply.gitlab.com> Date: Wed, 7 Jul 2021 16:12:00 +0100 Subject: [PATCH 6/6] AT1-905 bugfix: MCCS was not optional in CN.assignResources, making it required even for MID --- src/ska_telmodel/tmc/schema.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ska_telmodel/tmc/schema.py b/src/ska_telmodel/tmc/schema.py index 927b0946..d5949a7b 100644 --- a/src/ska_telmodel/tmc/schema.py +++ b/src/ska_telmodel/tmc/schema.py @@ -118,13 +118,15 @@ def get_tmc_assignres_schema(version: str, strict: bool) -> Schema: """ ), ): And(int, if_strict(lambda n: mccs_validators.validate_subarray_id(n))), - Literal( - "mccs", - description=cleandoc( - """ - MCCS specification for resource allocation. - """ - ), + Optional( + Literal( + "mccs", + description=cleandoc( + """ + MCCS specification for resource allocation. + """ + ), + ) ): { Literal( "subarray_beam_ids", -- GitLab