From 1960efbbec970bab8732ae2d711f3b2bd739b286 Mon Sep 17 00:00:00 2001 From: Dmitry Sutyagin Date: Thu, 25 Aug 2016 13:52:19 +0300 Subject: [PATCH] Change exit codes, list exit codes in a doc --- doc/source/exitcodes.rst | 5 +++++ doc/source/index.rst | 1 + timmy/cli.py | 4 ++-- timmy/nodes.py | 6 +++--- timmy/tools.py | 20 +++++++++++--------- 5 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 doc/source/exitcodes.rst diff --git a/doc/source/exitcodes.rst b/doc/source/exitcodes.rst new file mode 100644 index 0000000..9bbf287 --- /dev/null +++ b/doc/source/exitcodes.rst @@ -0,0 +1,5 @@ +========== +Exit Codes +========== + + diff --git a/doc/source/index.rst b/doc/source/index.rst index c41372f..33ab50d 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -16,6 +16,7 @@ Contents: usage cli tools + exitcodes Indices and tables ================== diff --git a/timmy/cli.py b/timmy/cli.py index f10cd46..de0c5ab 100755 --- a/timmy/cli.py +++ b/timmy/cli.py @@ -195,7 +195,7 @@ def main(argv=None): args = parser.parse_args(argv[1:]) if args.version: print(version) - sys.exit(0) + return 0 loglevels = [logging.WARNING, logging.INFO, logging.DEBUG] if args.quiet and not args.log_file: args.verbose = 0 @@ -307,7 +307,7 @@ def main(argv=None): if not enough_space: logger.error('Not enough space for logs in "%s", exiting.' % nm.conf['archive_dir']) - return 2 + return 100 if not args.only_logs: if nm.has(Node.pkey): pretty_run(args.quiet, 'Uploading files', nm.put_files) diff --git a/timmy/nodes.py b/timmy/nodes.py index bc80f18..917f3b0 100644 --- a/timmy/nodes.py +++ b/timmy/nodes.py @@ -452,7 +452,7 @@ class NodeManager(object): if (not os.path.exists(self.rqdir)): self.logger.critical(('NodeManager: directory %s does not' ' exist') % self.rqdir) - sys.exit(1) + sys.exit(101) if self.conf['rqfile']: self.import_rq() self.nodes = {} @@ -495,7 +495,7 @@ class NodeManager(object): if (not self.get_nodes_fuelclient() and not self.get_nodes_api() and not self.get_nodes_cli()): - sys.exit(4) + sys.exit(105) self.nodes_init() # apply soft-filter on all nodes for node in self.nodes.values(): @@ -609,7 +609,7 @@ class NodeManager(object): def fuel_init(self): if not self.conf['fuel_ip']: self.logger.critical('NodeManager: fuel_ip not set') - sys.exit(7) + sys.exit(106) fuelnode = Node(id=0, cluster=0, name='fuel', diff --git a/timmy/tools.py b/timmy/tools.py index e8369cb..3d94fdb 100644 --- a/timmy/tools.py +++ b/timmy/tools.py @@ -30,6 +30,7 @@ import json from flock import FLock from tempfile import gettempdir from pipes import quote +import signal logger = logging.getLogger(__name__) slowpipe = ''' @@ -51,6 +52,7 @@ def interrupt_wrapper(f): f(*args, **kwargs) except KeyboardInterrupt: logger.warning('Interrupted, exiting.') + sys.exit(signal.SIGINT) except Exception as e: logger.error('Error: %s' % e, exc_info=True) for k in dir(e): @@ -132,7 +134,7 @@ def run_batch(item_list, maxthreads, dict_result=False): if isinstance(run_item.result, Exception): logger.critical('%s, exiting' % run_item.result) cleanup() - sys.exit(42) + sys.exit(109) run_item.process.join() run_item.process = None if dict_result: @@ -157,10 +159,10 @@ def load_json_file(filename): except IOError as e: logger.critical("I/O error(%s): file: %s; msg: %s" % (e.errno, e.filename, e.strerror)) - sys.exit(1) + sys.exit(107) except ValueError: - logger.critical("Could not convert data") - sys.exit(1) + logger.critical("Could not convert data", exc_info=True) + sys.exit(108) def load_yaml_file(filename): @@ -173,14 +175,14 @@ def load_yaml_file(filename): except IOError as e: logger.critical("I/O error(%s): file: %s; msg: %s" % (e.errno, e.filename, e.strerror)) - sys.exit(1) + sys.exit(102) except ValueError: - logger.critical("Could not convert data") - sys.exit(1) + logger.critical("Could not convert data", exc_info=True) + sys.exit(103) except yaml.parser.ParserError as e: logger.critical("Could not parse %s:\n%s" % (filename, str(e))) - sys.exit(1) + sys.exit(105) def mdir(directory): @@ -193,7 +195,7 @@ def mdir(directory): os.makedirs(directory) except: logger.critical("Can't create a directory: %s" % directory) - sys.exit(3) + sys.exit(110) def launch_cmd(cmd, timeout, input=None, ok_codes=None, decode=True):