Add --force option to stack delete 30/15930/1
authorAnil Belur <abelur@linuxfoundation.org>
Wed, 19 Jun 2019 00:42:08 +0000 (10:42 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Wed, 19 Jun 2019 00:42:08 +0000 (10:42 +1000)
Add --force option to stack delete to improve error
handling in the builder-openstack-cron job.

Issue: RELENG-2058
Change-Id: I3f9918000ce615d765c27d9334c161a1cdf2443c
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
lftools/openstack/cmd.py
lftools/openstack/stack.py
releasenotes/notes/add-force-option-stack-delete-35463a7b8a0920eb.yaml [new file with mode: 0644]

index ba659e8..5e22dc1 100644 (file)
@@ -208,16 +208,20 @@ def create(ctx, name, template_file, parameter_file, timeout, tries):
 
 @click.command()
 @click.argument('name_or_id')
+@click.option(
+    '--force', type=bool, is_flag=True, default=False,
+    help='Ignore timeout and continue with next stack.')
 @click.option(
     '--timeout', type=int, default=900,
     help='Stack delete timeout in seconds.')
 @click.pass_context
-def delete(ctx, name_or_id, timeout):
+def delete(ctx, name_or_id, force, timeout):
     """Delete stack."""
     os_stack.delete(
         ctx.obj['os_cloud'],
         name_or_id,
-        timeout)
+        force=force,
+        timeout=timeout)
 
 
 @click.command(name='delete-stale')
index f4133d2..42bf542 100644 (file)
@@ -74,7 +74,7 @@ def create(os_cloud, name, template_file, parameter_file, timeout=900, tries=2):
     print('------------------------------------')
 
 
-def delete(os_cloud, name_or_id, timeout=900):
+def delete(os_cloud, name_or_id, force, timeout=900):
     """Delete a stack.
 
     Return True if delete was successful.
@@ -104,8 +104,9 @@ def delete(os_cloud, name_or_id, timeout=900):
             print('Retrying delete...')
             cloud.delete_stack(name_or_id)
 
-    print('Failed to delete stack.')
-    return False
+    print('Failed to delete stack {}'.format(name_or_id))
+    if not force:
+        return False
 
 
 def delete_stale(os_cloud, jenkins_servers):
diff --git a/releasenotes/notes/add-force-option-stack-delete-35463a7b8a0920eb.yaml b/releasenotes/notes/add-force-option-stack-delete-35463a7b8a0920eb.yaml
new file mode 100644 (file)
index 0000000..6c450fb
--- /dev/null
@@ -0,0 +1,7 @@
+---
+features:
+  - |
+    Add a ``--force`` option to delete stacks command. This will help with
+    re-factoring the code in global-jjb scripts using in builder-openstack-cron
+    job to remove orphaned stacks/node and continue with the next stack
+    to delete.