Skip to content

Commit

Permalink
[uss_qualifier] split cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Shastick committed Oct 31, 2023
1 parent 89aaa4b commit 5255074
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _delete_isa_if_exists(self):
)

def _clean_any_sub(self):
utils.delete_any_subscription(self, self._dss_wrapper, self._isa.footprint)
self._dss_wrapper.cleanup_subs_in_area(self._isa_area)

def cleanup(self):
self.begin_cleanup()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,7 @@ def _ensure_test_sub_ids_do_not_exist(self):
which is why we need to explicitly test for their presence.
"""
for sub_id in self._test_subscription_ids:
# TODO migrate this to the two-check pattern when the utility has been migrated
with self.check(
"Ensure subscription with test ID does not exist",
[self._dss_wrapper.participant_id],
) as check:
self._dss_wrapper.cleanup_sub(check, sub_id)
self._dss_wrapper.cleanup_sub(sub_id)

def _ensure_no_active_subs_exist(self):
"""Ensure that we don't currently have any other active subscriptions at the DSS:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
from datetime import timedelta

import arrow
import datetime
from typing import Dict

from monitoring.monitorlib import schema_validation
from monitoring.monitorlib.fetch import rid as fetch
from monitoring.monitorlib.mutate import rid as mutate
from monitoring.monitorlib.rid import RIDVersion
from monitoring.monitorlib.mutate.rid import ChangedSubscription
from monitoring.prober.infrastructure import register_resource_type
from monitoring.uss_qualifier.common_data_definitions import Severity
from monitoring.uss_qualifier.resources.astm.f3411.dss import DSSInstanceResource
Expand All @@ -18,10 +13,6 @@
GenericTestScenario,
PendingCheck,
)
from monitoring.monitorlib.mutate.rid import ChangedSubscription

from typing import Dict


_24H_MIN_TOLERANCE_S = 23 * 3600 + 59 * 60 # 23 hours and 59 minutes
_24H_MAX_TOLERANCE_S = 24 * 3600 + 1 # 24 hours sharp, plus a second
Expand Down Expand Up @@ -54,6 +45,7 @@ def __init__(
# for creating different subscriptions this probably won't do.
self._sub_id = id_generator.id_factory.make_id(self.SUB_TYPE)
self._isa = isa.specification
self._isa_area = [vertex.as_s2sphere() for vertex in self._isa.footprint]

def run(self):
self.begin_test_scenario()
Expand All @@ -78,7 +70,7 @@ def _setup_case(self):
self.end_test_case()

def _clean_any_sub(self):
utils.delete_any_subscription(self, self._dss_wrapper, self._isa.footprint)
self._dss_wrapper.cleanup_subs_in_area(self._isa_area)

def _ensure_clean_workspace_step(self):
self.begin_test_step("Ensure clean workspace")
Expand Down Expand Up @@ -218,7 +210,7 @@ def _check_properly_truncated(
query_timestamps=[changed.query.request.timestamp],
)
# If a subscription was created, we want to delete it before continuing:
self._dss_wrapper.cleanup_sub(check, sub_id=self._sub_id)
self._dss_wrapper.cleanup_sub(sub_id=self._sub_id)

def _default_subscription_params(self, duration: datetime.timedelta) -> Dict:
now = datetime.datetime.utcnow()
Expand Down
26 changes: 0 additions & 26 deletions monitoring/uss_qualifier/scenarios/astm/netrid/common/dss/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,3 @@ def delete_isa_if_exists(
f"Attempting to notify subscriber for ISA {isa_id} at {subscriber_url} resulted in {notification.status_code}",
query_timestamps=[notification.query.request.timestamp],
)


def delete_any_subscription(
scenario: GenericTestScenario,
dss_wrapper: DSSWrapper,
area: List[LatLngPoint],
):
"""
Deletes any subscription that is returned for the passed area.
Args:
scenario: the scenario instance that will provide the checks
dss_wrapper: the dss on which to delete subscriptions
area: the area for which subscriptions are to be deleted
"""
with scenario.check(
"Successful subscription query", [dss_wrapper.participant_id]
) as check:
fetched = dss_wrapper.search_subs(
check, [vertex.as_s2sphere() for vertex in area]
)
for sub_id in fetched.subscriptions.keys():
with scenario.check(
"Successful subscription deletion", [dss_wrapper.participant_id]
) as check:
dss_wrapper.cleanup_sub(check, sub_id=sub_id)
Original file line number Diff line number Diff line change
Expand Up @@ -767,14 +767,9 @@ def cleanup(self):
)

elif entity.type == EntityType.Sub:
with self.check(
"Subscription deleted with proper response",
[self._dss_primary.participant_id],
) as check:
_ = self._dss_primary.cleanup_sub(
check,
sub_id=entity.uuid,
)
_ = self._dss_primary.cleanup_sub(
sub_id=entity.uuid,
)

else:
raise RuntimeError(f"Unknown Entity type: {entity.type}")
Expand Down
98 changes: 70 additions & 28 deletions monitoring/uss_qualifier/scenarios/astm/netrid/dss_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,45 @@ def del_sub(
"DSS query was not successful, but a High Severity issue didn't interrupt execution"
)

def cleanup_subs_in_area(
self,
area: List[s2sphere.LatLng],
):
"""Cleanup any subscription that is returned for the search in the provided area"""

with self._scenario.check(
"Successful subscription search query", [self.participant_id]
) as check:
found_subs = self.search_subs(check, area)

try:
for sub_id, sub in found_subs.subscriptions.items():
with self._scenario.check(
"Subscription can be deleted", [self.participant_id]
) as check:
del_sub = mutate.delete_subscription(
subscription_id=sub_id,
subscription_version=sub.version,
rid_version=self._dss.rid_version,
utm_client=self._dss.client,
participant_id=self._dss.participant_id,
)

self._handle_query_result(
check,
del_sub,
f"Failed to delete subscription {sub}",
{404, 200},
Severity.Medium,
)
except QueryError as e:
self._handle_query_error(check, e)
raise RuntimeError(
"DSS query was not successful, but a High Severity issue didn't interrupt execution"
)

def cleanup_sub(
self,
check: PendingCheck,
sub_id: str,
) -> Optional[ChangedSubscription]:
"""Cleanup a subscription at the DSS. Does not fail if it is not found.
Expand All @@ -950,39 +986,45 @@ def cleanup_sub(
:return: the DSS response if the subscription exists
"""
try:
sub = fetch.subscription(
subscription_id=sub_id,
rid_version=self._dss.rid_version,
session=self._dss.client,
participant_id=self._dss.participant_id,
)
with self._scenario.check(
"Subscription can be queried by ID", [self.participant_id]
) as check:
sub = fetch.subscription(
subscription_id=sub_id,
rid_version=self._dss.rid_version,
session=self._dss.client,
participant_id=self._dss.participant_id,
)

self._handle_query_result(
check,
sub,
f"Failed to get subscription {sub_id}",
{404, 200},
Severity.Medium,
)
self._handle_query_result(
check,
sub,
f"Failed to get subscription {sub_id}",
{404, 200},
Severity.Medium,
)

if sub.status_code == 404:
return None

del_sub = mutate.delete_subscription(
subscription_id=sub_id,
subscription_version=sub.subscription.version,
rid_version=self._dss.rid_version,
utm_client=self._dss.client,
participant_id=self._dss.participant_id,
)
with self._scenario.check(
"Subscription can be deleted", [self.participant_id]
) as check:
del_sub = mutate.delete_subscription(
subscription_id=sub_id,
subscription_version=sub.subscription.version,
rid_version=self._dss.rid_version,
utm_client=self._dss.client,
participant_id=self._dss.participant_id,
)

self._handle_query_result(
check,
del_sub,
f"Failed to delete subscription {sub_id}",
{404, 200},
Severity.Medium,
)
self._handle_query_result(
check,
del_sub,
f"Failed to delete subscription {sub_id}",
{404, 200},
Severity.Medium,
)

return del_sub

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If an ISA with the intended ID is already present in the DSS, it needs to be rem

When a pre-existing ISA needs to be deleted to ensure a clean workspace, any subscribers to ISAs in that area must be notified (as specified by the DSS). If a notification cannot be delivered, then the **[astm.f3411.v19.NET0730](../../../../../requirements/astm/f3411/v19.md)** requirement to implement the POST ISAs endpoint isn't met.

#### Successful subscription query check
#### Successful subscription search query check

**[astm.f3411.v19.DSS0030,f](../../../../../requirements/astm/f3411/v19.md)** requires the implementation of the DSS endpoint to allow callers to retrieve the subscriptions they created.

Expand Down Expand Up @@ -139,7 +139,7 @@ If an ISA with the intended ID is already present in the DSS, it needs to be rem

