Skip to content

Commit 819765b

Browse files
authored
[uss_qualifier] expand OIR implicit sub handling scenario (#1026)
1 parent 24ad8cf commit 819765b

File tree

4 files changed

+271
-91
lines changed

4 files changed

+271
-91
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
from typing import Optional
2+
3+
from uas_standards.astm.f3548.v21.api import EntityID, SubscriptionID
4+
5+
from monitoring.monitorlib.fetch import QueryError
6+
from monitoring.uss_qualifier.resources.astm.f3548.v21.dss import DSSInstance
7+
from monitoring.uss_qualifier.scenarios.scenario import TestScenarioType
8+
9+
# The InterUSS DSS implementation will set an OIR's subscription ID to 00000000-0000-4000-8000-000000000000
10+
# when the OIR is not attached to any subscription, as the OpenAPI spec does not allow the value to be empty.
11+
# Other implementations may use a different value. One way to check that an OIR is not attached to any subscription
12+
# is to attempt to retrieve the subscription reportedly attached to it: if a 404 is returned then we may assume
13+
# no subscription is attached.
14+
# Note that this is only allowed for OIRs in the ACCEPTED state.
15+
NULL_SUBSCRIPTION_ID = "00000000-0000-4000-8000-000000000000"
16+
17+
18+
def step_oir_has_correct_subscription(
19+
scenario: TestScenarioType,
20+
dss: DSSInstance,
21+
oir_id: EntityID,
22+
expected_sub_id: Optional[SubscriptionID],
23+
):
24+
"""
25+
Ensure that an OIR is currently attached to the specified subscription,
26+
or not attached to any subscription if the passed subscription ID is None.
27+
28+
This fragment will fetch the OIR from the DSS.
29+
"""
30+
31+
step_name = (
32+
"OIR is not attached to any subscription"
33+
if expected_sub_id is None
34+
else "OIR is attached to expected subscription"
35+
)
36+
scenario.begin_test_step(step_name)
37+
check_oir_has_correct_subscription(
38+
scenario,
39+
dss,
40+
oir_id,
41+
expected_sub_id,
42+
)
43+
scenario.end_test_step()
44+
45+
46+
def check_oir_has_correct_subscription(
47+
scenario: TestScenarioType,
48+
dss: DSSInstance,
49+
oir_id: EntityID,
50+
expected_sub_id: Optional[SubscriptionID],
51+
):
52+
with scenario.check(
53+
"Get operational intent reference by ID", dss.participant_id
54+
) as check:
55+
try:
56+
oir, q = dss.get_op_intent_reference(oir_id)
57+
scenario.record_query(q)
58+
except QueryError as qe:
59+
scenario.record_queries(qe.queries)
60+
check.record_failed(
61+
summary="Could not get OIR",
62+
details=f"Failed to get OIR with error code {qe.cause_status_code}: {qe.msg}",
63+
query_timestamps=qe.query_timestamps,
64+
)
65+
66+
sub_is_as_expected = False
67+
referenced_sub_was_found_when_non_expected = False
68+
if expected_sub_id is None:
69+
# See comment on NULL_SUBSCRIPTION_ID
70+
# ASTM may at some point decide to tolerate accepting empty returned values here,
71+
# but in the meantime we simply attempt to obtain the subscription and check that it does not exist
72+
if oir.subscription_id == NULL_SUBSCRIPTION_ID:
73+
# Sub ID explicitly set to the value representing the null subscription: all good
74+
sub_is_as_expected = True
75+
elif oir.subscription_id is None:
76+
# Sub ID not set at all: not compliant with the spec, but not wrong with regard to which subscription should be attached to the OIR
77+
sub_is_as_expected = True
78+
else:
79+
# If the subscription ID is defined and not set to the known 'null' value, we assume that the DSS used another
80+
# placeholder for the non-existing subscription, and we check that it does not exist.
81+
with scenario.check(
82+
"Subscription referenced by the OIR does not exist"
83+
) as check:
84+
sub = dss.get_subscription(oir.subscription_id)
85+
scenario.record_query(sub)
86+
if sub.status_code not in [200, 404]:
87+
check.record_failed(
88+
summary="Failed to try to obtain the subscription referenced by the OIR",
89+
details=f"Failed in an unexpected way while querying subscription with ID {oir.subscription_id}: expected a 404 or 200, but got {sub.status_code}",
90+
query_timestamps=[sub.request.timestamp],
91+
)
92+
if sub.status_code == 200:
93+
referenced_sub_was_found_when_non_expected = True
94+
else:
95+
sub_is_as_expected = oir.subscription_id == expected_sub_id
96+
97+
attached_check_name = (
98+
"OIR is not attached to a subscription"
99+
if expected_sub_id is None
100+
else f"OIR is attached to expected subscription"
101+
)
102+
103+
with scenario.check(attached_check_name, dss.participant_id) as check:
104+
if referenced_sub_was_found_when_non_expected:
105+
check.record_failed(
106+
summary="OIR is attached to a subscription although it should not be",
107+
details=f"Expected OIR to not be attached to any subscription, but the referenced subscription {oir.subscription_id} does exist.",
108+
query_timestamps=[sub.request.timestamp],
109+
)
110+
if not sub_is_as_expected:
111+
check.record_failed(
112+
summary="OIR is not attached to the correct subscription",
113+
details=f"Expected OIR to be attached to subscription {expected_sub_id}, but it is attached to {oir.subscription_id}",
114+
query_timestamps=[q.request.timestamp],
115+
)

monitoring/uss_qualifier/scenarios/astm/utm/dss/oir_explicit_sub_handling.py

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,15 @@
3131
from monitoring.uss_qualifier.scenarios.astm.utm.dss.fragments.oir import (
3232
crud as oir_fragments,
3333
)
34+
from monitoring.uss_qualifier.scenarios.astm.utm.dss.fragments.oir import (
35+
step_oir_has_correct_subscription,
36+
)
3437
from monitoring.uss_qualifier.scenarios.astm.utm.dss.fragments.sub import (
3538
crud as sub_fragments,
3639
)
3740
from monitoring.uss_qualifier.scenarios.scenario import TestScenario
3841
from monitoring.uss_qualifier.suites.suite import ExecutionContext
3942

40-
# The InterUSS DSS implementation will set an OIR's subscription ID to 00000000-0000-4000-8000-000000000000
41-
# when the OIR is not attached to any subscription, as the OpenAPI spec does not allow the value to be empty.
42-
# Other implementations may use a different value. One way to check that an OIR is not attached to any subscription
43-
# is to attempt to retrieve the subscription reportedly attached to it: if a 404 is returned then we may assume
44-
# no subscription is attached.
45-
# Note that this is only allowed for OIRs in the ACCEPTED state.
46-
NULL_SUBSCRIPTION_ID = "00000000-0000-4000-8000-000000000000"
47-
4843

4944
class OIRExplicitSubHandling(TestScenario):
5045
OIR_TYPE = register_resource_type(401, "Operational Intent Reference")
@@ -377,76 +372,13 @@ def _step_update_oir_with_sufficient_explicit_sub(self, is_replacement: bool):
377372
def _step_oir_has_correct_subscription(
378373
self, expected_sub_id: Optional[SubscriptionID]
379374
):
380-
step_check_name = (
381-
"OIR is not attached to any subscription"
382-
if expected_sub_id is None
383-
else "OIR is attached to expected subscription"
384-
)
385-
self.begin_test_step(step_check_name)
386-
with self.check("Get operational intent reference by ID", self._pid) as check:
387-
try:
388-
oir, q = self._dss.get_op_intent_reference(self._oir_id)
389-
self.record_query(q)
390-
except QueryError as qe:
391-
self.record_queries(qe.queries)
392-
check.record_failed(
393-
summary="Could not get OIR",
394-
details=f"Failed to get OIR with error code {qe.cause_status_code}: {qe.msg}",
395-
query_timestamps=qe.query_timestamps,
396-
)
397-
398-
sub_is_as_expected = False
399-
referenced_sub_was_found_when_non_expected = False
400-
if expected_sub_id is None:
401-
# See comment on NULL_SUBSCRIPTION_ID
402-
# ASTM may at some point decide to tolerate accepting empty returned values here,
403-
# but in the meantime we simply attempt to obtain the subscription and check that it does not exist
404-
if oir.subscription_id == NULL_SUBSCRIPTION_ID:
405-
# Sub ID explicitly set to the value representing the null subscription: all good
406-
sub_is_as_expected = True
407-
elif oir.subscription_id is None:
408-
# Sub ID not set at all: not compliant with the spec, but not wrong with regard to which subscription should be attached to the OIR
409-
sub_is_as_expected = True
410-
else:
411-
# If the subscription ID is defined and not set to the known 'null' value, we assume that the DSS used another
412-
# placeholder for the non-existing subscription, and we check that it does not exist.
413-
with self.check(
414-
"Subscription referenced by the OIR does not exist"
415-
) as check:
416-
sub = self._dss.get_subscription(oir.subscription_id)
417-
self.record_query(sub)
418-
if sub.status_code not in [200, 404]:
419-
check.record_failed(
420-
summary="Failed to try to obtain the subscription referenced by the OIR",
421-
details=f"Failed in an unexpected way while querying subscription with ID {oir.subscription_id}: expected a 404 or 200, but got {sub.status_code}",
422-
query_timestamps=[sub.request.timestamp],
423-
)
424-
if sub.status_code == 200:
425-
referenced_sub_was_found_when_non_expected = True
426-
else:
427-
sub_is_as_expected = oir.subscription_id == expected_sub_id
428-
429-
attached_check_name = (
430-
"OIR is not attached to a subscription"
431-
if expected_sub_id is None
432-
else f"OIR is attached to expected subscription"
375+
step_oir_has_correct_subscription(
376+
self,
377+
self._dss,
378+
self._oir_id,
379+
expected_sub_id,
433380
)
434381

435-
with self.check(attached_check_name, self._pid) as check:
436-
if referenced_sub_was_found_when_non_expected:
437-
check.record_failed(
438-
summary="OIR is attached to a subscription although it should not be",
439-
details=f"Expected OIR to not be attached to any subscription, but the referenced subscription {oir.subscription_id} does exist.",
440-
query_timestamps=[sub.request.timestamp],
441-
)
442-
if not sub_is_as_expected:
443-
check.record_failed(
444-
summary="OIR is not attached to the correct subscription",
445-
details=f"Expected OIR to be attached to subscription {expected_sub_id}, but it is attached to {oir.subscription_id}",
446-
query_timestamps=[q.request.timestamp],
447-
)
448-
self.end_test_step()
449-
450382
def _delete_subscription(self, sub_id: EntityID, sub_version: str):
451383
with self.check("Subscription can be deleted", self._pid) as check:
452384
sub = self._dss.delete_subscription(sub_id, sub_version)

monitoring/uss_qualifier/scenarios/astm/utm/dss/oir_implicit_sub_handling.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,7 @@ If the newly created OIR does not mention the implicit subscription from the pre
9292
the DSS is either improperly managing implicit subscriptions, or failing to report the subscriptions relevant to an OIR,
9393
and therefore in violation of **[astm.f3548.v21.DSS0005,1](../../../../requirements/astm/f3548/v21.md)** or **[astm.f3548.v21.DSS0005,5](../../../../requirements/astm/f3548/v21.md)** respectively.
9494

95-
#### 🛑 No implicit subscription was attached check
96-
97-
If the DSS attached an implicit subscription, by either creating or re-using an existing one, to the OIR that was created in this step,
98-
the DSS is in violation of **[astm.f3548.v21.DSS0005,1](../../../../requirements/astm/f3548/v21.md)**.
95+
#### [No implicit subscription was attached](./fragments/oir/oir_has_no_subscription.md)
9996

10097
### Mutate OIR with implicit subscription to not overlap anymore test step
10198

@@ -135,10 +132,7 @@ that were present when the test case started.
135132
Otherwise, the DSS may be failing to properly implement **[astm.f3548.v21.DSS0005,1](../../../../requirements/astm/f3548/v21.md)**
136133
or **[astm.f3548.v21.DSS0005,5](../../../../requirements/astm/f3548/v21.md)**.
137134

138-
#### 🛑 No implicit subscription was attached check
139-
140-
If the DSS attached an implicit subscription, by either creating or re-using an existing one, to the OIR that was created in this step,
141-
the DSS is in violation of **[astm.f3548.v21.DSS0005,1](../../../../requirements/astm/f3548/v21.md)**.
135+
#### [No implicit subscription was attached](./fragments/oir/oir_has_no_subscription.md)
142136

143137
## Implicit subscriptions are properly deleted when required by OIR mutation test case
144138

@@ -271,10 +265,41 @@ Replace the first OIR's explicit subscription with the implicit one created in t
271265

272266
Confirm that the query to replace the second OIR's explicit subscription with the second OIR's implicit subscription succeeds.
273267

274-
#### 🛑 The first OIR is now attached to the specified implicit subscription check
268+
#### [First OIR is now attached to the specified implicit subscription](fragments/oir/oir_has_expected_subscription.md)
269+
270+
## Existing implicit subscription can be attached to OIR without subscription test case
271+
272+
This test case verifies that an implicit subscription can be attached to an OIR that is not currently attached to any subscription.
273+
274+
### Ensure clean workspace test step
275+
276+
Reset the workspace for this test case.
277+
278+
#### [Clean any existing OIRs with known test IDs](clean_workspace_op_intents.md)
279+
280+
#### [Clean any existing subscriptions with known test IDs](clean_workspace_subs.md)
281+
282+
### [Create OIR with no subscription test step](./fragments/oir/crud/create_query.md)
283+
284+
#### [OIR is not attached to an implicit subscription](./fragments/oir/oir_has_no_subscription.md)
285+
286+
### [Create second OIR with an implicit subscription test step](./fragments/oir/crud/create_query.md)
287+
288+
#### [An implicit subscription was created](./fragments/sub/implicit_create.md)
289+
290+
### Attach OIR without subscription to implicit subscription test step
291+
292+
Attach the first OIR to the implicit subscription created with the second OIR.
293+
294+
#### [Attach OIR to implicit subscription](./fragments/oir/crud/update_query.md)
295+
296+
### Confirm OIR is now attached to implicit subscription test step
297+
298+
Confirms that the DSS properly attached the first OIR to the implicit subscription created with the second OIR.
299+
300+
#### [Get OIR query](./fragments/oir/crud/read_query.md)
275301

276-
If the OIR is not attached to the implicit subscription specified in a successful mutation query,
277-
the DSS is in violation of **[astm.f3548.v21.DSS0005,1](../../../../requirements/astm/f3548/v21.md)**.
302+
#### [First OIR is now attached to the specified implicit subscription](fragments/oir/oir_has_expected_subscription.md)
278303

279304
## Cleanup
280305

0 commit comments

Comments
 (0)