Skip to content

Commit d74396d

Browse files
committed
comments
1 parent 007679a commit d74396d

File tree

4 files changed

+137
-80
lines changed

4 files changed

+137
-80
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +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-
#### [OIR is not attached to an implicit subscription](./fragments/oir/oir_has_expected_subscription.md)
95+
#### [No implicit subscription was attached](./fragments/oir/oir_has_no_subscription.md)
9696

9797
### Mutate OIR with implicit subscription to not overlap anymore test step
9898

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

135-
#### [OIR is not attached to an implicit subscription](./fragments/oir/oir_has_expected_subscription.md)
135+
#### [No implicit subscription was attached](./fragments/oir/oir_has_no_subscription.md)
136+
136137
## Implicit subscriptions are properly deleted when required by OIR mutation test case
137138

138139
This test case verifies that implicit subscriptions are properly removed if they become unnecessary following the mutation of an OIR.
@@ -280,7 +281,7 @@ Reset the workspace for this test case.
280281

281282
### [Create OIR with no subscription test step](./fragments/oir/crud/create_query.md)
282283

283-
#### [OIR is not attached to an implicit subscription](./fragments/oir/oir_has_expected_subscription.md)
284+
#### [OIR is not attached to an implicit subscription](./fragments/oir/oir_has_no_subscription.md)
284285

285286
### [Create second OIR with an implicit subscription test step](./fragments/oir/crud/create_query.md)
286287

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
from monitoring.uss_qualifier.resources.communications import ClientIdentityResource
2121
from monitoring.uss_qualifier.resources.interuss.id_generator import IDGeneratorResource
2222
from monitoring.uss_qualifier.scenarios.astm.utm.dss import test_step_fragments
23+
from monitoring.uss_qualifier.scenarios.astm.utm.dss.fragments.oir import (
24+
check_oir_has_correct_subscription,
25+
)
2326
from monitoring.uss_qualifier.scenarios.astm.utm.dss.fragments.sub.crud import (
2427
sub_create_query,
2528
)
@@ -440,7 +443,7 @@ def _create_oir(
440443
implicit_sub = sub.subscription
441444
elif subscription_id is None:
442445
with self.check(
443-
"OIR is attached to expected subscription", self._pid
446+
"OIR is not attached to a subscription", self._pid
444447
) as check:
445448
# The official DSS implementation will set the subscription ID to 00000000-0000-4000-8000-000000000000
446449
# Other implementations may use a different value, as the OpenAPI spec does not allow the value to be empty
@@ -802,6 +805,12 @@ def _case_6_attach_implicit_sub_to_oir_without_subscription(self):
802805
with_implicit_sub=False,
803806
)
804807
self._oir_a_ovn = oir_no_sub.ovn
808+
check_oir_has_correct_subscription(
809+
self,
810+
self._dss,
811+
self._oir_a_id,
812+
expected_sub_id=None,
813+
)
805814
self.end_test_step()
806815

807816
self.begin_test_step("Create second OIR with an implicit subscription")

0 commit comments

Comments
 (0)