Created
November 9, 2016 18:23
-
-
Save tipabu/1dccb2a46c47b7450bfb4d41a0765d82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import keystoneauth1.loading | |
import keystoneauth1.session | |
import swiftclient.client | |
use_v1 = True | |
do_preauth = False | |
bad_preauth = False | |
if use_v1: | |
loader = keystoneauth1.loading.get_plugin_loader('v1password') | |
auth_plugin = loader.load_from_options( | |
auth_url='http://saio:8080/auth/v1.0', | |
username='test:tester', | |
password='testing') | |
else: | |
loader = keystoneauth1.loading.get_plugin_loader('v2password') | |
auth_plugin = loader.load_from_options( | |
auth_url='http://192.168.201.176:35357/v2.0', | |
username='swiftstack', | |
password='password', | |
tenant_name='SS') | |
keystone_session = keystoneauth1.session.Session(auth_plugin) | |
logging.basicConfig(level=logging.DEBUG) | |
logging.getLogger('swiftclient').setLevel(logging.WARNING) | |
kwargs = {} | |
if do_preauth or bad_preauth: | |
kwargs['preauthurl'] = keystone_session.get_endpoint( | |
service_type='object-store', interface='public') | |
if bad_preauth: | |
kwargs['preauthtoken'] = 'bad' | |
conn = swiftclient.Connection(session=keystone_session, **kwargs) | |
if bad_preauth: | |
print('\nFirst head (with bad token): should get 401, hit auth, and retry') | |
elif do_preauth: | |
print('\nFirst head: should NOT hit auth') | |
else: | |
print('\nFirst head: should hit auth') | |
conn.head_account() | |
print('\nSecond head: should NOT hit auth') | |
conn.head_account() | |
print('\nThird head (with bad token): should get 401, hit auth, and retry') | |
conn.token = 'bad' | |
conn.head_account() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment