c-w commented on a change in pull request #1617:
URL: https://github.com/apache/libcloud/pull/1617#discussion_r734750067
##########
File path: integration/storage/test_azure_blobs.py
##########
@@ -128,12 +129,35 @@ def setUpClass(cls):
name += random_string(MAX_STORAGE_ACCOUNT_NAME_LENGTH - len(name))
timeout = float(os.getenv('AZURE_TIMEOUT_SECONDS',
DEFAULT_TIMEOUT_SECONDS))
+ # We clean up any left over resource groups from previous runs on
setUpClass. If tests on
+ # CI get terminated non-gracefully, old resources will be left laying
around and we want
+ # to clean those up to ensure we dont hit any limits.
+ # To avoid deleting groups from concurrent runs, we only delete
resources older than a
+ # couple (6) of hours
+ resource_groups = resource_client.resource_groups.list()
+ now_ts = int(time.time())
+ delete_threshold_ts = now_ts - (6 * 60 * 60)
+
+ for resource_group in resource_groups:
+ resource_create_ts = resource_groups.tags.get('create_ts', now_ts)
+
+ if resource_group.name.startswith(name) and
resource_group.location == location and \
+ 'test' in resource_groups.tags and resource_create_ts <=
delete_threshold_ts:
+ #'test' in resource_groups.tags and resource_create_ts <=
delete_threshold_ts:
Review comment:
Nit: remove comment before merge.
##########
File path: integration/storage/test_azure_blobs.py
##########
@@ -128,12 +129,35 @@ def setUpClass(cls):
name += random_string(MAX_STORAGE_ACCOUNT_NAME_LENGTH - len(name))
timeout = float(os.getenv('AZURE_TIMEOUT_SECONDS',
DEFAULT_TIMEOUT_SECONDS))
+ # We clean up any left over resource groups from previous runs on
setUpClass. If tests on
+ # CI get terminated non-gracefully, old resources will be left laying
around and we want
+ # to clean those up to ensure we dont hit any limits.
+ # To avoid deleting groups from concurrent runs, we only delete
resources older than a
+ # couple (6) of hours
+ resource_groups = resource_client.resource_groups.list()
+ now_ts = int(time.time())
+ delete_threshold_ts = now_ts - (6 * 60 * 60)
+
+ for resource_group in resource_groups:
+ resource_create_ts = resource_groups.tags.get('create_ts', now_ts)
+
+ if resource_group.name.startswith(name) and
resource_group.location == location and \
+ 'test' in resource_groups.tags and resource_create_ts <=
delete_threshold_ts:
+ #'test' in resource_groups.tags and resource_create_ts <=
delete_threshold_ts:
+ print("Deleting old stray resource group: %s..." %
(resource_group.name))
+
+ try:
+
resource_client.resource_groups.begin_delete(resource_group.name)
+ except Exception as e:
+ print("Failed to delete resource group: %s" % (str(e)))
Review comment:
Nit: suggest to log to stderr so it gets highlighted in the logs: `from
sys import stderr; print("Failed to delete resource group: %s" % (str(e)),
file=stderr)`
##########
File path: integration/storage/test_azure_blobs.py
##########
@@ -128,12 +129,35 @@ def setUpClass(cls):
name += random_string(MAX_STORAGE_ACCOUNT_NAME_LENGTH - len(name))
timeout = float(os.getenv('AZURE_TIMEOUT_SECONDS',
DEFAULT_TIMEOUT_SECONDS))
+ # We clean up any left over resource groups from previous runs on
setUpClass. If tests on
+ # CI get terminated non-gracefully, old resources will be left laying
around and we want
+ # to clean those up to ensure we dont hit any limits.
+ # To avoid deleting groups from concurrent runs, we only delete
resources older than a
+ # couple (6) of hours
+ resource_groups = resource_client.resource_groups.list()
+ now_ts = int(time.time())
+ delete_threshold_ts = now_ts - (6 * 60 * 60)
Review comment:
Nit: this may be easier to read using `from datetime import timedelta;
timedelta(hours=60).total_seconds()`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]