When a pre-existing ISA needs to be deleted to ensure a clean workspace, any subscribers to ISAs in that area must be notified (as specified by the DSS). If a notification cannot be delivered, then the **[astm.f3411.v19.NET0730](../../../../../requirements/astm/f3411/v19.md)** requirement to implement the POST ISAs endpoint isn't met.

#### Successful subscription query check
#### Successful subscription search query check

**[astm.f3411.v19.DSS0030,f](../../../../../requirements/astm/f3411/v19.md)** requires the implementation of the DSS endpoint to allow callers to retrieve the subscriptions they created.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ This step ensures that no subscription with the known test ID exists in the DSS.

If the DSS fails to let us search in the area for which test subscriptions will be created, it is failing to properly implement **[astm.f3411.v19.DSS0030,f](../../../../../requirements/astm/f3411/v19.md)**.

#### Subscription can be deleted check
#### Subscription can be queried by ID check

An attempt to delete a subscription when the correct version is provided should succeed, otherwise the DSS is in violation of **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)**.
If the DSS cannot be queried for the existing test ID, the DSS is likely not implementing **[astm.f3411.v19.DSS0030,e](../../../../../requirements/astm/f3411/v19.md)** correctly.

#### Ensure subscription with test ID does not exist check
#### Subscription can be deleted check

If the DSS cannot be queried for the existing test ID, or if a subscription with that ID exists and it cannot be removed,
the DSS is likely not implementing **[astm.f3411.v19.DSS0030,e](../../../../../requirements/astm/f3411/v19.md)** or **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)** properly.
An attempt to delete a subscription when the correct version is provided should succeed, otherwise the DSS is in violation of **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)**.

## Subscription Simple test case

Expand Down Expand Up @@ -396,7 +395,11 @@ If the DSS returns the deleted subscription in a search that covers the area it

The cleanup phase of this test scenario removes the subscription with the known test ID if it has not been removed before.

#### Ensure subscription with test ID does not exist check
#### Subscription can be queried by ID check

If the DSS cannot be queried for the existing test ID, the DSS is likely not implementing **[astm.f3411.v19.DSS0030,e](../../../../../requirements/astm/f3411/v19.md)** correctly.

#### Subscription can be deleted check

An attempt to delete a subscription when the correct version is provided should succeed, otherwise the DSS is in violation of **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)**.

If the DSS cannot be queried for the existing test ID, or if a subscription with that ID exists and it cannot be removed,
the DSS is likely not implementing **[astm.f3411.v19.DSS0030,e](../../../../../requirements/astm/f3411/v19.md)** or **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)** properly.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Perform basic operations on a single DSS instance to create subscriptions and ch

This step ensures that we remove any subscription that may already exist for the service area. First, the DSS is queried for any applicable existing subscriptions, and then any subscriptions found are deleted.

#### Successful subscription query check
#### Successful subscription search query check

If the query for subscriptions fails, **[astm.f3411.v19.DSS0030,f](../../../../../requirements/astm/f3411/v19.md)** was not met.
If the search query for subscriptions fails, **[astm.f3411.v19.DSS0030,f](../../../../../requirements/astm/f3411/v19.md)** was not met.

#### Successful subscription deletion check
#### Subscription can be deleted check

If the deletion attempt fails, **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)** was not met.

Expand Down Expand Up @@ -56,11 +56,11 @@ it will not have performed the Subscription count validation as defined in **[as

Clean up any subscriptions created.

#### Successful subscription query check
#### Successful subscription search query check

If the query for subscriptions fails, **[astm.f3411.v19.DSS0030,f](../../../../../requirements/astm/f3411/v19.md)** was not met.

#### Successful subscription deletion check
#### Subscription can be deleted check

If the deletion attempt fails, **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)** was not met.

