File 0001-Exit-w-valid-code-when-no-servers-are-deleted.patch of Package python-novaclient
From fa0d6e85a2117c61e1f4b1728d49a2c67d509cdf Mon Sep 17 00:00:00 2001
From: Matt Thompson <mattt@defunct.ca>
Date: Tue, 4 Jun 2013 10:39:10 +0100
Subject: [PATCH] Exit w/ valid code when no servers are deleted.
This change updates do_delete in v1_1/shell.py to keep track of
deletion failures and raises an exception when all of the specified
servers cannot be deleted. This in turn causes nova client to exit
with a correct exit code when no successful deletes occur.
Change-Id: I16ee7a4c754cf2e8add09a41becbcc37edc767ff
Fixes: bug #1185009
---
novaclient/tests/v1_1/fakes.py | 3 +++
novaclient/tests/v1_1/test_shell.py | 26 ++++++++++++++++++++++++++
novaclient/v1_1/shell.py | 7 +++++++
3 files changed, 36 insertions(+)
(novaclient/tests/* removed from the body of the patch since they
are not in the tarball)
Index: python-novaclient-2.13.0/novaclient/v1_1/shell.py
===================================================================
--- python-novaclient-2.13.0.orig/novaclient/v1_1/shell.py
+++ python-novaclient-2.13.0/novaclient/v1_1/shell.py
@@ -1267,12 +1267,19 @@ def do_show(cs, args):
help='Name or ID of server(s).')
def do_delete(cs, args):
"""Immediately shut down and delete specified server(s)."""
+ failure_count = 0
+
for server in args.server:
try:
_find_server(cs, server).delete()
except Exception as e:
+ failure_count += 1
print(e)
+ if failure_count == len(args.server):
+ raise exceptions.CommandError("Unable to delete any of the specified "
+ "servers.")
+
def _find_server(cs, server):
"""Get a server by name or ID."""