Merge "handles keyboard interrupt"

This commit is contained in:
Jenkins
2015-02-02 01:06:08 +00:00
committed by Gerrit Code Review
2 changed files with 13 additions and 1 deletions

View File

@@ -461,7 +461,9 @@ class OpenStackHelpFormatter(argparse.HelpFormatter):
def main(): def main():
try: try:
OpenStackIdentityShell().main(sys.argv[1:]) OpenStackIdentityShell().main(sys.argv[1:])
except KeyboardInterrupt:
print("... terminating keystone client", file=sys.stderr)
sys.exit(130)
except Exception as e: except Exception as e:
print(encodeutils.safe_encode(six.text_type(e)), file=sys.stderr) print(encodeutils.safe_encode(six.text_type(e)), file=sys.stderr)
sys.exit(1) sys.exit(1)

View File

@@ -520,3 +520,13 @@ class ShellTest(utils.TestCase):
'http://example.com:4321/go', 'http://example.com:4321/go',
'http://example.com:9876/adm') 'http://example.com:9876/adm')
self.assertTrue(all([x == y for x, y in zip(actual, expect)])) 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)