From 8e8dde2052148fea0135a19ad229da7114738024 Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Wed, 10 Dec 2014 21:16:23 +0300 Subject: [PATCH] Output clear error message on invalid api version Now if --os-image-api-version mistakenly contains a string then you will get a ValueError Example: $ glance --os-image-api-version hui ValueError: invalid literal for int() with base 10: 'hui' This code correctly handles this situation, prints a warning message and interrupts the execution of the client Change-Id: I4733578adfc70bd57afd5f0d4d361c8ef689a381 Closes-bug: 1401197 --- glanceclient/shell.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/glanceclient/shell.py b/glanceclient/shell.py index 44607661..31891e65 100644 --- a/glanceclient/shell.py +++ b/glanceclient/shell.py @@ -597,7 +597,11 @@ class OpenStackImagesShell(object): url_version = None # build available subcommands based on version - api_version = int(options.os_image_api_version or url_version or 1) + try: + api_version = int(options.os_image_api_version or url_version or 1) + except ValueError: + print("Invalid API version parameter") + utils.exit() if api_version == 2: self._cache_schemas(options)