Example #1
0
def upload(step):
        key_path = os.environ.get('GCS_KEY')
        with open(key_path) as f:
            key = base64.b64encode(f.read())
        access_data = dict(service_account_name='*****@*****.**', key=key)
 
        gcs.bus = mock.MagicMock()
        gcs.bus.platform.get_access_data = lambda k: access_data[k]
 
        gsm = GoogleServiceManager(gcs.bus.platform,
                "storage", "v1beta2", *STORAGE_FULL_SCOPE)
 
        gcs.bus.platform.get_numeric_project_id.return_value = '876103924605'
        gcs.bus.platform.new_storage_client = lambda: gsm.get_service()
 
        world.gcs = gcs.GCSFileSystem()
        world.tmpdir = tempfile.mkdtemp()
        # make random file
        tmp_file = os.path.join(world.tmpdir, 'test_file')
        system("dd if=/dev/urandom of=%s bs=1M count=1" % tmp_file, shell=True)
        world.src_md5 = system('md5sum %s' % tmp_file, shell=True)[0]
        LOG.info('MD5 : %s' % world.src_md5)
        world.bucket_name = 'scalr-tests-%s' % str(uuid.uuid4())[:8]
        LOG.info('Bucket name: %s' % world.bucket_name)
 
        world.dst_path = 'gcs://%s/test_file' % world.bucket_name
 
        try:
            world.gcs.ls(world.dst_path)
        except:
            pass
        else:
            raise Exception('Destination path already exist')
        world.gcs.put(tmp_file, world.dst_path)
        os.unlink(tmp_file)
Example #2
0
def upload(step):
        key_path = os.environ.get('GCS_KEY')
        with open(key_path) as f:
            key = base64.b64encode(f.read())
        access_data = dict(service_account_name='*****@*****.**', key=key)

        gcs.bus = mock.MagicMock()
        gcs.bus.platform.get_access_data = lambda k: access_data[k]

        gsm = GoogleServiceManager(gcs.bus.platform,
                "storage", "v1beta2", *STORAGE_FULL_SCOPE)

        gcs.bus.platform.get_numeric_project_id.return_value = '876103924605'
        gcs.bus.platform.new_storage_client = lambda: gsm.get_service()

        world.gcs = gcs.GCSFileSystem()
        world.tmpdir = tempfile.mkdtemp()
        # make random file
        tmp_file = os.path.join(world.tmpdir, 'test_file')
        system("dd if=/dev/urandom of=%s bs=1M count=1" % tmp_file, shell=True)
        world.src_md5 = system('md5sum %s' % tmp_file, shell=True)[0]
        LOG.info('MD5 : %s' % world.src_md5)
        world.bucket_name = 'scalr-tests-%s' % str(uuid.uuid4())[:8]
        LOG.info('Bucket name: %s' % world.bucket_name)

        world.dst_path = 'gcs://%s/test_file' % world.bucket_name

        try:
            world.gcs.ls(world.dst_path)
        except:
            pass
        else:
            raise Exception('Destination path already exist')
        world.gcs.put(tmp_file, world.dst_path)
        os.unlink(tmp_file)
Example #3
0
def setup_feature(feat):
    # prevent ini parser from lowercasing params
    _RESTORE.append((ConfigParser, "optionxform", ConfigParser.optionxform))
    ConfigParser.optionxform = lambda self, x: x

    # make connections work

    if STORAGE == "s3":
        _RESTORE.append((s3.S3FileSystem, "_get_connection",
                         s3.S3FileSystem._get_connection))
        s3.S3FileSystem._get_connection = lambda self: connect_s3()
        s3.S3FileSystem._bucket_location = lambda self: ''

    elif STORAGE == "gcs":

        def get_pk(f="gcs_pk.p12"):  # TODO:
            with open(f, "rb") as fd:
                pk = fd.read()
            return base64.b64encode(pk)

        ACCESS_DATA = {
            "service_account_name":
            '*****@*****.**',
            "key": get_pk(),
        }

        _RESTORE.append((gcs, "bus", gcs.bus))
        gcs.bus = mock.MagicMock()
        gcs.bus.platform.get_access_data = lambda k: ACCESS_DATA[k]

        gsm = GoogleServiceManager(gcs.bus.platform, "storage", "v1beta2",
                                   *STORAGE_FULL_SCOPE)

        gcs.bus.platform.get_numeric_project_id.return_value = '876103924605'
        gcs.bus.platform.new_storage_client = lambda: gsm.get_service()

    elif STORAGE == "swift":
        _RESTORE.append((swift.SwiftFileSystem, "_get_connection",
                         swift.SwiftFileSystem._get_connection))
        swift.SwiftFileSystem._get_connection = lambda self: swiftclient.Connection(
            "https://identity.api.rackspacecloud.com/v1.0", os.environ[
                "RS_USERNAME"], os.environ["RS_API_KEY"])

    elif STORAGE == "swift-enter-it":
        _RESTORE.append((swift.SwiftFileSystem, "_get_connection",
                         swift.SwiftFileSystem._get_connection))
        swift.SwiftFileSystem._get_connection = lambda self: swiftclient.Connection(
            "http://folsom.enter.it:5000/v2.0",
            os.environ["ENTER_IT_USERNAME"],
            os.environ["ENTER_IT_API_KEY"],
            auth_version="2")
Example #4
0
def setup_feature(feat):
    # prevent ini parser from lowercasing params
    _RESTORE.append((ConfigParser, "optionxform",
                                     ConfigParser.optionxform))
    ConfigParser.optionxform = lambda self, x: x

    # make connections work

    if STORAGE == "s3":
        _RESTORE.append((s3.S3FileSystem, "_get_connection",
                                         s3.S3FileSystem._get_connection))
        s3.S3FileSystem._get_connection = lambda self: connect_s3()
        s3.S3FileSystem._bucket_location = lambda self: ''

    elif STORAGE == "gcs":
        def get_pk(f="gcs_pk.p12"):  # TODO:
            with open(f, "rb") as fd:
                pk = fd.read()
            return base64.b64encode(pk)

        ACCESS_DATA = {
                "service_account_name": '*****@*****.**',
                "key": get_pk(),
        }

        _RESTORE.append((gcs, "bus", gcs.bus))
        gcs.bus = mock.MagicMock()
        gcs.bus.platform.get_access_data = lambda k: ACCESS_DATA[k]

        gsm = GoogleServiceManager(gcs.bus.platform,
                "storage", "v1beta1", *STORAGE_FULL_SCOPE)

        gcs.bus.platform.get_numeric_project_id.return_value = '876103924605'
        gcs.bus.platform.new_storage_client = lambda: gsm.get_service()

    elif STORAGE == "swift":
        _RESTORE.append((swift.SwiftFileSystem, "_get_connection",
                                         swift.SwiftFileSystem._get_connection))
        swift.SwiftFileSystem._get_connection = lambda self: swiftclient.Connection(
                        "https://identity.api.rackspacecloud.com/v1.0",
                        os.environ["RS_USERNAME"], os.environ["RS_API_KEY"])

    elif STORAGE == "swift-enter-it":
        _RESTORE.append((swift.SwiftFileSystem, "_get_connection",
                                         swift.SwiftFileSystem._get_connection))
        swift.SwiftFileSystem._get_connection = lambda self: swiftclient.Connection(
                "http://folsom.enter.it:5000/v2.0",
                os.environ["ENTER_IT_USERNAME"], os.environ["ENTER_IT_API_KEY"], auth_version="2")