From a31bf607309c6130dea5cf19d713e7d2bf2c1807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Misbach?= Date: Fri, 9 Feb 2024 19:11:19 +0100 Subject: [PATCH] [uss_qualifier/resources/f3548/dss/set_uss_availability] Use QueryError for error handling (#503) --- .../resources/astm/f3548/v21/dss.py | 16 +++++---- .../astm/utm/off_nominal_planning/down_uss.py | 17 ++++++---- .../scenarios/astm/utm/test_steps.py | 34 +++++++++++-------- 3 files changed, 40 insertions(+), 27 deletions(-) diff --git a/monitoring/uss_qualifier/resources/astm/f3548/v21/dss.py b/monitoring/uss_qualifier/resources/astm/f3548/v21/dss.py index e22227af82..5d88143006 100644 --- a/monitoring/uss_qualifier/resources/astm/f3548/v21/dss.py +++ b/monitoring/uss_qualifier/resources/astm/f3548/v21/dss.py @@ -323,12 +323,15 @@ def set_uss_availability( uss_id: str, available: bool, version: str = "", - ) -> Tuple[Optional[str], Query]: + ) -> Tuple[str, Query]: """ + Set USS availability. Returns: A tuple composed of - 1) the new version of the USS availability, or None if the query failed; + 1) the new version of the USS availability; 2) the query. + Raises: + * QueryError: if request failed, if HTTP status code is different than 200, or if the parsing of the response failed. """ self._uses_scope(Scope.AvailabilityArbitration) if available: @@ -351,11 +354,12 @@ def set_uss_availability( json=req, ) if query.status_code != 200: - return None, query - else: - result = UssAvailabilityStatusResponse( - ImplicitDict.parse(query.response.json, UssAvailabilityStatusResponse) + raise QueryError( + f"Received code {query.status_code} when attempting to set USS availability of {uss_id}{f'; error message: `{query.error_message}`' if query.error_message is not None else ''}", + query, ) + else: + result = query.parse_json_result(UssAvailabilityStatusResponse) return result.version, query def query_subscriptions( diff --git a/monitoring/uss_qualifier/scenarios/astm/utm/off_nominal_planning/down_uss.py b/monitoring/uss_qualifier/scenarios/astm/utm/off_nominal_planning/down_uss.py index 6e67b3c94b..880b21967d 100644 --- a/monitoring/uss_qualifier/scenarios/astm/utm/off_nominal_planning/down_uss.py +++ b/monitoring/uss_qualifier/scenarios/astm/utm/off_nominal_planning/down_uss.py @@ -317,15 +317,18 @@ def cleanup(self): with self.check( "Availability of virtual USS restored", [self.dss.participant_id] ) as check: - availability_version, avail_query = self.dss.set_uss_availability( - self.uss_qualifier_sub, - True, - ) - self.record_query(avail_query) - if availability_version is None: + try: + availability_version, avail_query = self.dss.set_uss_availability( + self.uss_qualifier_sub, + True, + ) + self.record_query(avail_query) + except QueryError as e: + self.record_queries(e.queries) + avail_query = e.queries[0] check.record_failed( summary=f"Availability of USS {self.uss_qualifier_sub} could not be set to available", - details=f"DSS responded code {avail_query.status_code}; error message: {avail_query.error_message}", + details=f"DSS responded code {avail_query.status_code}; {e}", query_timestamps=[avail_query.request.timestamp], ) diff --git a/monitoring/uss_qualifier/scenarios/astm/utm/test_steps.py b/monitoring/uss_qualifier/scenarios/astm/utm/test_steps.py index 6e8c2e05c1..d889bb68b0 100644 --- a/monitoring/uss_qualifier/scenarios/astm/utm/test_steps.py +++ b/monitoring/uss_qualifier/scenarios/astm/utm/test_steps.py @@ -648,18 +648,21 @@ def set_uss_available( Returns: The new version of the USS availability. """ - availability_version, avail_query = dss.set_uss_availability( - uss_sub, - True, - ) - scenario.record_query(avail_query) with scenario.check( "USS availability successfully set to 'Available'", [dss.participant_id] ) as check: - if availability_version is None: + try: + availability_version, avail_query = dss.set_uss_availability( + uss_sub, + True, + ) + scenario.record_query(avail_query) + except QueryError as e: + scenario.record_queries(e.queries) + avail_query = e.queries[0] check.record_failed( summary=f"Availability of USS {uss_sub} could not be set to available", - details=f"DSS responded code {avail_query.status_code}; error message: {avail_query.error_message}", + details=f"DSS responded code {avail_query.status_code}; {e}", query_timestamps=[avail_query.request.timestamp], ) return availability_version @@ -677,18 +680,21 @@ def set_uss_down( Returns: The new version of the USS availability. """ - availability_version, avail_query = dss.set_uss_availability( - uss_sub, - False, - ) - scenario.record_query(avail_query) with scenario.check( "USS availability successfully set to 'Down'", [dss.participant_id] ) as check: - if availability_version is None: + try: + availability_version, avail_query = dss.set_uss_availability( + uss_sub, + False, + ) + scenario.record_query(avail_query) + except QueryError as e: + scenario.record_queries(e.queries) + avail_query = e.queries[0] check.record_failed( summary=f"Availability of USS {uss_sub} could not be set to down", - details=f"DSS responded code {avail_query.status_code}; error message: {avail_query.error_message}", + details=f"DSS responded code {avail_query.status_code}; {e}", query_timestamps=[avail_query.request.timestamp], ) return availability_version