summaryrefslogtreecommitdiff
path: root/glanceclient
diff options
context:
space:
mode:
authorMridula Joshi <mrjoshi@redhat.com>2021-08-03 10:35:40 +0000
committerMridula Joshi <mrjoshi@redhat.com>2021-08-03 10:35:40 +0000
commit1eb0bbbed7c5ce12aee5f26be7a7aec51ae9ef55 (patch)
tree6e3f7ada696fb278eb1a173017029dd95e4a2845 /glanceclient
parentcb084f5289c5c23bdb9fabb413a81b32acb5a498 (diff)
downloadpython-glanceclient-1eb0bbbed7c5ce12aee5f26be7a7aec51ae9ef55.tar.gz
Fix undesirable raw Python error
Using the glanceclient without a subcommand while passing an optional argument triggers the raw Python error `ERROR: 'Namespace' object has no attribute 'func'`. This bug can be reproduced by issuing the command `glance --os-image-api-version 2`. Added a default value to `func` as placeholder so that a help message is shown instead of the Python error. Closes-Bug: #1903727 Change-Id: Ie4288262e408192310cbbc240bd1779b265a64fd
Diffstat (limited to 'glanceclient')
-rw-r--r--glanceclient/shell.py2
-rw-r--r--glanceclient/tests/unit/test_shell.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/glanceclient/shell.py b/glanceclient/shell.py
index ca10359..3a32bfb 100644
--- a/glanceclient/shell.py
+++ b/glanceclient/shell.py
@@ -166,6 +166,8 @@ class OpenStackImagesShell(object):
parser.add_argument('--os_image_api_version',
help=argparse.SUPPRESS)
+ parser.set_defaults(func=self.do_help)
+
if osprofiler_profiler:
parser.add_argument('--profile',
metavar='HMAC_KEY',
diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py
index 74d1c33..129b127 100644
--- a/glanceclient/tests/unit/test_shell.py
+++ b/glanceclient/tests/unit/test_shell.py
@@ -211,6 +211,14 @@ class ShellTest(testutils.TestCase):
self.assertEqual(0, actual)
self.assertFalse(et_mock.called)
+ def test_help_no_subcommand(self):
+ shell = openstack_shell.OpenStackImagesShell()
+ argstr = '--os-image-api-version 2'
+ with mock.patch.object(shell, '_get_keystone_auth_plugin') as et_mock:
+ actual = shell.main(argstr.split())
+ self.assertEqual(0, actual)
+ self.assertFalse(et_mock.called)
+
def test_blank_call(self):
shell = openstack_shell.OpenStackImagesShell()
with mock.patch.object(shell, '_get_keystone_auth_plugin') as et_mock: