From 703e66d5475be31fa0e2048538e481947ac929cc Mon Sep 17 00:00:00 2001 From: Joe Buck Date: Wed, 21 Aug 2013 15:47:04 -0700 Subject: [PATCH] Add support for default_region Changes to actually use the 'default_region' setting in the S3TEST_CONF file. Previously, the first connection set was assumed to be the default. This means that the parse order of the S3TEST_CONF file was dictating how the tests behaved, resulting in failures in some cases. Signed-off-by: Joe Buck Reviewed-by: Josh Durgin --- s3tests/functional/__init__.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/s3tests/functional/__init__.py b/s3tests/functional/__init__.py index a69a175..ce609a8 100644 --- a/s3tests/functional/__init__.py +++ b/s3tests/functional/__init__.py @@ -182,6 +182,9 @@ class RegionsConn: def iteritems(self): return self.m.iteritems() + def set_default(self, conn): + self.default = conn + def add(self, name, conn): self.m[name] = conn if not self.default: @@ -217,6 +220,12 @@ def setup(): template = 'test-{random}-' prefix = choose_bucket_prefix(template=template) + # pull the default_region out, if it exists + try: + default_region = cfg.get('fixtures', 'default_region') + except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): + default_region = None + s3.clear() config.clear() @@ -263,7 +272,18 @@ def setup(): # TODO test vhost calling format calling_format=conf.calling_format, ) - targets[name].add(k, TargetConnection(conf, conn)) + + temp_targetConn = TargetConnection(conf, conn) + targets[name].add(k, temp_targetConn) + + # Explicitly test for and set the default region, if specified. + # If it was not specified, use the 'is_master' flag to set it. + if default_region: + if default_region == name: + targets[name].set_default(temp_targetConn) + elif conf.is_master: + targets[name].set_default(temp_targetConn) + s3[name] = targets[name].default.connection # WARNING! we actively delete all buckets we see with the prefix