Expand Down Expand Up @@ -101,10 +101,10 @@ The ability to delete an existing subscription is required in **[astm.f3411.v19.

The cleanup phase of this test scenario will remove any subscription that may have been created during the test and that intersects with the test ISA.

### Successful subscription query check
### Successful subscription search query check

If the query for subscriptions fails, the "GET Subscriptions" portion of **[astm.f3411.v19.DSS0030,f](../../../../../requirements/astm/f3411/v19.md)** was not met.

### Successful subscription deletion check
### Subscription can be deleted check

If the deletion attempt fails, the "DELETE Subscription" portion of **[astm.f3411.v19.DSS0030,d](../../../../../requirements/astm/f3411/v19.md)** was not met.
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ Any entities (ISAs or Subscriptions) not deleted normally will be deleted here.

**[astm.f3411.v19.DSS0130,A2-6-1,2a](../../../../requirements/astm/f3411/v19.md)**

### Subscription deleted with proper response check
### Subscription can be queried by ID check

**[astm.f3411.v19.DSS0130,A2-6-1,4a](../../../../requirements/astm/f3411/v19.md)**

### Subscription can be deleted check

**[astm.f3411.v19.DSS0130,A2-6-1,4a](../../../../requirements/astm/f3411/v19.md)**
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If an ISA with the intended ID is already present in the DSS, it needs to be rem

When a pre-existing ISA needs to be deleted to ensure a clean workspace, any subscribers to ISAs in that area must be notified (as specified by the DSS). If a notification cannot be delivered, then the **[astm.f3411.v22a.NET0730](../../../../../requirements/astm/f3411/v22a.md)** requirement to implement the POST ISAs endpoint isn't met.

#### Successful subscription query check
#### Successful subscription search query check

**[astm.f3411.v22a.DSS0030,f](../../../../../requirements/astm/f3411/v22a.md)** requires the implementation of the DSS endpoint to allow callers to retrieve the subscriptions they created.

Expand Down Expand Up @@ -139,7 +139,7 @@ If an ISA with the intended ID is already present in the DSS, it needs to be rem

When a pre-existing ISA needs to be deleted to ensure a clean workspace, any subscribers to ISAs in that area must be notified (as specified by the DSS). If a notification cannot be delivered, then the **[astm.f3411.v22a.NET0730](../../../../../requirements/astm/f3411/v22a.md)** requirement to implement the POST ISAs endpoint isn't met.

#### Successful subscription query check
#### Successful subscription search query check

**[astm.f3411.v22a.DSS0030,f](../../../../../requirements/astm/f3411/v22a.md)** requires the implementation of the DSS endpoint to allow callers to retrieve the subscriptions they created.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ This step ensures that no subscription with the known test ID exists in the DSS.

If the DSS fails to let us search in the area for which test subscriptions will be created, it is failing to properly implement **[astm.f3411.v22a.DSS0030,f](../../../../../requirements/astm/f3411/v22a.md)**.

#### Subscription can be deleted check
#### Subscription can be queried by ID check

An attempt to delete a subscription when the correct version is provided should succeed, otherwise the DSS is in violation of **[astm.f3411.v22a.DSS0030,d](../../../../../requirements/astm/f3411/v22a.md)**.
If the DSS cannot be queried for the existing test ID, the DSS is likely not implementing **[astm.f3411.v19.DSS0030,e](../../../../../requirements/astm/f3411/v19.md)** correctly.

#### Ensure subscription with test ID does not exist check
#### Subscription can be deleted check

If the DSS cannot be queried for the existing test ID, or if a subscription with that ID exists and it cannot be removed,
the DSS is likely not implementing **[astm.f3411.v22a.DSS0030,e](../../../../../requirements/astm/f3411/v22a.md)** or **[astm.f3411.v22a.DSS0030,d](../../../../../requirements/astm/f3411/v22a.md)** properly.
An attempt to delete a subscription when the correct version is provided should succeed, otherwise the DSS is in violation of **[astm.f3411.v22a.DSS0030,d](../../../../../requirements/astm/f3411/v22a.md)**.

## Subscription Simple test case

Expand Down Expand Up @@ -389,7 +388,10 @@ If the DSS returns the deleted subscription in a search that covers the area it

The cleanup phase of this test scenario removes the subscription with the known test ID if it has not been removed before.

#### Ensure subscription with test ID does not exist check
#### Subscription can be queried by ID check

If the DSS cannot be queried for the existing test ID, or if a subscription with that ID exists and it cannot be removed,
the DSS is likely not implementing **[astm.f3411.v22a.DSS0030,e](../../../../../requirements/astm/f3411/v22a.md)** or **[astm.f3411.v22a.DSS0030,d](../../../../../requirements/astm/f3411/v22a.md)** properly.
If the DSS cannot be queried for the existing test ID, the DSS is likely not implementing **[astm.f3411.v19.DSS0030,e](../../../../../requirements/astm/f3411/v19.md)** correctly.

#### Subscription can be deleted check

An attempt to delete a subscription when the correct version is provided should succeed, otherwise the DSS is in violation of **[astm.f3411.v22a.DSS0030,d](../../../../../requirements/astm/f3411/v22a.md)**.
Loading

0 comments on commit 5255074

Please sign in to comment.