Suppress InsecureRequestWarning when using --insecure
The user already knows this is insecure, there's no point in bringing it up again and again. See also: https://github.com/kennethreitz/requests/issues/2214 Change-Id: I7991b2e568407269f84138bc03711147ed080c9c
This commit is contained in:
@@ -1524,6 +1524,11 @@ Examples:
|
|||||||
|
|
||||||
with OutputManager() as output:
|
with OutputManager() as output:
|
||||||
parser.usage = globals()['st_%s_help' % args[0]]
|
parser.usage = globals()['st_%s_help' % args[0]]
|
||||||
|
if options['insecure']:
|
||||||
|
import requests
|
||||||
|
from requests.packages.urllib3.exceptions import \
|
||||||
|
InsecureRequestWarning
|
||||||
|
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
|
||||||
try:
|
try:
|
||||||
globals()['st_%s' % args[0]](parser, argv[1:], output)
|
globals()['st_%s' % args[0]](parser, argv[1:], output)
|
||||||
except ClientException as err:
|
except ClientException as err:
|
||||||
|
@@ -23,7 +23,7 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
from requests.packages.urllib3.exceptions import InsecureRequestWarning
|
||||||
import six
|
import six
|
||||||
|
|
||||||
import swiftclient
|
import swiftclient
|
||||||
@@ -1899,15 +1899,23 @@ class TestKeystoneOptions(MockHttpTest):
|
|||||||
auth_token=token)
|
auth_token=token)
|
||||||
|
|
||||||
with mock.patch('swiftclient.client._import_keystone_client',
|
with mock.patch('swiftclient.client._import_keystone_client',
|
||||||
_make_fake_import_keystone_client(fake_ks)):
|
_make_fake_import_keystone_client(fake_ks)), \
|
||||||
with mock.patch('swiftclient.client.http_connection', fake_conn):
|
mock.patch('swiftclient.client.http_connection', fake_conn), \
|
||||||
with mock.patch.dict(os.environ, env, clear=True):
|
mock.patch.dict(os.environ, env, clear=True), \
|
||||||
try:
|
mock.patch('requests.packages.urllib3.disable_warnings') as \
|
||||||
swiftclient.shell.main(args)
|
mock_disable_warnings:
|
||||||
except SystemExit as e:
|
try:
|
||||||
self.fail('Unexpected SystemExit: %s' % e)
|
swiftclient.shell.main(args)
|
||||||
except SwiftError as err:
|
except SystemExit as e:
|
||||||
self.fail('Unexpected SwiftError: %s' % err)
|
self.fail('Unexpected SystemExit: %s' % e)
|
||||||
|
except SwiftError as err:
|
||||||
|
self.fail('Unexpected SwiftError: %s' % err)
|
||||||
|
|
||||||
|
if 'insecure' in flags:
|
||||||
|
self.assertEqual([mock.call(InsecureRequestWarning)],
|
||||||
|
mock_disable_warnings.mock_calls)
|
||||||
|
else:
|
||||||
|
self.assertEqual([], mock_disable_warnings.mock_calls)
|
||||||
|
|
||||||
if no_auth:
|
if no_auth:
|
||||||
# check that keystone client was not used and terminate tests
|
# check that keystone client was not used and terminate tests
|
||||||
|
Reference in New Issue
Block a user