-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'interuss/main' into idempotency
- Loading branch information
Showing
65 changed files
with
2,511 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
29 changes: 29 additions & 0 deletions
29
monitoring/mock_uss/dynamic_configuration/configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
|
||
from implicitdict import ImplicitDict | ||
from monitoring.mock_uss import require_config_value, webapp | ||
from monitoring.mock_uss.config import KEY_BEHAVIOR_LOCALITY | ||
from monitoring.monitorlib.locality import Locality, LocalityCode | ||
from monitoring.monitorlib.multiprocessing import SynchronizedValue | ||
|
||
|
||
require_config_value(KEY_BEHAVIOR_LOCALITY) | ||
|
||
|
||
class DynamicConfiguration(ImplicitDict): | ||
locale: LocalityCode | ||
|
||
|
||
db = SynchronizedValue( | ||
DynamicConfiguration(locale=LocalityCode(webapp.config[KEY_BEHAVIOR_LOCALITY])), | ||
decoder=lambda b: ImplicitDict.parse( | ||
json.loads(b.decode("utf-8")), DynamicConfiguration | ||
), | ||
capacity_bytes=10000, | ||
) | ||
|
||
|
||
def get_locality() -> Locality: | ||
with db as tx: | ||
code = tx.locale | ||
return Locality.from_locale(code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Tuple | ||
|
||
import flask | ||
from implicitdict import ImplicitDict | ||
|
||
from monitoring.mock_uss import webapp | ||
from monitoring.mock_uss.auth import requires_scope, MOCK_USS_CONFIG_SCOPE | ||
from monitoring.mock_uss.dynamic_configuration.configuration import db, get_locality | ||
from monitoring.monitorlib.clients.mock_uss.locality import ( | ||
PutLocalityRequest, | ||
GetLocalityResponse, | ||
) | ||
from monitoring.monitorlib.locality import Locality | ||
|
||
|
||
@webapp.route("/configuration/locality", methods=["GET"]) | ||
def locality_get() -> Tuple[str, int]: | ||
return flask.jsonify( | ||
GetLocalityResponse(locality_code=get_locality().locality_code()) | ||
) | ||
|
||
|
||
@webapp.route("/configuration/locality", methods=["PUT"]) | ||
@requires_scope([MOCK_USS_CONFIG_SCOPE]) # TODO: use separate public key for this | ||
def locality_set() -> Tuple[str, int]: | ||
"""Set the locality of the mock_uss.""" | ||
try: | ||
json = flask.request.json | ||
if json is None: | ||
raise ValueError("Request did not contain a JSON payload") | ||
req: PutLocalityRequest = ImplicitDict.parse(json, PutLocalityRequest) | ||
except ValueError as e: | ||
msg = f"Change locality unable to parse JSON: {str(e)}" | ||
return msg, 400 | ||
|
||
# Make sure this is a valid locality | ||
try: | ||
Locality.from_locale(req.locality_code) | ||
except ValueError as e: | ||
msg = f"Invalid locality_code: {str(e)}" | ||
return msg, 400 | ||
|
||
with db as tx: | ||
tx.locale = req.locality_code | ||
|
||
return flask.jsonify( | ||
GetLocalityResponse(locality_code=get_locality().locality_code()) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import List, Optional, Union | ||
|
||
from monitoring.monitorlib.clients.flight_planning.test_preparation import ( | ||
TestPreparationActivityResponse, | ||
) | ||
|
||
from monitoring.monitorlib.clients.flight_planning.flight_info import ( | ||
FlightInfo, | ||
FlightID, | ||
ExecutionStyle, | ||
) | ||
from monitoring.monitorlib.clients.flight_planning.planning import ( | ||
PlanningActivityResponse, | ||
) | ||
from monitoring.monitorlib.fetch import Query | ||
from monitoring.monitorlib.geotemporal import Volume4D | ||
|
||
|
||
class PlanningActivityError(Exception): | ||
queries: List[Query] | ||
|
||
def __init__( | ||
self, message: str, queries: Optional[Union[Query, List[Query]]] = None | ||
): | ||
super(PlanningActivityError, self).__init__(message) | ||
if queries is None: | ||
self.queries = [] | ||
elif isinstance(queries, Query): | ||
self.queries = [queries] | ||
else: | ||
self.queries = queries | ||
|
||
|
||
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.""" | ||
|
||
# ===== Emulation of user actions ===== | ||
|
||
@abstractmethod | ||
def try_plan_flight( | ||
self, flight_info: FlightInfo, execution_style: ExecutionStyle | ||
) -> PlanningActivityResponse: | ||
"""Instruct the USS to emulate a normal user trying to plan the described flight. | ||
Raises: | ||
* PlanningActivityError | ||
""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def try_update_flight( | ||
self, | ||
flight_id: FlightID, | ||
updated_flight_info: FlightInfo, | ||
execution_style: ExecutionStyle, | ||
) -> PlanningActivityResponse: | ||
"""Instruct the USS to emulate a normal user trying to update the specified flight as described. | ||
Raises: | ||
* PlanningActivityError | ||
""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def try_end_flight( | ||
self, flight_id: FlightID, execution_style: ExecutionStyle | ||
) -> PlanningActivityResponse: | ||
"""Instruct the USS to emulate a normal user trying to end the specified flight. | ||
Raises: | ||
* PlanningActivityError | ||
""" | ||
raise NotImplementedError() | ||
|
||
# ===== Test preparation activities ===== | ||
|
||
@abstractmethod | ||
def report_readiness(self) -> TestPreparationActivityResponse: | ||
"""Acting as test director, ask the USS about its readiness to use its flight planning interface for automated testing. | ||
Raises: | ||
* PlanningActivityError | ||
""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def clear_area(self, area: Volume4D) -> TestPreparationActivityResponse: | ||
"""Acting as test director, instruct the USS to close/end/remove all flights it manages within the specified area. | ||
Raises: | ||
* PlanningActivityError | ||
""" | ||
raise NotImplementedError() |
Oops, something went wrong.