Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Jan 8, 2024
1 parent 59c726c commit 4af7674
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 119 deletions.
69 changes: 20 additions & 49 deletions monitoring/monitorlib/fetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
import json
import os
import uuid
import jwt
from typing import Dict, Optional, List, Union

from enum import Enum
from typing import Dict, Optional, List, Union
from urllib.parse import urlparse

import flask
from loguru import logger
import jwt
import requests
import urllib3
import yaml
from implicitdict import ImplicitDict, StringBasedDateTime
from loguru import logger
from yaml.representer import Representer

from implicitdict import ImplicitDict, StringBasedDateTime
from monitoring.monitorlib import infrastructure
from monitoring.monitorlib.errors import stacktrace_string
from monitoring.monitorlib.rid import RIDVersion
Expand Down Expand Up @@ -180,8 +179,8 @@ def describe_flask_response(resp: flask.Response, elapsed_s: float):


class QueryType(str, Enum):

# ASTM F3411-19 and F3411-22a (RID)
# DSS endpoints
F3411v19DSSSearchIdentificationServiceAreas = (
"astm.f3411.v19.dss.searchIdentificationServiceAreas"
)
Expand Down Expand Up @@ -217,9 +216,6 @@ class QueryType(str, Enum):
"astm.f3411.v22a.dss.deleteIdentificationServiceArea"
)

F3411v19DSSSearchFlights = "astm.f3411.v19.dss.searchFlights"
F3411v22aDSSSearchFlights = "astm.f3411.v22a.dss.searchFlights"

F3411v19DSSSearchSubscriptions = "astm.f3411.v19.dss.searchSubscriptions"
F3411v22aDSSSearchSubscriptions = "astm.f3411.v22a.dss.searchSubscriptions"

Expand All @@ -235,26 +231,19 @@ class QueryType(str, Enum):
F3411v19DSSDeleteSubscription = "astm.f3411.v19.dss.deleteSubscription"
F3411v22aDSSDeleteSubscription = "astm.f3411.v22a.dss.deleteSubscription"

# USS endpoints
F3411v19USSSearchFlights = "astm.f3411.v19.uss.searchFlights"
F3411v22aUSSSearchFlights = "astm.f3411.v22a.uss.searchFlights"

F3411v19USSPostIdentificationServiceArea = (
"astm.f3411.v19.uss.postIdentificationServiceArea"
)
F3411v22aUSSPostIdentificationServiceArea = (
"astm.f3411.v22a.uss.postIdentificationServiceArea"
)

# Flight injection (test harness)

F3411v19USSCreateTest = "rid.f3411.v19.sp.createTest"
F3411v22aUSSCreateTest = "rid.f3411.v22a.sp.createTest"

F3411v19USSDeleteTest = "rid.f3411.v19.sp.deleteTest"
F3411v22aUSSDeleteTest = "rid.f3411.v22a.sp.deleteTest"

# RID flight details endpoint that a USS provides (!= DSS)
F3411v22aUSSGetDisplayData = "rid.f3411.v22a.sp.getDisplayData"
F3411v19USSGetDisplayData = "rid.f3411.v19.sp.getDisplayData"
F3411v22aUSSGetFlightDetails = "rid.f3411.v22a.sp.getDetails"
F3411v19USSGetFlightDetails = "rid.f3411.v19.sp.getDetails"
F3411v22aUSSGetFlightDetails = "astm.f3411.v22a.uss.getFlightDetails"
F3411v19USSGetFlightDetails = "astm.f3411.v19.uss.getFlightDetails"

# ASTM F3548-21
F3548v21DSSQueryOperationalIntentReferences = (
Expand Down Expand Up @@ -333,18 +322,18 @@ class QueryType(str, Enum):
"interuss.automated_testing.rid.v1.observation.getDetails"
)

# Flight injection (test harness)
InterussRIDAutomatedTestingV1CreateTest = (
"interuss.automated_testing.rid.v1.injection.createTest"
)

