from boto.s3.connection import S3Connection from boto.exception import S3ResponseError try: s3_host = test.s3_store_host access_key = test.s3_store_access_key secret_key = test.s3_store_secret_key bucket_name = test.s3_store_bucket except AttributeError, e: test.disabled_message = ("Failed to find required configuration " "options for S3 store. Got error: %s" % e) test.disabled = True return calling_format = get_calling_format(test.s3_store_bucket_url_format) s3_conn = S3Connection(access_key, secret_key, host=s3_host, is_secure=False, calling_format=calling_format) test.bucket = None try: buckets = s3_conn.get_all_buckets() for bucket in buckets: if bucket.name == bucket_name: test.bucket = bucket except S3ResponseError, e: test.disabled_message = ("Failed to connect to S3 with " "credentials, to find bucket. " "Got error: %s" % e)
def setup_s3(test): # Test machines can set the GLANCE_TEST_S3_CONF variable # to override the location of the config file for S3 testing CONFIG_FILE_PATH = os.environ.get('GLANCE_TEST_S3_CONF') if not CONFIG_FILE_PATH: test.disabled_message = "GLANCE_TEST_S3_CONF environ not set." test.disabled = True return if os.path.exists(CONFIG_FILE_PATH): cp = ConfigParser.RawConfigParser() try: cp.read(CONFIG_FILE_PATH) defaults = cp.defaults() for key, value in defaults.items(): test.__dict__[key] = (_uniq(value) if key == 's3_store_bucket' else value) except ConfigParser.ParsingError as e: test.disabled_message = ("Failed to read test_s3.conf config " "file. Got error: %s" % e) test.disabled = True return from boto.s3.connection import S3Connection from boto.exception import S3ResponseError try: s3_host = test.s3_store_host access_key = test.s3_store_access_key secret_key = test.s3_store_secret_key bucket_name = test.s3_store_bucket except AttributeError as e: test.disabled_message = ("Failed to find required configuration " "options for S3 store. Got error: %s" % e) test.disabled = True return calling_format = get_calling_format(test.s3_store_bucket_url_format) s3_conn = S3Connection(access_key, secret_key, host=s3_host, is_secure=False, calling_format=calling_format) test.bucket = None try: buckets = s3_conn.get_all_buckets() for bucket in buckets: if bucket.name == bucket_name: test.bucket = bucket except S3ResponseError as e: test.disabled_message = ("Failed to connect to S3 with " "credentials, to find bucket. " "Got error: %s" % e) test.disabled = True return except TypeError as e: # This hack is necessary because of a bug in boto 1.9b: # http://code.google.com/p/boto/issues/detail?id=540 test.disabled_message = ("Failed to connect to S3 with " "credentials. Got error: %s" % e) test.disabled = True return test.s3_conn = s3_conn if not test.bucket: location = get_s3_location(test.s3_store_host) try: test.bucket = s3_conn.create_bucket(bucket_name, location=location) except S3ResponseError as e: test.disabled_message = ("Failed to create bucket. " "Got error: %s" % e) test.disabled = True return else: for key in test.bucket.list(): key.delete()
from boto.s3.connection import S3Connection from boto.exception import S3ResponseError try: s3_host = test.s3_store_host access_key = test.s3_store_access_key secret_key = test.s3_store_secret_key bucket_name = test.s3_store_bucket except AttributeError, e: test.disabled_message = ("Failed to find required configuration " "options for S3 store. Got error: %s" % e) test.disabled = True return calling_format = get_calling_format(test.s3_store_bucket_url_format) s3_conn = S3Connection(access_key, secret_key, host=s3_host, is_secure=False, calling_format=calling_format) test.bucket = None try: buckets = s3_conn.get_all_buckets() for bucket in buckets: if bucket.name == bucket_name: test.bucket = bucket except S3ResponseError, e: test.disabled_message = ("Failed to connect to S3 with " "credentials, to find bucket. "