Ejemplo n.º 1
0
def test_parse_simple_raid():
    config = _parse_blockstore_params([
        "raid0:0:MOCKED",
        "raid0:1:POSTGRESQL",
        "raid0:2:s3:s3.example.com:region1:bucketA:key123:S3cr3t",
        "raid0:3:swift:swift.example.com:tenant2:containerB:user123:S3cr3t",
    ])
    assert config == RAID0BlockStoreConfig(blockstores=[
        MockedBlockStoreConfig(),
        PostgreSQLBlockStoreConfig(),
        S3BlockStoreConfig(
            s3_endpoint_url="s3.example.com",
            s3_region="region1",
            s3_bucket="bucketA",
            s3_key="key123",
            s3_secret="S3cr3t",
        ),
        SWIFTBlockStoreConfig(
            swift_authurl="swift.example.com",
            swift_tenant="tenant2",
            swift_container="containerB",
            swift_user="******",
            swift_password="******",
        ),
    ])
Ejemplo n.º 2
0
def _parse_blockstore_params(raw_params: str) -> BaseBlockStoreConfig:
    raid_configs = defaultdict(list)
    for raw_param in raw_params:
        raid_mode: Optional[str]
        raid_node: Optional[int]
        raw_param_parts = raw_param.split(":", 2)
        if raw_param_parts[0].upper() in (
                "RAID0", "RAID1", "RAID5") and len(raw_param_parts) == 3:
            raid_mode, raw_raid_node, node_param = raw_param_parts
            try:
                raid_node = int(raw_raid_node)
            except ValueError:
                raise click.BadParameter(
                    f"Invalid node index `{raid_node}` (must be integer)")
        else:
            raid_mode = raid_node = None
            node_param = raw_param
        raid_configs[raid_mode].append((raid_node, node_param))

    if len(raid_configs) != 1:
        config_types = [k if k else v[0][1] for k, v in raid_configs.items()]
        raise click.BadParameter(
            f"Multiple blockstore config with different types: {'/'.join(config_types)}"
        )

    raid_mode, raid_params = list(raid_configs.items())[0]
    if not raid_mode:
        if len(raid_params) == 1:
            return _parse_blockstore_param(raid_params[0][1])
        else:
            raise click.BadParameter(
                "Multiple blockstore configs only available for RAID mode")

    blockstores = []
    for x in count(0):
        if x == len(raid_params):
            break

        x_node_params = [
            node_param for raid_node, node_param in raid_params
            if raid_node == x
        ]
        if len(x_node_params) == 0:
            raise click.BadParameter(
                f"Missing node index `{x}` in RAID config")
        elif len(x_node_params) > 1:
            raise click.BadParameter(
                f"Multiple configuration for node index `{x}` in RAID config")
        blockstores.append(_parse_blockstore_param(x_node_params[0]))

    if raid_mode.upper() == "RAID0":
        return RAID0BlockStoreConfig(blockstores=blockstores)
    elif raid_mode.upper() == "RAID1":
        return RAID1BlockStoreConfig(blockstores=blockstores)
    elif raid_mode.upper() == "RAID5":
        return RAID5BlockStoreConfig(blockstores=blockstores)
    else:
        raise click.BadParameter(
            f"Invalid multi blockstore mode `{raid_mode}`")
Ejemplo n.º 3
0
def blockstore(request, backend_store):
    # TODO: allow to test against swift ?
    if backend_store.startswith("postgresql://"):
        config = PostgreSQLBlockStoreConfig()
    else:
        config = MockedBlockStoreConfig()

    # More or less a hack to be able to to configure this fixture from
    # the test function by adding tags to it
    if request.node.get_closest_marker("raid0_blockstore"):
        config = RAID0BlockStoreConfig(
            blockstores=[config, MockedBlockStoreConfig()])
    if request.node.get_closest_marker("raid1_blockstore"):
        config = RAID1BlockStoreConfig(
            blockstores=[config, MockedBlockStoreConfig()])
    if request.node.get_closest_marker("raid5_blockstore"):
        config = RAID5BlockStoreConfig(blockstores=[
            config, MockedBlockStoreConfig(),
            MockedBlockStoreConfig()
        ])

    return config
Ejemplo n.º 4
0
def blockstore(backend_store, fixtures_customization):
    # TODO: allow to test against swift ?
    if backend_store.startswith("postgresql://"):
        config = PostgreSQLBlockStoreConfig()
    else:
        config = MockedBlockStoreConfig()

    raid = fixtures_customization.get("blockstore_mode", "NO_RAID").upper()
    if raid == "RAID0":
        config = RAID0BlockStoreConfig(
            blockstores=[config, MockedBlockStoreConfig()])
    elif raid == "RAID1":
        config = RAID1BlockStoreConfig(
            blockstores=[config, MockedBlockStoreConfig()])
    elif raid == "RAID1_PARTIAL_CREATE_OK":
        config = RAID1BlockStoreConfig(
            blockstores=[config, MockedBlockStoreConfig()],
            partial_create_ok=True)
    elif raid == "RAID5":
        config = RAID5BlockStoreConfig(blockstores=[
            config, MockedBlockStoreConfig(),
            MockedBlockStoreConfig()
        ])
    elif raid == "RAID5_PARTIAL_CREATE_OK":
        config = RAID5BlockStoreConfig(
            blockstores=[
                config,
                MockedBlockStoreConfig(),
                MockedBlockStoreConfig()
            ],
            partial_create_ok=True,
        )
    else:
        assert raid == "NO_RAID"

    return config