forked from TrueCloudLab/s3-tests
Refactor S3 connection opening.
This commit is contained in:
parent
367fd3981a
commit
f30f9d0aca
1 changed files with 20 additions and 22 deletions
|
@ -91,6 +91,22 @@ def read_config(fp):
|
||||||
config.update(bunch.bunchify(new))
|
config.update(bunch.bunchify(new))
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
def connect(conf):
|
||||||
|
mapping = dict(
|
||||||
|
port='port',
|
||||||
|
host='host',
|
||||||
|
is_secure='is_secure',
|
||||||
|
access_key='aws_access_key_id',
|
||||||
|
secret_key='aws_secret_access_key',
|
||||||
|
)
|
||||||
|
kwargs = dict((mapping[k],v) for (k,v) in conf.iteritems() if k in mapping)
|
||||||
|
conn = boto.s3.connection.S3Connection(
|
||||||
|
# TODO support & test all variations
|
||||||
|
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
return conn
|
||||||
|
|
||||||
def setup():
|
def setup():
|
||||||
global s3, config, prefix
|
global s3, config, prefix
|
||||||
s3.clear()
|
s3.clear()
|
||||||
|
@ -123,29 +139,11 @@ def setup():
|
||||||
for section in config.s3.keys():
|
for section in config.s3.keys():
|
||||||
if section == 'defaults':
|
if section == 'defaults':
|
||||||
continue
|
continue
|
||||||
section_config = config.s3[section]
|
|
||||||
|
|
||||||
kwargs = bunch.Bunch()
|
conf = {}
|
||||||
conn_args = bunch.Bunch(
|
conf.update(defaults)
|
||||||
port='port',
|
conf.update(config.s3[section])
|
||||||
host='host',
|
conn = connect(conf)
|
||||||
is_secure='is_secure',
|
|
||||||
access_key='aws_access_key_id',
|
|
||||||
secret_key='aws_secret_access_key',
|
|
||||||
)
|
|
||||||
for cfg_key in conn_args.keys():
|
|
||||||
conn_key = conn_args[cfg_key]
|
|
||||||
|
|
||||||
if section_config.has_key(cfg_key):
|
|
||||||
kwargs[conn_key] = section_config[cfg_key]
|
|
||||||
elif defaults.has_key(cfg_key):
|
|
||||||
kwargs[conn_key] = defaults[cfg_key]
|
|
||||||
|
|
||||||
conn = boto.s3.connection.S3Connection(
|
|
||||||
# TODO support & test all variations
|
|
||||||
calling_format=boto.s3.connection.OrdinaryCallingFormat(),
|
|
||||||
**kwargs
|
|
||||||
)
|
|
||||||
s3[section] = conn
|
s3[section] = conn
|
||||||
|
|
||||||
# WARNING! we actively delete all buckets we see with the prefix
|
# WARNING! we actively delete all buckets we see with the prefix
|
||||||
|
|
Loading…
Reference in a new issue