summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRakesh H S <rh-s@hp.com>2014-09-12 15:46:28 +0530
committerRakesh H S <rh-s@hp.com>2015-01-28 06:15:23 -0800
commit5000a851d8f08c2bc6e1f8db1576a9d51abfebf7 (patch)
tree7995137aaaafb6787fab560330e733239d117631
parent99078247c7af7e82d34c8c95b1542895ba365907 (diff)
downloadpython-keystoneclient-5000a851d8f08c2bc6e1f8db1576a9d51abfebf7.tar.gz
handles keyboard interrupt
When an user intentionally provides an keyboard interrupt, keystoneclient throws the entire traceback on to the terminal instead of handling it. keystoneclient will now handle the keyboard interrrupt and provides an crisp message on to the terminal. Change-Id: I1026d259fd0688dd2b950b1bdb135d219da2a60a Closes-Bug: #1367283
-rw-r--r--keystoneclient/shell.py4
-rw-r--r--keystoneclient/tests/test_shell.py10
2 files changed, 13 insertions, 1 deletions
diff --git a/keystoneclient/shell.py b/keystoneclient/shell.py
index be7330c..16e3a2c 100644
--- a/keystoneclient/shell.py
+++ b/keystoneclient/shell.py
@@ -461,7 +461,9 @@ class OpenStackHelpFormatter(argparse.HelpFormatter):
def main():
try:
OpenStackIdentityShell().main(sys.argv[1:])
-
+ except KeyboardInterrupt:
+ print("... terminating keystone client", file=sys.stderr)
+ sys.exit(130)
except Exception as e:
print(encodeutils.safe_encode(six.text_type(e)), file=sys.stderr)
sys.exit(1)
diff --git a/keystoneclient/tests/test_shell.py b/keystoneclient/tests/test_shell.py
index 65cba9d..842aa4e 100644
--- a/keystoneclient/tests/test_shell.py
+++ b/keystoneclient/tests/test_shell.py
@@ -520,3 +520,13 @@ class ShellTest(utils.TestCase):
'http://example.com:4321/go',
'http://example.com:9876/adm')
self.assertTrue(all([x == y for x, y in zip(actual, expect)]))
+
+ def test_shell_keyboard_interrupt(self):
+ shell_mock = mock.MagicMock()
+ with mock.patch('keystoneclient.shell.OpenStackIdentityShell.main',
+ shell_mock):
+ try:
+ shell_mock.side_effect = KeyboardInterrupt()
+ openstack_shell.main()
+ except SystemExit as ex:
+ self.assertEqual(130, ex.code)