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}`")
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
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