Skip to content

Commit

Permalink
[uss_qualifier] op-data-validation: cleanup flights even if creation …
Browse files Browse the repository at this point in the history
…seemingly failed (#774)
  • Loading branch information
Shastick authored Sep 11, 2024
1 parent b50155e commit b926b65
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
18 changes: 8 additions & 10 deletions monitoring/monitorlib/clients/flight_planning/client_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def _inject(
for k, v in additional_fields.items():
req[k] = v

# We record the flight regardless of the outcome of the query that will be executed
# below. This should ward off unexpected exceptions, timeouts or error responses returned
# by the server despite the flight having been created.
# The cleanup logic supports cleanup attempts for flights that do not exist.
self.created_flight_ids.add(flight_plan_id)

op = api.OPERATIONS[api.OperationID.UpsertFlightPlan]
url = op.path.format(flight_plan_id=flight_plan_id)
query = query_and_describe(
Expand All @@ -80,15 +86,6 @@ def _inject(
f"Response to plan flight could not be parsed: {str(e)}", query
)

created_status = [
FlightPlanStatus.Planned,
FlightPlanStatus.OkToFly,
FlightPlanStatus.OffNominal,
]
if resp.planning_result == PlanningActivityResult.Completed:
if resp.flight_plan_status in created_status:
self.created_flight_ids.add(flight_plan_id)

response = PlanningActivityResponse(
flight_id=flight_plan_id,
queries=[query],
Expand Down Expand Up @@ -139,7 +136,8 @@ def try_end_flight(
participant_id=self.participant_id,
query_type=QueryType.InterUSSFlightPlanningV1DeleteFlightPlan,
)
if query.status_code != 200:
# 404 is acceptable, as the end state we are interested in is already effective.
if query.status_code not in [200, 404]:
raise PlanningActivityError(
f"Attempt to delete flight plan returned status {query.status_code} rather than 200 as expected",
query,
Expand Down
22 changes: 8 additions & 14 deletions monitoring/uss_qualifier/scenarios/flight_planning/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@
from typing import Optional, Tuple, Iterable, Set, Dict

import arrow

from monitoring.monitorlib.geotemporal import end_time_of
from uas_standards.interuss.automated_testing.flight_planning.v1.api import (
BasicFlightPlanInformationUsageState,
BasicFlightPlanInformationUasState,
)

from monitoring.monitorlib.clients.flight_planning.client import PlanningActivityError
from monitoring.monitorlib.clients.flight_planning.planning import (
PlanningActivityResponse,
PlanningActivityResult,
FlightPlanStatus,
)

from monitoring.monitorlib.clients.flight_planning.client_v1 import (
FlightPlannerClient,
)
from monitoring.monitorlib.clients.flight_planning.flight_info import (
FlightInfo,
ExecutionStyle,
)
from monitoring.monitorlib.clients.flight_planning.planning import (
PlanningActivityResponse,
PlanningActivityResult,
FlightPlanStatus,
)
from monitoring.monitorlib.fetch import QueryError, Query

from monitoring.monitorlib.geotemporal import end_time_of
from monitoring.uss_qualifier.common_data_definitions import Severity
from monitoring.uss_qualifier.scenarios.scenario import TestScenarioType

Expand Down Expand Up @@ -341,7 +338,6 @@ def request_flight(
def cleanup_flight(
flight_planner: FlightPlannerClient, flight_id: str
) -> Tuple[PlanningActivityResponse, Query]:

try:
resp = flight_planner.try_end_flight(flight_id, ExecutionStyle.IfAllowed)
except PlanningActivityError as e:
Expand Down Expand Up @@ -431,10 +427,8 @@ def cleanup_flights(
)
continue

if (
resp.activity_result == PlanningActivityResult.Completed
and resp.flight_plan_status == FlightPlanStatus.Closed
):
# A non-existing flight is considered successfully deleted
if query.status_code in [200, 404]:
removed.append(flight_id)
else:
check.record_failed(
Expand Down

0 comments on commit b926b65

Please sign in to comment.