|
| 1 | +from uas_standards.astm.f3548.v21.api import UssAvailabilityState |
| 2 | +from uas_standards.astm.f3548.v21.constants import Scope |
| 3 | + |
| 4 | +from monitoring.monitorlib.fetch import QueryError |
| 5 | +from monitoring.uss_qualifier.resources.astm.f3548.v21.dss import ( |
| 6 | + DSSInstance, |
| 7 | + DSSInstanceResource, |
| 8 | +) |
| 9 | +from monitoring.uss_qualifier.resources.communications import ClientIdentityResource |
| 10 | +from monitoring.uss_qualifier.scenarios.astm.utm.dss.test_step_fragments import ( |
| 11 | + get_uss_availability, |
| 12 | + set_uss_availability, |
| 13 | +) |
| 14 | +from monitoring.uss_qualifier.scenarios.scenario import TestScenario |
| 15 | +from monitoring.uss_qualifier.suites.suite import ExecutionContext |
| 16 | + |
| 17 | + |
| 18 | +class UssAvailabilitySimple(TestScenario): |
| 19 | + """ |
| 20 | + A scenario that verifies that USS availability status cannot be updated with the incorrect version. |
| 21 | + """ |
| 22 | + |
| 23 | + _dss: DSSInstance |
| 24 | + |
| 25 | + _uss_id: str |
| 26 | + |
| 27 | + def __init__( |
| 28 | + self, |
| 29 | + dss: DSSInstanceResource, |
| 30 | + client_identity: ClientIdentityResource, |
| 31 | + ): |
| 32 | + """ |
| 33 | + Args: |
| 34 | + dss: dss to test |
| 35 | + id_generator: will let us generate specific identifiers |
| 36 | + client_identity: tells us the identity we should expect as an entity's manager |
| 37 | + """ |
| 38 | + super().__init__() |
| 39 | + scopes: dict[str, str] = { |
| 40 | + Scope.AvailabilityArbitration: "read and set availability for a USS" |
| 41 | + } |
| 42 | + |
| 43 | + self._dss = dss.get_instance(scopes) |
| 44 | + self._pid = [self._dss.participant_id] |
| 45 | + |
| 46 | + self._uss_id = client_identity.subject() |
| 47 | + |
| 48 | + def run(self, context: ExecutionContext): |
| 49 | + self.begin_test_scenario(context) |
| 50 | + |
| 51 | + self.begin_test_case("Update USS availability state") |
| 52 | + self._step_declare_uss_available() |
| 53 | + self.end_test_case() |
| 54 | + |
| 55 | + self.begin_test_case("Update requires correct version") |
| 56 | + self._step_attempt_update_missing_version() |
| 57 | + self._step_attempt_update_incorrect_version() |
| 58 | + self.end_test_case() |
| 59 | + |
| 60 | + def _step_declare_uss_available(self): |
| 61 | + self.begin_test_step("Declare USS as available at DSS") |
| 62 | + version = get_uss_availability( |
| 63 | + self, |
| 64 | + self._dss, |
| 65 | + self._uss_id, |
| 66 | + Scope.AvailabilityArbitration, |
| 67 | + ) |
| 68 | + set_uss_availability( |
| 69 | + self, self._dss, self._uss_id, UssAvailabilityState.Normal, version |
| 70 | + ) |
| 71 | + self.end_test_step() |
| 72 | + |
| 73 | + def _step_attempt_update_missing_version(self): |
| 74 | + self.begin_test_step("Attempt update with missing version") |
| 75 | + with self.check( |
| 76 | + "Request to update USS availability status with empty version fails", |
| 77 | + self._pid, |
| 78 | + ) as check: |
| 79 | + try: |
| 80 | + _, q = self._dss.set_uss_availability( |
| 81 | + self._uss_id, |
| 82 | + UssAvailabilityState.Down, |
| 83 | + "", |
| 84 | + ) |
| 85 | + self.record_query(q) |
| 86 | + # We don't expect the reach this point: |
| 87 | + check.record_failed( |
| 88 | + summary="Set USS availability with missing version was not expected to succeed", |
| 89 | + details=f"Was expecting an HTTP 409 response because of an missing version, but got {q.status_code} instead", |
| 90 | + query_timestamps=[q.request.timestamp], |
| 91 | + ) |
| 92 | + except QueryError as qe: |
| 93 | + self.record_queries(qe.queries) |
| 94 | + if qe.cause_status_code == 409: |
| 95 | + # The spec explicitly requests a 409 response code for incorrect OVNs. |
| 96 | + pass |
| 97 | + else: |
| 98 | + check.record_failed( |
| 99 | + summary="Set USS availability with missing version failed for unexpected reason", |
| 100 | + details=f"Was expecting an HTTP 409 response because of an missing version, but got {qe.cause_status_code} instead", |
| 101 | + query_timestamps=qe.query_timestamps, |
| 102 | + ) |
| 103 | + self.end_test_step() |
| 104 | + |
| 105 | + def _step_attempt_update_incorrect_version(self): |
| 106 | + self.begin_test_step("Attempt update with incorrect version") |
| 107 | + with self.check( |
| 108 | + "Request to update USS availability status with incorrect version fails", |
| 109 | + self._pid, |
| 110 | + ) as check: |
| 111 | + try: |
| 112 | + _, q = self._dss.set_uss_availability( |
| 113 | + self._uss_id, |
| 114 | + UssAvailabilityState.Down, |
| 115 | + "ThisIsAnIncorrectVersion", |
| 116 | + ) |
| 117 | + self.record_query(q) |
| 118 | + # We don't expect the reach this point: |
| 119 | + check.record_failed( |
| 120 | + summary="Set USS availability with incorrect version was not expected to succeed", |
| 121 | + details=f"Was expecting an HTTP 409 response because of an incorrect version, but got {q.status_code} instead", |
| 122 | + query_timestamps=[q.request.timestamp], |
| 123 | + ) |
| 124 | + except QueryError as qe: |
| 125 | + self.record_queries(qe.queries) |
| 126 | + if qe.cause_status_code == 409: |
| 127 | + # The spec explicitly requests a 409 response code for incorrect OVNs. |
| 128 | + pass |
| 129 | + else: |
| 130 | + check.record_failed( |
| 131 | + summary="Set USS availability with incorrect version failed for unexpected reason", |
| 132 | + details=f"Was expecting an HTTP 409 response because of an incorrect version, but got {qe.cause_status_code} instead", |
| 133 | + query_timestamps=qe.query_timestamps, |
| 134 | + ) |
| 135 | + self.end_test_step() |
0 commit comments