InterussRIDAutomatedTestingV1DeleteTest = (
"interuss.automated_testing.rid.v1.injection.deleteTest"
)

def __str__(self):
return self.value

@staticmethod
def flight_details(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19USSGetFlightDetails
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aUSSGetFlightDetails
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def dss_get_isa(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
Expand Down Expand Up @@ -381,24 +370,6 @@ def dss_delete_isa(rid_version: RIDVersion):
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def sp_create_test(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19USSCreateTest
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aUSSCreateTest
else:
raise ValueError(f"Unsupported RID version: {rid_version}")

@staticmethod
def sp_delete_test(rid_version: RIDVersion):
if rid_version == RIDVersion.f3411_19:
return QueryType.F3411v19USSDeleteTest
elif rid_version == RIDVersion.f3411_22a:
return QueryType.F3411v22aUSSDeleteTest
else:
raise ValueError(f"Unsupported RID version: {rid_version}")


class Query(ImplicitDict):
request: RequestDescription
Expand Down
12 changes: 2 additions & 10 deletions monitoring/monitorlib/fetch/rid.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,6 @@ def set_participant_id(self, participant_id: str) -> None:
else:
raise NotImplementedError(f"Cannot set participant_id")

def set_query_type(self, query_type: QueryType) -> None:
if self.v19_query is not None:
self.v19_query.query_type = query_type
elif self.v22a_query is not None:
self.v22a_query.query_type = query_type
else:
raise NotImplementedError(f"Cannot set query_type")


class FetchedISA(RIDQuery):
"""Version-independent representation of an ISA read from the DSS."""
Expand Down Expand Up @@ -1035,7 +1027,7 @@ def uss_flights(
else "false",
},
scope=v19.constants.Scope.Read,
query_type=QueryType.F3411v19USSGetDisplayData,
query_type=QueryType.F3411v19USSSearchFlights,
participant_id=participant_id,
)
return FetchedUSSFlights(v19_query=query)
Expand All @@ -1056,7 +1048,7 @@ def uss_flights(
flights_url,
params=params,
scope=v22a.constants.Scope.DisplayProvider,
query_type=QueryType.F3411v22aUSSGetDisplayData,
query_type=QueryType.F3411v19USSSearchFlights,
participant_id=participant_id,
)
return FetchedUSSFlights(v22a_query=query)
Expand Down
7 changes: 3 additions & 4 deletions monitoring/uss_qualifier/resources/netrid/observers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
self.local_debug = local_debug

def observe_system(
self, rect: s2sphere.LatLngRect, rid_version: RIDVersion
self, rect: s2sphere.LatLngRect
) -> Tuple[Optional[observation_api.GetDisplayDataResponse], fetch.Query]:
url = "/display_data?view={},{},{},{}".format(
rect.lo().lat().degrees,
Expand All @@ -49,7 +49,7 @@ def observe_system(
url,
scope=Scope.Observe,
participant_id=self.participant_id,
query_type=QueryType.flight_details(rid_version),
query_type=QueryType.InterUSSRIDObservationV1GetDisplayData,
)
try:
result = (
Expand All @@ -65,7 +65,7 @@ def observe_system(
return result, query

def observe_flight_details(
self, flight_id: str, rid_version: RIDVersion
self, flight_id: str
) -> Tuple[Optional[observation_api.GetDetailsResponse], fetch.Query]:
query = fetch.query_and_describe(
self.session,
Expand All @@ -77,7 +77,6 @@ def observe_flight_details(
)
# Record query metadata for later use in the aggregate checks
query.participant_id = self.participant_id
query.query_type = QueryType.flight_details(rid_version)
try:
result = (
ImplicitDict.parse(
Expand Down
12 changes: 4 additions & 8 deletions monitoring/uss_qualifier/resources/netrid/service_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,25 @@ def __init__(
)
self.local_debug = local_debug

def submit_test(
self, request: CreateTestParameters, test_id: str, rid_version: RIDVersion
) -> fetch.Query:
def submit_test(self, request: CreateTestParameters, test_id: str) -> fetch.Query:
return fetch.query_and_describe(
self.injection_client,
"PUT",
url=f"/tests/{test_id}",
json=request,
scope=SCOPE_RID_QUALIFIER_INJECT,
participant_id=self.participant_id,
query_type=fetch.QueryType.sp_create_test(rid_version),
query_type=fetch.QueryType.InterussRIDAutomatedTestingV1CreateTest,
)

def delete_test(
self, test_id: str, version: str, rid_version: RIDVersion
) -> fetch.Query:
def delete_test(self, test_id: str, version: str) -> fetch.Query:
return fetch.query_and_describe(
self.injection_client,
"DELETE",
url=f"/tests/{test_id}/{version}",
scope=SCOPE_RID_QUALIFIER_INJECT,
participant_id=self.participant_id,
query_type=fetch.QueryType.sp_delete_test(rid_version),
query_type=fetch.QueryType.InterussRIDAutomatedTestingV1DeleteTest,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ def _dp_display_data_details_times_step(self):
if (
query.status_code == 200
and query.has_field_with_value("query_type")
and (
query.query_type == QueryType.F3411v19USSGetFlightDetails
or query.query_type == QueryType.F3411v22aUSSGetFlightDetails
)
and query.query_type == QueryType.InterUSSRIDObservationV1GetDetails
):
relevant_queries.append(query)

Expand Down Expand Up @@ -257,8 +254,8 @@ def _sp_flights_area_times_step(self):
for query in all_queries:
if query.has_field_with_value("query_type") and (
# TODO find a cleaner way than checking for version here
query.query_type == QueryType.F3411v19USSGetDisplayData
or query.query_type == QueryType.F3411v22aUSSGetDisplayData
query.query_type == QueryType.F3411v19USSSearchFlights
or query.query_type == QueryType.F3411v22aUSSSearchFlights
):
relevant_queries.append(query)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,12 @@ def _isa_missing_outline(self, create_isa_url: str, json_body: Dict[str, Any]):
url=create_isa_url,
scope=self.write_scope,
json=payload,
query_type=QueryType.dss_create_isa(self._dss.rid_version),
)
if self._dss.rid_version == RIDVersion.f3411_19:
rid_query = ChangedISA(v19_query=q)
rid_query.set_query_type(
QueryType.F3411v19DSSCreateIdentificationServiceArea
)
elif self._dss.rid_version == RIDVersion.f3411_22a:
rid_query = ChangedISA(v22a_query=q)
rid_query.set_query_type(
QueryType.F3411v22aDSSCreateIdentificationServiceArea
)
else:
raise ValueError(f"Unknown RID version: {self._dss.rid_version}")

Expand Down Expand Up @@ -287,17 +282,12 @@ def _isa_missing_volume(self, create_isa_url: str, json_body: Dict[str, Any]):
url=create_isa_url,
scope=self.write_scope,
json=payload,
query_type=QueryType.dss_create_isa(self._dss.rid_version),
)
if self._dss.rid_version == RIDVersion.f3411_19:
rid_query = ChangedISA(v19_query=q)
rid_query.set_query_type(
QueryType.F3411v19DSSCreateIdentificationServiceArea
)
elif self._dss.rid_version == RIDVersion.f3411_22a:
rid_query = ChangedISA(v22a_query=q)
rid_query.set_query_type(
QueryType.F3411v22aDSSCreateIdentificationServiceArea
)
else:
raise ValueError(f"Unknown RID version: {self._dss.rid_version}")

Expand All @@ -324,17 +314,12 @@ def _isa_missing_extents(self, create_isa_url: str, json_body: Dict[str, Any]):
url=create_isa_url,
scope=self.write_scope,
json=payload,
query_type=QueryType.dss_create_isa(self._dss.rid_version),
)
if self._dss.rid_version == RIDVersion.f3411_19:
rid_query = ChangedISA(v19_query=q)
rid_query.set_query_type(
QueryType.F3411v19DSSCreateIdentificationServiceArea
)
elif self._dss.rid_version == RIDVersion.f3411_22a:
rid_query = ChangedISA(v22a_query=q)
rid_query.set_query_type(
QueryType.F3411v22aDSSCreateIdentificationServiceArea
)
else:
raise ValueError(f"Unknown RID version: {self._dss.rid_version}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def run(self, context: ExecutionContext):

def _inject_flights(self):
(self._injected_flights, self._injected_tests) = injection.inject_flights(
self, self._flights_data, self._service_providers, self._rid_version
self, self._flights_data, self._service_providers
)

def _poll_unauthenticated_during_flights(self):
Expand Down Expand Up @@ -238,9 +238,7 @@ def cleanup(self):
sp = matching_sps[0]
check = self.check("Successful test deletion", [sp.participant_id])
try:
query = sp.delete_test(
injected_test.test_id, injected_test.version, self._rid_version
)
query = sp.delete_test(injected_test.test_id, injected_test.version)
self.record_query(query)
if query.status_code != 200:
raise ValueError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def run(self, context: ExecutionContext):

def _inject_flights(self):
(self._injected_flights, self._injected_tests) = injection.inject_flights(
self, self._flights_data, self._service_providers, self._rid_version
self, self._flights_data, self._service_providers
)

def _poll_during_flights(self):
Expand Down Expand Up @@ -128,9 +128,7 @@ def cleanup(self):
sp = matching_sps[0]
check = self.check("Successful test deletion", [sp.participant_id])
try:
query = sp.delete_test(
injected_test.test_id, injected_test.version, self._rid_version
)
query = sp.delete_test(injected_test.test_id, injected_test.version)
self.record_query(query)
if query.status_code != 200:
raise ValueError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def evaluate_system_instantaneously(
if perform_observation:
self._test_scenario.begin_test_step("Observer polling")
for observer in observers:
(observation, query) = observer.observe_system(rect, self._rid_version)
(observation, query) = observer.observe_system(rect)
self._test_scenario.record_query(query)
self._evaluate_observation(
observer,
Expand Down
3 changes: 1 addition & 2 deletions monitoring/uss_qualifier/scenarios/astm/netrid/injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def inject_flights(
test_scenario: TestScenario,
flights_data_res: FlightDataResource,
service_providers_res: NetRIDServiceProviders,
rid_version: RIDVersion,
) -> Tuple[List[InjectedFlight], List[InjectedTest]]:
test_id = str(uuid.uuid4())
test_flights = flights_data_res.get_test_flights()
Expand All @@ -55,7 +54,7 @@ def inject_flights(
with test_scenario.check(
"Successful injection", [target.participant_id]
) as check:
query = target.submit_test(p, test_id, rid_version)
query = target.submit_test(p, test_id)
test_scenario.record_query(query)

if query.status_code != 200:
Expand Down
4 changes: 2 additions & 2 deletions monitoring/uss_qualifier/scenarios/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
QueryType.F3411v19USSPostIdentificationServiceArea,
QueryType.F3411v22aUSSPostIdentificationServiceArea,
# When querying for display data and flight details, we don't always know the participant ID
QueryType.F3411v19USSGetDisplayData,
QueryType.F3411v22aUSSGetDisplayData,
QueryType.InterUSSRIDObservationV1GetDisplayData,
QueryType.InterUSSRIDObservationV1GetDetails,
QueryType.F3411v19USSGetFlightDetails,
QueryType.F3411v22aUSSGetFlightDetails,
]
Expand Down
Loading

0 comments on commit 4af7674

Please sign in to comment.