Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Merge pull request #826 from open-craft/joaocabrita/fix_ci_cleanup
Browse files Browse the repository at this point in the history
fix: Skip empty hashes when cleaning up OpenStack servers created by CI
  • Loading branch information
João Cabrita authored Jul 21, 2021
2 parents 8b1a824 + 8735a22 commit 74cf08d
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions cleanup_utils/openstack_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,37 @@ def run_cleanup(self):
# If instance is older than age limit
if instance_age and instance_age < self.age_limit:
# Get instance name in format edxapp-HASHinteg-1
self.cleaned_up_hashes.append(
instance.name.split('-')[1][:-5]
)
clean_hash = instance.name.split('-')[1][:-5]
# some instance names might not actually
# match what we expect, so we ignore them
if not clean_hash:
logger.warning("Unexpected instance name %s, skipping...", instance.name)
continue

# Terminate the servers
logger.info(
" * TERMINATING instance (created at: %s, termination threshold: %s)...",
instance_age,
self.age_limit
)
if not self.dry_run:
try:
instance.delete()
except Exception as e: # pylint: disable=broad-except
logger.warning(
" * WARNING: Unable to delete instance. Error: %s.",
e,
)

self.cleaned_up_hashes.append(clean_hash)
self._delete_instance(instance)
else:
logger.info(
" * SKIPPING: Instance was created at %s but the cut-off age threshold is %s.",
instance_age,
self.age_limit
)

def _delete_instance(self, instance):
"""
Delete the instance.
"""
if not self.dry_run:
try:
instance.delete()
except Exception as e: # pylint: disable=broad-except
logger.warning(
" * WARNING: Unable to delete instance. Error: %s.",
e,
)

0 comments on commit 74cf08d

Please sign in to comment.