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
This commit is contained in:
Rakesh H S 2014-09-12 15:46:28 +05:30
parent 99078247c7
commit 5000a851d8
2 changed files with 13 additions and 1 deletions

View File

@ -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)

View File

@ -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)