|
1 | 1 | from datetime import timedelta |
| 2 | +from urllib.parse import urlparse |
2 | 3 |
|
3 | | -from uas_standards.astm.f3548.v21.api import OperationalIntentDetails, Volume4D |
| 4 | +from uas_standards.astm.f3548.v21.api import ( |
| 5 | + OperationalIntentDetails, |
| 6 | + OperationalIntentReference, |
| 7 | + UssAvailabilityState, |
| 8 | + Volume4D, |
| 9 | +) |
4 | 10 |
|
5 | 11 | from monitoring.monitorlib.geotemporal import Volume4DCollection |
6 | 12 | from monitoring.monitorlib.scd import priority_of |
7 | 13 |
|
8 | 14 | NUMERIC_PRECISION = 0.001 |
9 | 15 |
|
10 | 16 |
|
| 17 | +def validate_op_intent_reference( |
| 18 | + uss_oi: OperationalIntentReference, |
| 19 | + dss_oi: OperationalIntentReference, |
| 20 | +) -> str | None: |
| 21 | + # this function assumes all fields required by the OpenAPI definition are present as the format validation |
| 22 | + # should have been performed by OpIntentValidator._evaluate_op_intent_validation before |
| 23 | + errors_text: list[str] = [] |
| 24 | + |
| 25 | + def append_err(name: str, uss_value: str, dss_value: str): |
| 26 | + errors_text.append( |
| 27 | + f"{name} reported by USS ({uss_value}) does not match the one published to the DSS ({dss_value})" |
| 28 | + ) |
| 29 | + return |
| 30 | + |
| 31 | + if uss_oi.version != dss_oi.version: |
| 32 | + append_err("Version", str(uss_oi.version), str(dss_oi.version)) |
| 33 | + |
| 34 | + # use str.lower() to tolerate case mismatch for string values |
| 35 | + if uss_oi.id.lower() != dss_oi.id.lower(): |
| 36 | + append_err("ID", uss_oi.id, dss_oi.id) |
| 37 | + if uss_oi.manager.lower() != dss_oi.manager.lower(): |
| 38 | + append_err("Manager", uss_oi.manager, dss_oi.manager) |
| 39 | + if uss_oi.state.lower() != dss_oi.state.lower(): |
| 40 | + append_err("State", uss_oi.state, dss_oi.state) |
| 41 | + if uss_oi.subscription_id.lower() != dss_oi.subscription_id.lower(): |
| 42 | + append_err("Subscription ID", uss_oi.subscription_id, dss_oi.subscription_id) |
| 43 | + if uss_oi.uss_availability.lower() != dss_oi.uss_availability.lower(): |
| 44 | + # tolerate empty value if unknown |
| 45 | + if ( |
| 46 | + len(uss_oi.uss_availability) != 0 |
| 47 | + or dss_oi.uss_availability != UssAvailabilityState.Unknown |
| 48 | + ): |
| 49 | + append_err( |
| 50 | + "USS availability", uss_oi.uss_availability, dss_oi.uss_availability |
| 51 | + ) |
| 52 | + |
| 53 | + if uss_oi.uss_base_url != dss_oi.uss_base_url: |
| 54 | + # tolerate differences in URL that have no impact |
| 55 | + uss_url = urlparse(uss_oi.uss_base_url) |
| 56 | + dss_url = urlparse(dss_oi.uss_base_url) |
| 57 | + if ( |
| 58 | + uss_url.scheme != dss_url.scheme |
| 59 | + or uss_url.netloc != dss_url.netloc |
| 60 | + or uss_url.path != dss_url.path |
| 61 | + ): |
| 62 | + append_err("USS base URL", uss_oi.uss_base_url, dss_oi.uss_base_url) |
| 63 | + |
| 64 | + # tolerate USS starting later than published on DSS |
| 65 | + if uss_oi.time_start.value.datetime < dss_oi.time_start.value.datetime - timedelta( |
| 66 | + seconds=NUMERIC_PRECISION |
| 67 | + ): |
| 68 | + append_err("Start time", uss_oi.time_start.value, dss_oi.time_start.value) |
| 69 | + |
| 70 | + # tolerate USS ending sooner than published on DSS |
| 71 | + if uss_oi.time_end.value.datetime > dss_oi.time_end.value.datetime + timedelta( |
| 72 | + seconds=NUMERIC_PRECISION |
| 73 | + ): |
| 74 | + append_err("End time", uss_oi.time_start.value, dss_oi.time_start.value) |
| 75 | + |
| 76 | + return "; ".join(errors_text) if errors_text else None |
| 77 | + |
| 78 | + |
11 | 79 | def validate_op_intent_details( |
12 | 80 | op_intent_details: OperationalIntentDetails, |
13 | 81 | expected_priority: int, |
|
0 commit comments