add calling_format switch in functional and common

Add calling_format switch with options ordinary, subdomain, and vhost to
s3tests/functional/__init__.py and /s3tests/common.py to allow the use
of OrdinaryCallingFormat, SubdomainCallingFormat, and VHostCallingFormat
in the config files for the nosetests and the tools using the common
parser.
This commit is contained in:
Matthew Wodrich 2011-11-03 10:22:23 -07:00
parent dec5360c92
commit c4bded31c2
2 changed files with 35 additions and 6 deletions

View file

@ -93,11 +93,23 @@ def connect(conf):
secret_key='aws_secret_access_key', secret_key='aws_secret_access_key',
) )
kwargs = dict((mapping[k],v) for (k,v) in conf.iteritems() if k in mapping) kwargs = dict((mapping[k],v) for (k,v) in conf.iteritems() if k in mapping)
conn = boto.s3.connection.S3Connection( #process calling_format argument
# TODO support & test all variations calling_formats = dict(
calling_format=boto.s3.connection.OrdinaryCallingFormat(), ordinary=boto.s3.connection.OrdinaryCallingFormat(),
**kwargs subdomain=boto.s3.connection.SubdomainCallingFormat(),
vhost=boto.s3.connection.VHostCallingFormat(),
) )
kwargs['calling_format'] = calling_formats['ordinary']
if conf.has_key('calling_format'):
raw_calling_format = conf['calling_format']
try:
kwargs['calling_format'] = calling_formats[raw_calling_format]
except KeyError:
raise RuntimeError(
'calling_format unknown: %r' % raw_calling_format
)
# TODO test vhost calling format
conn = boto.s3.connection.S3Connection(**kwargs)
return conn return conn
def setup(): def setup():

View file

@ -96,6 +96,11 @@ def setup():
s3.clear() s3.clear()
config.clear() config.clear()
calling_formats = dict(
ordinary=boto.s3.connection.OrdinaryCallingFormat(),
subdomain=boto.s3.connection.SubdomainCallingFormat(),
vhost=boto.s3.connection.VHostCallingFormat(),
)
for section in cfg.sections(): for section in cfg.sections():
try: try:
(type_, name) = section.split(None, 1) (type_, name) = section.split(None, 1)
@ -108,6 +113,18 @@ def setup():
except ConfigParser.NoOptionError: except ConfigParser.NoOptionError:
port = None port = None
try:
raw_calling_format = cfg.get(section, 'calling_format')
except ConfigParser.NoOptionError:
raw_calling_format = 'ordinary'
try:
calling_format = calling_formats[raw_calling_format]
except KeyError:
raise RuntimeError(
'calling_format unknown: %r' % raw_calling_format
)
config[name] = bunch.Bunch() config[name] = bunch.Bunch()
for var in [ for var in [
'user_id', 'user_id',
@ -124,8 +141,8 @@ def setup():
is_secure=cfg.getboolean(section, 'is_secure'), is_secure=cfg.getboolean(section, 'is_secure'),
port=port, port=port,
host=cfg.get(section, 'host'), host=cfg.get(section, 'host'),
# TODO support & test all variations # TODO test vhost calling format
calling_format=boto.s3.connection.OrdinaryCallingFormat(), calling_format=calling_format,
) )
s3[name] = conn s3[name] = conn