Skip to content

Commit

Permalink
Fixing PR review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
punamverma committed Nov 20, 2023
1 parent 91d8e87 commit 3a2ccc5
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 64 deletions.
4 changes: 3 additions & 1 deletion monitoring/monitorlib/clients/flight_planning/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ class PlanningActivityError(QueryError):
class FlightPlannerClient(ABC):
"""Client to interact with a USS as a user performing flight planning activities and as the test director preparing for tests involving flight planning activities."""

participant_id: ParticipantID

def __init__(self, participant_id: ParticipantID):
self.participant_id = participant_id
self.created_flight_ids: Set[str] = set()
self.created_flight_ids: Set[FlightID] = set()
super(FlightPlannerClient, self).__init__()

# ===== Emulation of user actions =====
Expand Down
6 changes: 2 additions & 4 deletions monitoring/monitorlib/clients/flight_planning/client_scd.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def _inject(
]
if response.activity_result == PlanningActivityResult.Completed:
if response.flight_plan_status in created_status:
self.created_flight_ids.add(str(flight_id))
self.created_flight_ids.add(flight_id)

self._plan_statuses[flight_id] = response.flight_plan_status
return response
Expand Down Expand Up @@ -196,7 +196,7 @@ def try_end_flight(
)
if resp.result == scd_api.DeleteFlightResponseResult.Closed:
del self._plan_statuses[flight_id]
self.created_flight_ids.discard(str(flight_id))
self.created_flight_ids.discard(flight_id)

else:
self._plan_statuses[flight_id] = response.flight_plan_status
Expand Down Expand Up @@ -260,6 +260,4 @@ def clear_area(self, area: Volume4D) -> TestPreparationActivityResponse:
else:
errors = [f"[{resp.outcome.timestamp}]: {resp.outcome.message}"]

self.created_flight_ids.clear()

return TestPreparationActivityResponse(errors=errors, queries=[query])
5 changes: 2 additions & 3 deletions monitoring/monitorlib/clients/flight_planning/client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _inject(
]
if resp.planning_result == PlanningActivityResult.Completed:
if resp.flight_plan_status in created_status:
self.created_flight_ids.add(str(flight_plan_id))
self.created_flight_ids.add(flight_plan_id)

