From 139cd4cfc0e08c229ee046b3d3e5a1711d88e7f3 Mon Sep 17 00:00:00 2001 From: Andrew McDermott Date: Thu, 24 Jun 2021 10:09:10 +0100 Subject: [PATCH 1/2] AT2-910: Added scan for MID TMC, CSP, SDP --- docs/src/ska_mid_csp_scan.rst | 14 +++++++++++ docs/src/ska_mid_sdp_scan.rst | 14 +++++++++++ docs/src/ska_mid_tmc_scan.rst | 14 +++++++++++ src/ska_telmodel/csp/examples.py | 16 ++++++++++++ src/ska_telmodel/csp/schema.py | 33 +++++++++++++++++++++++++ src/ska_telmodel/csp/version.py | 10 +++++++- src/ska_telmodel/schema.py | 8 ++++++ src/ska_telmodel/sdp/examples.py | 18 ++++++++++++++ src/ska_telmodel/sdp/schema.py | 42 +++++++++++++++++++++++++++++++- src/ska_telmodel/sdp/version.py | 2 ++ src/ska_telmodel/tmc/examples.py | 16 ++++++++++++ src/ska_telmodel/tmc/schema.py | 34 ++++++++++++++++++++++++++ src/ska_telmodel/tmc/version.py | 6 +++++ tests/test_csp_config.py | 24 ++++++++++++++++++ tests/test_sdp_schemas.py | 7 ++++++ 15 files changed, 256 insertions(+), 2 deletions(-) create mode 100644 docs/src/ska_mid_csp_scan.rst create mode 100644 docs/src/ska_mid_sdp_scan.rst create mode 100644 docs/src/ska_mid_tmc_scan.rst diff --git a/docs/src/ska_mid_csp_scan.rst b/docs/src/ska_mid_csp_scan.rst new file mode 100644 index 00000000..2bfcaa4f --- /dev/null +++ b/docs/src/ska_mid_csp_scan.rst @@ -0,0 +1,14 @@ + +ska-mid-csp-scan +================ + +.. ska-schema:: https://schema.skatelescope.org/ska-mid-csp-scan/1.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skatelescope.org/ska-tmc-scan/1.0 + + Example JSON. diff --git a/docs/src/ska_mid_sdp_scan.rst b/docs/src/ska_mid_sdp_scan.rst new file mode 100644 index 00000000..72019919 --- /dev/null +++ b/docs/src/ska_mid_sdp_scan.rst @@ -0,0 +1,14 @@ + +ska-mid-sdp-scan +================ + +.. ska-schema:: https://schema.skatelescope.org/ska-mid-sdp-scan/1.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skatelescope.org/ska-mid-sdp-scan/1.0 + + Example JSON. diff --git a/docs/src/ska_mid_tmc_scan.rst b/docs/src/ska_mid_tmc_scan.rst new file mode 100644 index 00000000..7ae88bd6 --- /dev/null +++ b/docs/src/ska_mid_tmc_scan.rst @@ -0,0 +1,14 @@ + +ska-tmc-scan +================ + +.. ska-schema:: https://schema.skatelescope.org/ska-tmc-scan/1.0 + :auto_reference: + :auto_target: + :lift_description: + :lift_definitions: + :lift_title: + + .. ska-schema-example:: https://schema.skatelescope.org/ska-tmc-scan/1.0 + + Example JSON. diff --git a/src/ska_telmodel/csp/examples.py b/src/ska_telmodel/csp/examples.py index 71a896a4..6d3f301f 100644 --- a/src/ska_telmodel/csp/examples.py +++ b/src/ska_telmodel/csp/examples.py @@ -211,6 +211,11 @@ CSP_CONFIG_SCIENCE_A_0_1 = { ], } +CSP_MID_SCAN_1_0 = { + "interface": "https://schema.skatelescope.org/ska-mid-csp-scan/1.0", + "scan_id": 1, +} + def get_csp_config_example(version: str, scan: str = None) -> dict: """Generate examples for CSP configuration strings @@ -238,3 +243,14 @@ def get_csp_config_example(version: str, scan: str = None) -> dict: return copy.deepcopy(CSP_CONFIG_SCIENCE_A_1_0) raise ValueError(f"Could not generate example for schema {version} scan {scan}!") + + +def get_csp_mid_scan_example(version: str): + """Generate examples for CSP MID scan strings. + + :param version: Version URI of configuration format + """ + if version.startswith(csp_mid_scan_uri(1,0)): + return copy.deepcopy(CSP_MID_SCAN_1_0) + + raise ValueError(f"Could not generate example for schema {version})!") diff --git a/src/ska_telmodel/csp/schema.py b/src/ska_telmodel/csp/schema.py index d8d0cbda..806d35a0 100644 --- a/src/ska_telmodel/csp/schema.py +++ b/src/ska_telmodel/csp/schema.py @@ -590,3 +590,36 @@ def get_csp_config_schema(version: str, strict: bool) -> Schema: else: raise ValueError(f"Invalid JSON Schema URI {version}") + +def get_csp_mid_scan_schema(version: str, strict: bool) -> Schema: + """SKA Mid CSP scan Schema + + :param version: Interface Version URI + :param strict: Schema strictness + :return: Schema + """ + + items = { + Literal( + "interface", + description=cleandoc( + """ + URI of JSON schema applicable to this JSON payload. + """ + ), + ): str, + Literal( + "scan_id", + description=cleandoc( + """ + Scan ID to associate with the data. + + The scan ID and SBI ID are used together to uniquely associate + the data taken with the telescope configuration in effect at + the moment of observation. + """ + ), + ): int, + } + + return _common.make("Mid CSP scan", version, strict, items) \ No newline at end of file diff --git a/src/ska_telmodel/csp/version.py b/src/ska_telmodel/csp/version.py index b71a5600..48ac9257 100644 --- a/src/ska_telmodel/csp/version.py +++ b/src/ska_telmodel/csp/version.py @@ -1,9 +1,12 @@ from typing import Union import logging -from .._common import split_interface_version +from .._common import split_interface_version, interface_uri +from functools import partial CSP_CONFIG_PREFIX = "https://schema.skatelescope.org/ska-csp-configure/" +CSP_MID_SCAN_PREFIX = "https://schema.skatelescope.org/ska-mid-csp-scan/" + CSP_CONFIG_VER0 = CSP_CONFIG_PREFIX + "0" # ADR-3 Configuring and Scanning, # ADR-4 Link map CSP configuration @@ -14,6 +17,8 @@ CSP_CONFIG_VER0_1 = CSP_CONFIG_PREFIX + "0.1" CSP_CONFIG_VER1 = CSP_CONFIG_PREFIX + "1" CSP_CONFIG_VER1_0 = CSP_CONFIG_PREFIX + "1.0" +CSP_MID_SCAN_VER1_0 = CSP_MID_SCAN_PREFIX + "1.0" + # CSP configuration versions, chronologically sorted CSP_CONFIG_VERSIONS = sorted( [CSP_CONFIG_VER0_0, CSP_CONFIG_VER0_1, CSP_CONFIG_VER1_0], @@ -56,3 +61,6 @@ def get_csp_config_version( f"CSP interface URI '%s' not recognised!", csp_interface_version ) return csp_interface_version + + +csp_mid_scan_uri = partial(interface_uri, CSP_MID_SCAN_PREFIX) \ No newline at end of file diff --git a/src/ska_telmodel/schema.py b/src/ska_telmodel/schema.py index 88384082..f66fb906 100644 --- a/src/ska_telmodel/schema.py +++ b/src/ska_telmodel/schema.py @@ -15,10 +15,12 @@ _LOGGER = logging.getLogger("ska_telmodel") # the schema for them URI_SCHEMA_MAP = { csp.CSP_CONFIG_PREFIX: csp.get_csp_config_schema, + csp.CSP_MID_SCAN_PREFIX: csp.get_csp_mid_scan_schema, # SDP schemas sdp.SDP_ASSIGNRES_PREFIX: sdp.get_sdp_assign_resources_schema, sdp.SDP_CONFIG_PREFIX: sdp.get_sdp_config_schema, sdp.SDP_SCAN_PREFIX: sdp.get_sdp_scan_schema, + sdp.SDP_MID_SCAN_PREFIX: sdp.get_sdp_mid_scan_schema, sdp.SDP_RECVADDRS_PREFIX: sdp.get_sdp_receive_addresses_schema, # MCCS schemas mccs.MCCS_ASSIGNEDRES_PREFIX: mccs.get_mccs_assignedres_schema, @@ -32,15 +34,19 @@ URI_SCHEMA_MAP = { 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, + # TMC MID schemas + tmc.TMC_MID_SCAN_PREFIX: tmc.get_tmc_mid_scan_schema, } # As above, but for example generation URI_EXAMPLE_MAP = { csp.CSP_CONFIG_PREFIX: csp_examples.get_csp_config_example, + csp.CSP_MID_SCAN_PREFIX: csp_examples.get_csp_mid_scan_example, # SDP schemas sdp.SDP_ASSIGNRES_PREFIX: sdp_examples.get_sdp_assignres_example, sdp.SDP_CONFIG_PREFIX: sdp_examples.get_sdp_config_example, sdp.SDP_SCAN_PREFIX: sdp_examples.get_sdp_scan_example, + sdp.SDP_MID_SCAN_PREFIX: sdp_examples.get_sdp_mid_scan_example, sdp.SDP_RECVADDRS_PREFIX: sdp_examples.get_sdp_recvaddrs_example, # MCCS schemas mccs.MCCS_ASSIGNEDRES_PREFIX: mccs_examples.get_mccs_assignedres_example, @@ -54,6 +60,8 @@ URI_EXAMPLE_MAP = { 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, + # TMC MID schemas + tmc.TMC_MID_SCAN_PREFIX: tmc_examples.get_tmc_mid_scan_example, } diff --git a/src/ska_telmodel/sdp/examples.py b/src/ska_telmodel/sdp/examples.py index 38fce2da..4c71766f 100644 --- a/src/ska_telmodel/sdp/examples.py +++ b/src/ska_telmodel/sdp/examples.py @@ -143,6 +143,11 @@ def get_sdp_config_example(version: str, scan_type: str = "science_A") -> dict: SDP_SCAN = {"scan_type": "science_A"} +MID_SDP_SCAN = { + "interface": "https://schema.skatelescope.org/ska-mid-sdp-scan/1.0", + "scan_id": 1, +} + def get_sdp_scan_example(version: str, scan_type: str = "science_A") -> dict: """Generate examples for SDP scan command @@ -160,6 +165,19 @@ def get_sdp_scan_example(version: str, scan_type: str = "science_A") -> dict: raise ValueError(f"Could not generate example for schema {version}!") +def get_sdp_mid_scan_example(version: str) -> dict: + """Generate examples for Mid SDP scan command + + :param version: Version URI of resource assignment schema + :returns: Example dictionary + """ + + if version.startswith(SDP_MID_SCAN_PREFIX + "1.0"): + return copy.deepcopy(MID_SDP_SCAN) + + raise ValueError(f"Could not generate example for schema {version}!") + + SDP_RECEIVE_ADDR_MAP = { "science_A": { "host": [ diff --git a/src/ska_telmodel/sdp/schema.py b/src/ska_telmodel/sdp/schema.py index b3b87ba5..258c1ede 100644 --- a/src/ska_telmodel/sdp/schema.py +++ b/src/ska_telmodel/sdp/schema.py @@ -5,6 +5,7 @@ Used for checking SDP strings for conformance from schema import Schema, Optional, And, Or, Literal from .. import _common from .version import * +from inspect import cleandoc def get_sbi_name_schema(version: str, strict: bool) -> Schema: @@ -134,7 +135,7 @@ def get_sdp_config_schema(version: str, strict: bool) -> Schema: def get_sdp_scan_schema(version: str, strict: bool) -> Schema: """ - Returns a schema to verify a SDP scan parameter + Returns a schema to verify a Low SDP scan parameter :param version: SDP Interface version :param strict: Strict mode @@ -150,6 +151,45 @@ def get_sdp_scan_schema(version: str, strict: bool) -> Schema: ) +def get_sdp_mid_scan_schema(version: str, strict: bool) -> Schema: + """ + Returns a schema to verify a Mid SDP scan parameter + + :param version: Mid SDP Interface version + :param strict: Strict mode + """ + + items = { + Literal( + "interface", + description=cleandoc( + """ + URI of JSON schema applicable to this JSON payload. + """ + ), + ): str, + Literal( + "scan_id", + description=cleandoc( + """ + Scan ID to associate with the data. + + The scan ID and SBI ID are used together to uniquely associate + the data taken with the telescope configuration in effect at + the moment of observation. + """ + ), + ): int, + } + + return _common.make( + "Mid SDP scan", + version, + strict, + items, + ) + + def get_sdp_receive_addresses_schema(version: str, strict: bool) -> Schema: """ Returns a schema to verify an SDP receive address map diff --git a/src/ska_telmodel/sdp/version.py b/src/ska_telmodel/sdp/version.py index d7212706..98c056f0 100644 --- a/src/ska_telmodel/sdp/version.py +++ b/src/ska_telmodel/sdp/version.py @@ -4,6 +4,7 @@ import logging SDP_ASSIGNRES_PREFIX = "https://schema.skatelescope.org/ska-sdp-assignres/" SDP_CONFIG_PREFIX = "https://schema.skatelescope.org/ska-sdp-configure/" SDP_SCAN_PREFIX = "https://schema.skatelescope.org/ska-sdp-scan/" +SDP_MID_SCAN_PREFIX = "https://schema.skatelescope.org/ska-mid-sdp-scan/" SDP_RECVADDRS_PREFIX = "https://schema.skatelescope.org/ska-sdp-recvaddrs/" SDP_CONFIG_VER0 = SDP_CONFIG_PREFIX + "0" @@ -20,6 +21,7 @@ _PREFIXES = [ SDP_ASSIGNRES_PREFIX, SDP_CONFIG_PREFIX, SDP_SCAN_PREFIX, + SDP_MID_SCAN_PREFIX, SDP_RECVADDRS_PREFIX, ] diff --git a/src/ska_telmodel/tmc/examples.py b/src/ska_telmodel/tmc/examples.py index 59fd18dd..a5acda4d 100644 --- a/src/ska_telmodel/tmc/examples.py +++ b/src/ska_telmodel/tmc/examples.py @@ -47,6 +47,11 @@ TMC_SCAN_1_0 = { "scan_id": 1, } +TMC_MID_SCAN_1_0 = { + "interface": "https://schema.skatelescope.org/ska-tmc-scan/1.0", + "scan_id": 1, +} + TMC_ASSIGNEDRES_1_0 = { "interface": "https://schema.skatelescope.org/ska-low-tmc-assignedresources/1.0", "mccs": { @@ -110,6 +115,17 @@ def get_tmc_scan_example(version: str): raise ValueError(f"Could not generate example for schema {version})!") +def get_tmc_mid_scan_example(version: str): + """Generate examples for TMC MID scan strings. + + :param version: Version URI of configuration format + """ + if version.startswith(tmc_mid_scan_uri(1, 0)): + return copy.deepcopy(TMC_MID_SCAN_1_0) + + raise ValueError(f"Could not generate example for schema {version})!") + + def get_tmc_assignedres_example(version: str, empty: bool = False): """Generate examples for TMC assigned resources strings. diff --git a/src/ska_telmodel/tmc/schema.py b/src/ska_telmodel/tmc/schema.py index 7e13effd..277ca7b5 100644 --- a/src/ska_telmodel/tmc/schema.py +++ b/src/ska_telmodel/tmc/schema.py @@ -435,6 +435,40 @@ def get_tmc_scan_schema(version: str, strict: bool) -> Schema: return _common.make("Low TMC scan", version, strict, items) +def get_tmc_mid_scan_schema(version: str, strict: bool) -> Schema: + """SKA Mid Monitoring and Control scan schema + + :param version: Interface Version URI + :param strict: Schema strictness + :return: Schema + """ + + items = { + Literal( + "interface", + description=cleandoc( + """ + URI of JSON schema applicable to this JSON payload. + """ + ), + ): str, + Literal( + "scan_id", + description=cleandoc( + """ + Scan ID to associate with the data. + + The scan ID and SBI ID are used together to uniquely associate + the data taken with the telescope configuration in effect at + the moment of observation. + """ + ), + ): int, + } + + return _common.make("Mid TMC scan", version, strict, items) + + def get_tmc_releaseres_schema(version: str, strict: bool) -> Schema: """SKA Low Monitoring and Control resources release schema diff --git a/src/ska_telmodel/tmc/version.py b/src/ska_telmodel/tmc/version.py index 272ac94c..351456de 100644 --- a/src/ska_telmodel/tmc/version.py +++ b/src/ska_telmodel/tmc/version.py @@ -9,9 +9,15 @@ TMC_ASSIGNEDRES_PREFIX = ( "https://schema.skatelescope.org/ska-low-tmc-assignedresources/" ) +TMC_MID_SCAN_PREFIX = "https://schema.skatelescope.org/ska-tmc-scan/" + + # JSON strings for MVP-Low for PI#10 tmc_assignedres_uri = partial(interface_uri, TMC_ASSIGNEDRES_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) tmc_releaseres_uri = partial(interface_uri, TMC_RELEASERES_PREFIX) + +# JSON strings for Mid for PI#11 +tmc_mid_scan_uri = partial(interface_uri, TMC_MID_SCAN_PREFIX) \ No newline at end of file diff --git a/tests/test_csp_config.py b/tests/test_csp_config.py index aabb367e..a526f72f 100644 --- a/tests/test_csp_config.py +++ b/tests/test_csp_config.py @@ -208,3 +208,27 @@ def test_schema_example_with_invalid_parameters(): msg = "Unknown schema URI kind for example: https://invalid_uri/2.0!" with pytest.raises(ValueError, match=msg): example_by_uri("https://invalid_uri/2.0") + + +def test_mid_csp_scan(): + """Test CSP scan schema correctly validates the + expected JSON. + """ + scan_ver = csp_mid_scan_uri(1,0) + validate(scan_ver, example_by_uri(scan_ver), 2) + + # Check that an error is raised if 'scan_id' is omitted + csp_scan_erronous = example_by_uri(scan_ver) + del csp_scan_erronous["scan_id"] + validate(scan_ver, csp_scan_erronous, 0) + with pytest.raises(ValueError): + validate(scan_ver, csp_scan_erronous, 1) + + # Try with interface version given as part of JSON object + csp_scan_versioned = example_by_uri(scan_ver) + csp_scan_versioned["interface"] = scan_ver + validate(None, csp_scan_versioned, 1) + + # Check invalid version raises error + with pytest.raises(ValueError, match=r"Could not generate example"): + example_by_uri(CSP_MID_SCAN_PREFIX + "0.0") diff --git a/tests/test_sdp_schemas.py b/tests/test_sdp_schemas.py index 20035180..b70991c0 100644 --- a/tests/test_sdp_schemas.py +++ b/tests/test_sdp_schemas.py @@ -96,6 +96,13 @@ def test_sdp_scan(): validate(scan_ver1, example_by_uri(scan_ver1), 2) +def test_mid_sdp_scan(): + + scan_ver1 = SDP_MID_SCAN_PREFIX + "1.0" + + validate(scan_ver1, example_by_uri(scan_ver1), 2) + + def test_sdp_invalid_examples(): with pytest.raises(ValueError, match=r"Could not generate example"): -- GitLab From 8e8e3d6ac7fe6878caa89d4ad4af710566bdbe13 Mon Sep 17 00:00:00 2001 From: Andrew McDermott Date: Thu, 24 Jun 2021 10:15:58 +0100 Subject: [PATCH 2/2] blackify added code --- src/ska_telmodel/csp/examples.py | 2 +- src/ska_telmodel/csp/schema.py | 5 +++-- src/ska_telmodel/csp/version.py | 2 +- src/ska_telmodel/tmc/version.py | 2 +- tests/test_csp_config.py | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ska_telmodel/csp/examples.py b/src/ska_telmodel/csp/examples.py index 6d3f301f..198f1c85 100644 --- a/src/ska_telmodel/csp/examples.py +++ b/src/ska_telmodel/csp/examples.py @@ -250,7 +250,7 @@ def get_csp_mid_scan_example(version: str): :param version: Version URI of configuration format """ - if version.startswith(csp_mid_scan_uri(1,0)): + if version.startswith(csp_mid_scan_uri(1, 0)): return copy.deepcopy(CSP_MID_SCAN_1_0) raise ValueError(f"Could not generate example for schema {version})!") diff --git a/src/ska_telmodel/csp/schema.py b/src/ska_telmodel/csp/schema.py index 806d35a0..3526ecc2 100644 --- a/src/ska_telmodel/csp/schema.py +++ b/src/ska_telmodel/csp/schema.py @@ -591,9 +591,10 @@ def get_csp_config_schema(version: str, strict: bool) -> Schema: else: raise ValueError(f"Invalid JSON Schema URI {version}") + def get_csp_mid_scan_schema(version: str, strict: bool) -> Schema: """SKA Mid CSP scan Schema - + :param version: Interface Version URI :param strict: Schema strictness :return: Schema @@ -622,4 +623,4 @@ def get_csp_mid_scan_schema(version: str, strict: bool) -> Schema: ): int, } - return _common.make("Mid CSP scan", version, strict, items) \ No newline at end of file + return _common.make("Mid CSP scan", version, strict, items) diff --git a/src/ska_telmodel/csp/version.py b/src/ska_telmodel/csp/version.py index 48ac9257..02e99c19 100644 --- a/src/ska_telmodel/csp/version.py +++ b/src/ska_telmodel/csp/version.py @@ -63,4 +63,4 @@ def get_csp_config_version( return csp_interface_version -csp_mid_scan_uri = partial(interface_uri, CSP_MID_SCAN_PREFIX) \ No newline at end of file +csp_mid_scan_uri = partial(interface_uri, CSP_MID_SCAN_PREFIX) diff --git a/src/ska_telmodel/tmc/version.py b/src/ska_telmodel/tmc/version.py index 351456de..96e019b8 100644 --- a/src/ska_telmodel/tmc/version.py +++ b/src/ska_telmodel/tmc/version.py @@ -20,4 +20,4 @@ tmc_scan_uri = partial(interface_uri, TMC_SCAN_PREFIX) tmc_releaseres_uri = partial(interface_uri, TMC_RELEASERES_PREFIX) # JSON strings for Mid for PI#11 -tmc_mid_scan_uri = partial(interface_uri, TMC_MID_SCAN_PREFIX) \ No newline at end of file +tmc_mid_scan_uri = partial(interface_uri, TMC_MID_SCAN_PREFIX) diff --git a/tests/test_csp_config.py b/tests/test_csp_config.py index a526f72f..b0789785 100644 --- a/tests/test_csp_config.py +++ b/tests/test_csp_config.py @@ -214,7 +214,7 @@ def test_mid_csp_scan(): """Test CSP scan schema correctly validates the expected JSON. """ - scan_ver = csp_mid_scan_uri(1,0) + scan_ver = csp_mid_scan_uri(1, 0) validate(scan_ver, example_by_uri(scan_ver), 2) # Check that an error is raised if 'scan_id' is omitted -- GitLab