Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[uss_qualifier/resources/f3548/dss/set_uss_availability] Use QueryError for error handling #503

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -333,12 +333,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 @@ -361,11 +364,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 @@ -314,15 +314,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 @@ -637,18 +637,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 @@ -666,18 +669,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
Loading