response = PlanningActivityResponse(
flight_id=flight_plan_id,
Expand Down Expand Up @@ -150,7 +150,7 @@ def try_end_flight(
raise PlanningActivityError(
f"Response to delete flight plan could not be parsed: {str(e)}", query
)
self.created_flight_ids.discard(str(flight_id))
self.created_flight_ids.discard(flight_id)
response = PlanningActivityResponse(
flight_id=flight_id,
queries=[query],
Expand Down Expand Up @@ -220,7 +220,6 @@ def clear_area(self, area: Volume4D) -> TestPreparationActivityResponse:
raise PlanningActivityError(
f"Response to clear area could not be parsed: {str(e)}", query
)
self.created_flight_ids.clear()
if resp.outcome.success:
errors = None
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Dict

from implicitdict import ImplicitDict
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple, Optional, Set, get_type_hints
from typing import Tuple, Optional, Set
from urllib.parse import urlparse
from implicitdict import ImplicitDict
from monitoring.monitorlib import infrastructure, fetch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from typing import Optional
from urllib.parse import urlsplit
from monitoring.monitorlib.temporal import Time
import arrow

from monitoring.monitorlib.clients.flight_planning.client import FlightPlannerClient
from monitoring.uss_qualifier.resources.astm.f3548.v21 import DSSInstanceResource
from monitoring.uss_qualifier.resources.astm.f3548.v21.dss import DSSInstance
from monitoring.uss_qualifier.resources.flight_planning import (
FlightIntentsResource,
)
from monitoring.uss_qualifier.resources.flight_planning.flight_intent import (
FlightIntent,
)
from monitoring.uss_qualifier.resources.flight_planning.flight_planners import (
FlightPlannerResource,
)
from monitoring.monitorlib.geotemporal import Volume4DCollection
from monitoring.monitorlib.clients.flight_planning.flight_info import FlightInfo

from monitoring.uss_qualifier.resources.interuss.mock_uss.client import (
MockUSSClient,
MockUSSResource,
Expand All @@ -36,13 +35,11 @@
plan_flight,
delete_flight,
)
from implicitdict import StringBasedDateTime
from datetime import datetime


class GetOpResponseDataValidationByUSS(TestScenario):
flight_1: FlightIntent
flight_2: FlightIntent
flight_1: FlightInfo
flight_2: FlightInfo

tested_uss_client: FlightPlannerClient
control_uss: MockUSSClient
Expand Down Expand Up @@ -70,31 +67,24 @@ def __init__(
)
raise ScenarioCannotContinueError(msg)

t = Time(arrow.utcnow().datetime)
_flight_intents = {
k: FlightIntent.from_flight_info_template(v)
for k, v in flight_intents.get_flight_intents().items()
k: v.resolve(t) for k, v in flight_intents.get_flight_intents().items()
}

extents = []
for intent in _flight_intents.values():
extents.extend(intent.request.operational_intent.volumes)
extents.extend(intent.request.operational_intent.off_nominal_volumes)
self._intents_extent = Volume4DCollection.from_interuss_scd_api(
extents
).bounding_volume.to_f3548v21()
extents.append(intent.basic_information.area.bounding_volume)
self._intents_extent = Volume4DCollection(extents).bounding_volume.to_f3548v21()

try:
(self.flight_1, self.flight_2,) = (
_flight_intents["flight_1"],
_flight_intents["flight_2"],
)

assert not Volume4DCollection.from_interuss_scd_api(
self.flight_1.request.operational_intent.volumes
).intersects_vol4s(
Volume4DCollection.from_interuss_scd_api(
self.flight_2.request.operational_intent.volumes
)
assert not self.flight_1.basic_information.area.intersects_vol4s(
self.flight_2.basic_information.area
), "flight_1 and flight_2 must not intersect"

except KeyError as e:
Expand Down Expand Up @@ -141,10 +131,10 @@ def _tested_uss_plans_deconflicted_flight_near_existing_flight(self):
self,
"Control_uss plans flight 2",
self.control_uss_client,
FlightInfo.from_scd_inject_flight_request(self.flight_2.request),
self.flight_2,
)

flight_2_oi_ref = validator.expect_shared(self.flight_2.request)
validator.expect_shared(self.flight_2)

self.begin_test_step(
"Precondition - check tested_uss has no subscription in flight 2 area"
Expand All @@ -163,11 +153,11 @@ def _tested_uss_plans_deconflicted_flight_near_existing_flight(self):
self,
"Tested_uss plans flight 1",
self.tested_uss_client,
FlightInfo.from_scd_inject_flight_request(self.flight_1.request),
self.flight_1,
)

flight_1_oi_ref = validator.expect_shared(
self.flight_1.request,
validator.expect_shared(
self.flight_1,
)

self.begin_test_step("Validate flight2 GET interaction")
Expand All @@ -186,7 +176,7 @@ def _tested_uss_plans_deconflicted_flight_near_existing_flight(self):
)

def _tested_uss_unable_to_plan_flight_near_invalid_shared_existing_flight(self):
req = self.flight_2.request
flight_info = self.flight_2
# Modifying the request with invalid data
behavior = MockUssFlightBehavior(
modify_sharing_methods=["GET", "POST"],
Expand All @@ -196,7 +186,6 @@ def _tested_uss_unable_to_plan_flight_near_invalid_shared_existing_flight(self):
},
)

flight_info = FlightInfo.from_scd_inject_flight_request(req)
additional_fields = {"behavior": behavior}

_, self.flight_2_id = plan_flight(
Expand All @@ -223,7 +212,7 @@ def _tested_uss_unable_to_plan_flight_near_invalid_shared_existing_flight(self):
self,
"Tested_uss attempts to plan flight 1, expect failure",
self.tested_uss_client,
FlightInfo.from_scd_inject_flight_request(self.flight_1.request),
self.flight_1,
)

self.begin_test_step("Validate flight 1 not shared by tested_uss")
Expand Down
50 changes: 42 additions & 8 deletions monitoring/uss_qualifier/scenarios/astm/utm/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
OperationalIntentReference,
)

from monitoring.monitorlib.clients.flight_planning.flight_info import (
UasState,
AirspaceUsageState,
)
from monitoring.uss_qualifier.common_data_definitions import Severity
from monitoring.uss_qualifier.resources.astm.f3548.v21.dss import DSSInstance
from monitoring.uss_qualifier.resources.flight_planning.flight_planner import (
FlightPlanner,
)
from monitoring.monitorlib.clients.flight_planning.flight_info import FlightInfo
from monitoring.uss_qualifier.scenarios.astm.utm.evaluation import (
validate_op_intent_details,
)
Expand Down Expand Up @@ -141,7 +146,9 @@ def expect_not_shared(self) -> None:
self._scenario.end_test_step()

def expect_shared(
self, flight_intent: InjectFlightRequest, skip_if_not_found: bool = False
self,
flight_intent: Union[InjectFlightRequest, FlightInfo],
skip_if_not_found: bool = False,
) -> Optional[OperationalIntentReference]:
"""Validate that operational intent information was correctly shared for a flight intent.
Expand Down Expand Up @@ -177,8 +184,23 @@ def expect_shared(
if modified_oi_ref is None:
if not skip_if_not_found:
if (
flight_intent.operational_intent.state
== OperationalIntentState.Activated
(isinstance(flight_intent, InjectFlightRequest))
and (
flight_intent.operational_intent.state
== OperationalIntentState.Activated
)
) or (
isinstance(flight_intent, FlightInfo)
and (
(
flight_intent.basic_information.uas_state
== UasState.Nominal
)
and (
flight_intent.basic_information.usage_state
== AirspaceUsageState.InUse
)
)
):
with self._scenario.check(
"Operational intent for active flight not deleted",
Expand Down Expand Up @@ -258,13 +280,25 @@ def expect_shared(
with self._scenario.check(
"Correct operational intent details", [self._flight_planner.participant_id]
) as check:
error_text = validate_op_intent_details(
oi_full.details,
flight_intent.operational_intent.priority,
Volume4DCollection.from_interuss_scd_api(
priority = (
flight_intent.operational_intent.priority
if isinstance(flight_intent, InjectFlightRequest)
else flight_intent.astm_f3548_21.priority
)
if isinstance(flight_intent, InjectFlightRequest):
priority = flight_intent.operational_intent.priority
vols = Volume4DCollection.from_interuss_scd_api(
flight_intent.operational_intent.volumes
+ flight_intent.operational_intent.off_nominal_volumes
).bounding_volume.to_f3548v21(),
)
elif isinstance(flight_intent, FlightInfo):
priority = flight_intent.astm_f3548_21.priority
vols = flight_intent.basic_information.area

error_text = validate_op_intent_details(
oi_full.details,
priority,
vols.bounding_volume.to_f3548v21(),
)
if error_text:
check.record_failed(
Expand Down
21 changes: 4 additions & 17 deletions monitoring/uss_qualifier/scenarios/flight_planning/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def plan_flight_intent(
flight_intent: InjectFlightRequest,
) -> Tuple[InjectFlightResponse, Optional[str]]:
"""Plan a flight intent that should result in success.
Note: This method will be deprecated in favor of plan_flight
Note: This method is deprecated in favor of plan_flight
This function implements the test step described in
plan_flight_intent.md.
Expand Down Expand Up @@ -203,7 +203,7 @@ def submit_flight_intent(
flight_id: Optional[str] = None,
) -> Tuple[InjectFlightResponse, Optional[str]]:
"""Submit a flight intent with an expected result.
Note: This method will be deprecated in favor of submit_flight
Note: This method is deprecated in favor of submit_flight
A check fail is considered by default of high severity and as such will raise an ScenarioCannotContinueError.
The severity of each failed check may be overridden if needed.
Expand Down Expand Up @@ -273,7 +273,7 @@ def delete_flight_intent(
flight_id: str,
) -> DeleteFlightResponse:
"""Delete an existing flight intent that should result in success.
Note: This method will be deprecated in favor of delete_flight
Note: This method is deprecated in favor of delete_flight
A check fail is considered of high severity and as such will raise an ScenarioCannotContinueError.
Expand Down Expand Up @@ -319,7 +319,7 @@ def cleanup_flights(
scenario: TestScenarioType, flight_planners: Iterable[FlightPlanner]
) -> None:
"""Remove flights during a cleanup test step.
Note: This method will be deprecated in favor of cleanup_flights_fp_client
Note: This method is deprecated in favor of cleanup_flights_fp_client
This function assumes:
* `scenario` is currently cleaning up (cleanup has started)
Expand Down Expand Up @@ -468,12 +468,7 @@ def request_flight(
additional_fields: Optional[dict] = None,
) -> Tuple[PlanningActivityResponse, Query, str]:
"""
This method is needed till we are able to have checks with PlanningActivityResult.
Uses FlightPlannerClient to plan the flight
Args:
flight_planner:
flight_info:
flight_id:
Returns:
* Response from planning activity to request new flight or update existing flight
Expand Down Expand Up @@ -502,15 +497,7 @@ def request_flight(
def cleanup_flight(
flight_planner: FlightPlannerClient, flight_id: str
) -> Tuple[PlanningActivityResponse, Query]:
"""
This method is required till we are able to have checks with PlanningActivityResult
Args:
flight_planner:
flight_id:
Returns:

"""
try:
resp = flight_planner.try_end_flight(flight_id, ExecutionStyle.IfAllowed)
except PlanningActivityError as e:
Expand Down

0 comments on commit 3a2ccc5

Please sign in to comment.