[#344] Make user fixture parametrized to allow dedicated user creation
All checks were successful
DCO check / DCO (pull_request) Successful in 1m50s

Signed-off-by: a.berezin <a.berezin@yadro.com>
This commit is contained in:
Andrey Berezin 2024-12-16 17:32:26 +03:00
parent c75352e267
commit 4eef2f2437
3 changed files with 39 additions and 11 deletions

View file

@ -20,6 +20,7 @@ from ....helpers.container_access import (
@pytest.mark.sanity @pytest.mark.sanity
@pytest.mark.bearer @pytest.mark.bearer
@pytest.mark.ape @pytest.mark.ape
@pytest.mark.parametrize("user_tag", ["ApeBearer"], indirect=True) # provide dedicated user with no APE side-policies
class TestApeBearer(ClusterTestBase): class TestApeBearer(ClusterTestBase):
@allure.title("Operations with BearerToken (role={role}, obj_size={object_size})") @allure.title("Operations with BearerToken (role={role}, obj_size={object_size})")
@pytest.mark.parametrize("role", [ape.Role.OWNER, ape.Role.OTHERS], indirect=True) @pytest.mark.parametrize("role", [ape.Role.OWNER, ape.Role.OTHERS], indirect=True)

View file

@ -20,6 +20,7 @@ REP1_MSK = ContainerRequest("REP 1 IN MOW CBF 1 SELECT 1 FROM MSK AS MOW FILTER
@pytest.mark.ape_object @pytest.mark.ape_object
@pytest.mark.ape_allow @pytest.mark.ape_allow
@pytest.mark.parametrize("container_request", [REP1_MSK], indirect=True) @pytest.mark.parametrize("container_request", [REP1_MSK], indirect=True)
@pytest.mark.parametrize("user_tag", ["ApeLocalOverrideAllow"], indirect=True) # provide dedicated user with no APE side-policies
class TestApeLocalOverrideAllow(ClusterTestBase): class TestApeLocalOverrideAllow(ClusterTestBase):
@allure.title("LocalOverride: Allow to GetObject in root tenant") @allure.title("LocalOverride: Allow to GetObject in root tenant")
def test_local_override_allow_to_get_object_root( def test_local_override_allow_to_get_object_root(

View file

@ -207,8 +207,8 @@ def ec_placement_policy() -> PlacementPolicy:
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@allure.title("Init Frostfs CLI") @allure.title("Init Frostfs CLI")
def frostfs_cli(client_shell: Shell, default_wallet: WalletInfo) -> FrostfsCli: def frostfs_cli(client_shell: Shell, wallet: WalletInfo) -> FrostfsCli:
return FrostfsCli(client_shell, FROSTFS_CLI_EXEC, default_wallet.config_path) return FrostfsCli(client_shell, FROSTFS_CLI_EXEC, wallet.config_path)
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@ -288,17 +288,17 @@ def credentials_provider(cluster: Cluster) -> CredentialsProvider:
], ],
) )
def s3_client( def s3_client(
default_user: User, user: User,
s3_policy: Optional[str], s3_policy: Optional[str],
cluster: Cluster, cluster: Cluster,
request: pytest.FixtureRequest, request: pytest.FixtureRequest,
credentials_provider: CredentialsProvider, credentials_provider: CredentialsProvider,
) -> S3ClientWrapper: ) -> S3ClientWrapper:
node = cluster.cluster_nodes[0] node = cluster.cluster_nodes[0]
credentials_provider.S3.provide(default_user, node, s3_policy) credentials_provider.S3.provide(user, node, s3_policy)
s3_client_cls = request.param s3_client_cls = request.param
client = s3_client_cls(default_user.s3_credentials.access_key, default_user.s3_credentials.secret_key, cluster.default_s3_gate_endpoint) client = s3_client_cls(user.s3_credentials.access_key, user.s3_credentials.secret_key, cluster.default_s3_gate_endpoint)
return client return client
@ -466,10 +466,36 @@ def users_pool(credentials_provider: CredentialsProvider, cluster: Cluster) -> l
return users return users
@pytest.fixture(scope="session")
def user_tag(request: pytest.FixtureRequest) -> str:
tag = "default"
if "param" in request.__dict__:
tag = request.param
return tag
@pytest.fixture(scope="session")
@cached_fixture(optionals.OPTIONAL_CACHE_FIXTURES)
@reporter.step("Create {user_tag} user")
def user(user_tag: str) -> User:
user = User(string_utils.unique_name("user-"))
user.attributes["tag"] = user_tag
return user
@pytest.fixture(scope="session")
def wallet(user: User, credentials_provider: CredentialsProvider, cluster: Cluster) -> WalletInfo:
credentials_provider.GRPC.provide(user, cluster.cluster_nodes[0])
return user.wallet
# TODO: Migrate tests to fixture wallet above
@reporter.step("Get wallet for default user") @reporter.step("Get wallet for default user")
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def default_wallet(default_user: User) -> WalletInfo: def default_wallet(wallet) -> WalletInfo:
return default_user.wallet return wallet
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@ -544,26 +570,26 @@ def multiple_containers_request(request: pytest.FixtureRequest) -> ContainerRequ
@pytest.fixture @pytest.fixture
def container( def container(
default_wallet: WalletInfo, wallet: WalletInfo,
frostfs_cli: FrostfsCli, frostfs_cli: FrostfsCli,
client_shell: Shell, client_shell: Shell,
cluster: Cluster, cluster: Cluster,
rpc_endpoint: str, rpc_endpoint: str,
container_request: ContainerRequest, container_request: ContainerRequest,
) -> str: ) -> str:
return create_container_with_ape(container_request, frostfs_cli, default_wallet, client_shell, cluster, rpc_endpoint) return create_container_with_ape(container_request, frostfs_cli, wallet, client_shell, cluster, rpc_endpoint)
@pytest.fixture @pytest.fixture
def containers( def containers(
default_wallet: WalletInfo, wallet: WalletInfo,
frostfs_cli: FrostfsCli, frostfs_cli: FrostfsCli,
client_shell: Shell, client_shell: Shell,
cluster: Cluster, cluster: Cluster,
rpc_endpoint: str, rpc_endpoint: str,
multiple_containers_request: MultipleContainersRequest, multiple_containers_request: MultipleContainersRequest,
) -> list[str]: ) -> list[str]:
return create_containers_with_ape(frostfs_cli, default_wallet, client_shell, cluster, rpc_endpoint, multiple_containers_request) return create_containers_with_ape(frostfs_cli, wallet, client_shell, cluster, rpc_endpoint, multiple_containers_request)
@pytest.fixture() @pytest.fixture()