Skip to content

Commit 34d55a1

Browse files
authored
[uss_qualifier/scenarios/utm/data_exchange_validation] Factor away as test step fragment 'get_mock_uss_interactions' (#833)
1 parent eeac880 commit 34d55a1

File tree

11 files changed

+160
-140
lines changed

11 files changed

+160
-140
lines changed

monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/get_op_data_validation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mock_uss via a GET request. This assertion is only valid, however, if tested_us
5151
intent details in a different way -- specifically, a notification due to a pre-existing subscription. In this test
5252
step, we determine if tested_uss had a pre-existing subscription by:
5353

54-
#### [checking if mock_uss sent a notification to tested_uss](test_steps/query_mock_uss_interactions.md)
54+
#### [checking if mock_uss sent a notification to tested_uss](../../../interuss/mock_uss/get_mock_uss_interactions.md)
5555

5656
### [Validate flight2 GET interaction, if no notification test step](test_steps/validate_get_operational_intent.md)
5757
This step is skipped if a notification to tested_uss was found in the previous step since tested_uss obtained the operational intent details of flight 2 without needing to perform a GET interaction.
@@ -99,7 +99,7 @@ mock_uss via a GET request. This assertion is only valid, however, if tested_us
9999
intent details in a different way -- specifically, a notification due to a pre-existing subscription. In this test
100100
step, we determine if tested_uss had a pre-existing subscription by:
101101

102-
#### [Check if mock_uss sent a notification to tested_uss](test_steps/query_mock_uss_interactions.md)
102+
#### [Check if mock_uss sent a notification to tested_uss](../../../interuss/mock_uss/get_mock_uss_interactions.md)
103103

104104
### [Validate flight2 GET interaction, if no notification test step](test_steps/validate_get_operational_intent.md)
105105
This step is skipped if a notification to tested_uss was found in the previous step.

monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/get_op_data_validation.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,16 @@
4040
from monitoring.uss_qualifier.scenarios.astm.utm.data_exchange_validation.test_steps.expected_interactions_test_steps import (
4141
expect_no_interuss_post_interactions,
4242
expect_mock_uss_receives_op_intent_notification,
43-
mock_uss_interactions,
44-
notif_op_intent_id_filter,
45-
operation_filter,
46-
direction_filter,
4743
)
4844
from monitoring.monitorlib.clients.mock_uss.mock_uss_scd_injection_api import (
4945
MockUssFlightBehavior,
5046
)
47+
from monitoring.uss_qualifier.scenarios.interuss.mock_uss.test_steps import (
48+
get_mock_uss_interactions,
49+
operation_filter,
50+
direction_filter,
51+
notif_op_intent_id_filter,
52+
)
5153
from monitoring.uss_qualifier.scenarios.scenario import (
5254
TestScenario,
5355
ScenarioCannotContinueError,
@@ -199,7 +201,7 @@ def _plan_successfully_test_case(self, times: Dict[TimeDuringTest, Time]):
199201
self.begin_test_step(
200202
"Check for notification to tested_uss due to subscription in flight 2 area"
201203
)
202-
tested_uss_notifications, _ = mock_uss_interactions(
204+
tested_uss_notifications, _ = get_mock_uss_interactions(
203205
self,
204206
self.mock_uss,
205207
flight_2_planning_time,
@@ -211,7 +213,7 @@ def _plan_successfully_test_case(self, times: Dict[TimeDuringTest, Time]):
211213

212214
self.begin_test_step("Validate flight2 GET interaction, if no notification")
213215
if not tested_uss_notifications:
214-
tested_uss_get_requests, query = mock_uss_interactions(
216+
tested_uss_get_requests, query = get_mock_uss_interactions(
215217
self,
216218
self.mock_uss,
217219
flight_1_planning_time,
@@ -322,7 +324,7 @@ def _plan_unsuccessfully_test_case(self, times: Dict[TimeDuringTest, Time]):
322324
self.begin_test_step(
323325
"Check for notification to tested_uss due to subscription in flight 2 area"
324326
)
325-
tested_uss_notifications, _ = mock_uss_interactions(
327+
tested_uss_notifications, _ = get_mock_uss_interactions(
326328
self,
327329
self.mock_uss,
328330
flight_2_planning_time,
@@ -334,7 +336,7 @@ def _plan_unsuccessfully_test_case(self, times: Dict[TimeDuringTest, Time]):
334336

335337
self.begin_test_step("Validate flight2 GET interaction, if no notification")
336338
if not tested_uss_notifications:
337-
tested_uss_get_requests, query = mock_uss_interactions(
339+
tested_uss_get_requests, query = get_mock_uss_interactions(
338340
self,
339341
self.mock_uss,
340342
flight_1_planning_time,
Lines changed: 9 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
from __future__ import annotations
22

3-
from datetime import datetime, timedelta
4-
import re
5-
from typing import Callable, Dict, List, Tuple, Optional, Set
3+
from datetime import datetime
4+
from typing import Set
65

7-
import arrow
86
from implicitdict import StringBasedDateTime, ImplicitDict
9-
from uas_standards.astm.f3548.v21 import api
107
from uas_standards.astm.f3548.v21.api import (
118
OperationID,
129
EntityID,
1310
PutOperationalIntentDetailsParameters,
14-
OperationalIntentReference,
1511
)
1612

17-
from monitoring.monitorlib.clients.mock_uss.interactions import Interaction
1813
from monitoring.monitorlib.clients.mock_uss.interactions import QueryDirection
1914
from monitoring.monitorlib.delay import sleep
20-
from monitoring.monitorlib.fetch import QueryError, Query
2115
from monitoring.uss_qualifier.resources.interuss.mock_uss.client import MockUSSClient
2216
from monitoring.uss_qualifier.scenarios.astm.utm.data_exchange_validation.test_steps.wait import (
2317
wait_in_intervals,
2418
MaxTimeToWaitForSubscriptionNotificationSeconds as max_wait_time,
2519
)
20+
from monitoring.uss_qualifier.scenarios.interuss.mock_uss.test_steps import (
21+
get_mock_uss_interactions,
22+
operation_filter,
23+
direction_filter,
24+
)
2625
from monitoring.uss_qualifier.scenarios.scenario import TestScenarioType
2726

2827

@@ -42,7 +41,7 @@ def expect_mock_uss_receives_op_intent_notification(
4241
"""
4342

4443
# Check for 'notification found' will be done periodically by waiting for a duration till max_wait_time
45-
found, query = wait_in_intervals(mock_uss_interactions)(
44+
found, query = wait_in_intervals(get_mock_uss_interactions)(
4645
scenario,
4746
mock_uss,
4847
st,
@@ -77,7 +76,7 @@ def expect_no_interuss_post_interactions(
7776
max_wait_time,
7877
"we have to wait the longest it may take a USS to send a notification before we can establish that they didn't send a notification",
7978
)
80-
interactions, query = mock_uss_interactions(
79+
interactions, query = get_mock_uss_interactions(
8180
scenario,
8281
mock_uss,
8382
st,
@@ -112,96 +111,3 @@ def expect_no_interuss_post_interactions(
112111
details=f"Notification for operational intent ID {req.operational_intent_id} triggered by subscriptions {', '.join([sub.subscription_id for sub in req.subscriptions])} with timestamp {interaction.query.request.timestamp}.",
113112
query_timestamps=[query.request.timestamp],
114113
)
115-
116-
117-
def mock_uss_interactions(
118-
scenario: TestScenarioType,
119-
mock_uss: MockUSSClient,
120-
since: StringBasedDateTime,
121-
*is_applicable: Callable[[Interaction], bool],
122-
) -> Tuple[List[Interaction], Query]:
123-
"""Retrieve mock_uss interactions given specific criteria."""
124-
125-
with scenario.check(
126-
"Mock USS interactions logs retrievable", [mock_uss.participant_id]
127-
) as check:
128-
try:
129-
interactions, query = mock_uss.get_interactions(since)
130-
scenario.record_query(query)
131-
except QueryError as e:
132-
for q in e.queries:
133-
scenario.record_query(q)
134-
check.record_failed(
135-
summary=f"Error from mock_uss when attempting to get interactions since {since}",
136-
details=f"{str(e)}\n\nStack trace:\n{e.stacktrace}",
137-
query_timestamps=[q.request.timestamp for q in e.queries],
138-
)
139-
140-
return filter_interactions(interactions, is_applicable), query
141-
142-
143-
def filter_interactions(
144-
interactions: List[Interaction], filters: Iterable[Callable[[Interaction], bool]]
145-
) -> List[Interaction]:
146-
return list(filter(lambda x: all(f(x) for f in filters), interactions))
147-
148-
149-
def notif_op_intent_id_filter(
150-
op_intent_id: EntityID,
151-
) -> Callable[[Interaction], bool]:
152-
"""Returns an `is_applicable` function that detects whether an op intent notification refers to the specified operational intent."""
153-
154-
def is_applicable(interaction: Interaction) -> bool:
155-
if "json" in interaction.query.request and interaction.query.request.json:
156-
return (
157-
interaction.query.request.json.get("operational_intent_id", None)
158-
== op_intent_id
159-
)
160-
return False
161-
162-
return is_applicable
163-
164-
165-
def base_url_filter(
166-
base_url: str,
167-
) -> Callable[[Interaction], bool]:
168-
"""Returns an `is_applicable` function that detects if the request in an interaction is sent to the given base url."""
169-
170-
def is_applicable(interaction: Interaction) -> bool:
171-
return interaction.query.request.url.startswith(base_url)
172-
173-
return is_applicable
174-
175-
176-
def direction_filter(
177-
direction: QueryDirection,
178-
) -> Callable[[Interaction], bool]:
179-
"""Returns an `is_applicable` filter that filters according to query direction."""
180-
181-
def is_applicable(interaction: Interaction) -> bool:
182-
return interaction.direction == direction
183-
184-
return is_applicable
185-
186-
187-
def operation_filter(
188-
op_id: OperationID,
189-
**query_params: str,
190-
) -> Callable[[Interaction], bool]:
191-
"""
192-
Returns an `is_applicable` filter that filters according to operation ID.
193-
If the operation has query parameters, they must be provided through `**query_params`.
194-
195-
Raises:
196-
KeyError: if query_params contains a non-existing parameter
197-
IndexError: if query_params is missing a parameter
198-
"""
199-
op = api.OPERATIONS[op_id]
200-
op_path = op.path.format(**query_params) # raises KeyError, IndexError
201-
202-
def is_applicable(interaction: Interaction) -> bool:
203-
return interaction.query.request.method == op.verb and re.search(
204-
op_path, interaction.query.request.url
205-
)
206-
207-
return is_applicable

monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/query_mock_uss_interactions.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/validate_get_operational_intent.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
This step verifies that a USS makes a GET request to get the intent_details of an existing operation when needed as per ASTM F3548-21 by checking the interuss interactions of mock uss
44

5-
## 🛑 Mock USS interactions logs retrievable check
6-
**[interuss.mock_uss.hosted_instance.ExposeInterface](../../../../../requirements/interuss/mock_uss/hosted_instance.md)**.
5+
## [Get Mock USS interactions logs](../../../../interuss/mock_uss/get_mock_uss_interactions.md)
76

87
## 🛑 Expect GET request when no notification check
98
**[astm.f3548.v21.SCD0035](../../../../../requirements/astm/f3548/v21.md)**

monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/validate_no_notification_operational_intent.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
This step verifies when a flight is not created, it is also not notified by checking the interuss interactions of mock_uss instance.
44

5-
## 🛑 Mock USS interactions logs retrievable check
6-
**[interuss.mock_uss.hosted_instance.ExposeInterface](../../../../../requirements/interuss/mock_uss/hosted_instance.md)**.
5+
## [Get Mock USS interactions logs](../../../../interuss/mock_uss/get_mock_uss_interactions.md)
76

87
## ℹ️ Mock USS interaction can be parsed check
98
**[interuss.mock_uss.hosted_instance.ExposeInterface](../../../../../requirements/interuss/mock_uss/hosted_instance.md)**.

monitoring/uss_qualifier/scenarios/astm/utm/data_exchange_validation/test_steps/validate_notification_operational_intent.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
This step verifies that, when creating or modifying an operational intent, a USS sent the required notification for a relevant subscription owned by a mock_uss instance by checking the interactions of that mock_uss instance.
44

5-
## 🛑 Mock USS interactions logs retrievable check
6-
**[interuss.mock_uss.hosted_instance.ExposeInterface](../../../../../requirements/interuss/mock_uss/hosted_instance.md)**.
5+
## [Get Mock USS interactions logs](../../../../interuss/mock_uss/get_mock_uss_interactions.md)
76

87
## ⚠️ Expect Notification sent check
98
As per **[astm.f3548.v21.SCD0085](../../../../../requirements/astm/f3548/v21.md)**, the notification should be sent by a

monitoring/uss_qualifier/scenarios/astm/utm/subscription_notifications/test_steps/validate_notification_received.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
This step verifies that a Tested USS successfully received a notification about a relevant operational intent from a Mock USS instance.
44
This is done by checking the interactions of that Mock USS instance.
55

6-
## 🛑 Mock USS interactions logs retrievable check
7-
**[interuss.mock_uss.hosted_instance.ExposeInterface](../../../../../requirements/interuss/mock_uss/hosted_instance.md)**.
6+
## [Get Mock USS interactions logs](../../../../interuss/mock_uss/get_mock_uss_interactions.md)
87
Mock USS provides a GET endpoint to retrieve all the interactions that took place between Mock USS
98
and other USSes after a particular time.
10-
If there is any error retrieving these interactions, this check will fail.
119
These interactions also include the notifications sent and received by Mock USS.
1210

1311
## ⚠️ Mock USS sends valid notification check

monitoring/uss_qualifier/scenarios/astm/utm/subscription_notifications/test_steps/validate_notification_received.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
from implicitdict import StringBasedDateTime, ImplicitDict
2-
from typing import Callable, List, Tuple
3-
from monitoring.uss_qualifier.scenarios.scenario import TestScenarioType
4-
from monitoring.uss_qualifier.resources.interuss.mock_uss.client import MockUSSClient
5-
from datetime import datetime
6-
from monitoring.uss_qualifier.scenarios.astm.utm.data_exchange_validation.test_steps.expected_interactions_test_steps import (
7-
mock_uss_interactions,
2+
from typing import List, Tuple
3+
4+
from monitoring.uss_qualifier.scenarios.interuss.mock_uss.test_steps import (
5+
get_mock_uss_interactions,
86
operation_filter,
97
direction_filter,
108
notif_op_intent_id_filter,
119
base_url_filter,
1210
)
11+
from monitoring.uss_qualifier.scenarios.scenario import TestScenarioType
12+
from monitoring.uss_qualifier.resources.interuss.mock_uss.client import MockUSSClient
13+
from datetime import datetime
1314
from monitoring.uss_qualifier.scenarios.astm.utm.data_exchange_validation.test_steps.wait import (
1415
wait_in_intervals,
1516
)
1617
from monitoring.monitorlib.clients.mock_uss.interactions import (
1718
Interaction,
1819
QueryDirection,
1920
)
20-
from monitoring.monitorlib.fetch import (
21-
QueryType,
22-
)
2321
from uas_standards.astm.f3548.v21.api import (
2422
OperationID,
2523
PutOperationalIntentDetailsParameters,
@@ -55,7 +53,7 @@ def expect_tested_uss_receives_notification_from_mock_uss(
5553
"Mock USS sends valid notification", mock_uss.participant_id
5654
) as check:
5755
try:
58-
interactions, query = wait_in_intervals(mock_uss_interactions)(
56+
interactions, query = wait_in_intervals(get_mock_uss_interactions)(
5957
scenario,
6058
mock_uss,
6159
StringBasedDateTime(interactions_since_time),
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Get mock_uss interactions test step fragment
2+
This step obtains interactions of interest from mock_uss.
3+
4+
## 🛑 Mock USS interactions logs retrievable check
5+
The Mock USSes provide a GET endpoint to retrieve all the interactions that took place between them and other USSes
6+
after a particular time.
7+
If there is any error retrieving these interactions, this check will fail as per **[interuss.mock_uss.hosted_instance.ExposeInterface](../../../requirements/interuss/mock_uss/hosted_instance.md)**.

0 commit comments

Comments
 (0)