Skip to content

Commit

Permalink
[uss_qualifier/resources/f3548/dss/set_uss_availability] Use QueryErr…
Browse files Browse the repository at this point in the history
…or for error handling (#503)
  • Loading branch information
mickmis authored Feb 9, 2024
1 parent 880b8d4 commit a31bf60
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
16 changes: 10 additions & 6 deletions monitoring/uss_qualifier/resources/astm/f3548/v21/dss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)

Expand Down
34 changes: 20 additions & 14 deletions monitoring/uss_qualifier/scenarios/astm/utm/test_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit a31bf60

Please sign in to comment.