]> git-server-git.apps.pok.os.sepia.ceph.com Git - s3-tests.git/commitdiff
Refactor S3 connection opening.
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Tue, 26 Jul 2011 20:37:17 +0000 (13:37 -0700)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Tue, 26 Jul 2011 21:20:28 +0000 (14:20 -0700)
s3tests/common/__init__.py

index 38189ee54f30aa1c5dd0955241639c1e9db17d30..ba60658d8cfc960ce09c9d7281dae5db4a3ca395 100644 (file)
@@ -91,6 +91,22 @@ def read_config(fp):
         config.update(bunch.bunchify(new))
     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():
     global s3, config, prefix
     s3.clear()
@@ -123,29 +139,11 @@ def setup():
     for section in config.s3.keys():
         if section == 'defaults':
             continue
-        section_config = config.s3[section]
-
-        kwargs = bunch.Bunch()
-        conn_args = bunch.Bunch(
-            port='port',
-            host='host',
-            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
-            )
+
+        conf = {}
+        conf.update(defaults)
+        conf.update(config.s3[section])
+        conn = connect(conf)
         s3[section] = conn
 
     # WARNING! we actively delete all buckets we see with the prefix