From: Anil Belur Date: Wed, 19 Jun 2019 00:42:08 +0000 (+1000) Subject: Add --force option to stack delete X-Git-Tag: v0.25.1~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F30%2F15930%2F1;p=releng%2Flftools.git Add --force option to stack delete 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 --- diff --git a/lftools/openstack/cmd.py b/lftools/openstack/cmd.py index ba659e81..5e22dc15 100644 --- a/lftools/openstack/cmd.py +++ b/lftools/openstack/cmd.py @@ -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') diff --git a/lftools/openstack/stack.py b/lftools/openstack/stack.py index f4133d21..42bf542b 100644 --- a/lftools/openstack/stack.py +++ b/lftools/openstack/stack.py @@ -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 index 00000000..6c450fb4 --- /dev/null +++ b/releasenotes/notes/add-force-option-stack-delete-35463a7b8a0920eb.yaml @@ -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.