-
Notifications
You must be signed in to change notification settings - Fork 63
test(evalhub): add multi-tenancy integration tests #1333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
6c43426
test(evalhub): add multi-tenancy integration tests
ruivieira add0f4c
fix(evalhub): add missing type annotation for admin_client parameter
ruivieira 48b90ca
fix(evalhub): log correct job ID from nested response structure
ruivieira 73e492c
test(multitenancy): generate unique namespace names per test class in…
ruivieira 4e71633
test(multitenancy): extend rbac readiness check to include job servic…
ruivieira 390136c
test(evalhub): add body-level assertions to cross-tenant and no-tenan…
ruivieira 0e98602
test(evalhub): return full response from delete_evalhub_job and add b…
ruivieira 2ba5784
Merge branch 'main' into evalhub-tests
ruivieira 7d85522
fix: linting
ruivieira fcc4dcc
Merge remote-tracking branch 'origin/evalhub-tests' into evalhub-tests
ruivieira c550a23
fix(evalhub): replace blind exception catches with ValueError in resp…
ruivieira 4a7a663
test(evalhub): add tcpSocket readiness probe to vllm emulator deployment
ruivieira 3445c93
test(evalhub): add body-level assertion to no-tenant GET validator
ruivieira 3397bb7
test(evalhub): assert arc_easy benchmark id and metrics in job comple…
ruivieira 86699eb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ec5a9f4
test(evalhub): raise RuntimeError with context when operator RBAC pro…
ruivieira fb1c8b5
fix(evalhub): replace unreachable return with TimeoutExpiredError in …
ruivieira 078edc9
Merge remote-tracking branch 'origin/evalhub-tests' into evalhub-tests
ruivieira db31bb5
style(evalhub): wrap long error message in timeout handler to fix E501
ruivieira a5c4b96
fix(multitenancy): preserve exception chain in RBAC timeout handler
ruivieira a18bfd5
fix(multitenancy): tighten EVALHUB_USER_ROLE_RULES type annotation
ruivieira 041e66c
fix(multitenancy): extract status_code from delete_evalhub_job response
ruivieira 9b10488
Merge branch 'main' into evalhub-tests
dbasunag 4c31953
Merge branch 'main' into evalhub-tests
sheltoncyril File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
321 changes: 321 additions & 0 deletions
321
tests/model_explainability/evalhub/multitenancy/conftest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,321 @@ | ||
| from collections.abc import Generator | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| import structlog | ||
| from kubernetes.dynamic import DynamicClient | ||
| from ocp_resources.deployment import Deployment | ||
| from ocp_resources.namespace import Namespace | ||
| from ocp_resources.role import Role | ||
| from ocp_resources.role_binding import RoleBinding | ||
| from ocp_resources.route import Route | ||
| from ocp_resources.service import Service | ||
| from ocp_resources.service_account import ServiceAccount | ||
| from timeout_sampler import TimeoutSampler | ||
|
|
||
| from tests.model_explainability.evalhub.constants import ( | ||
| EVALHUB_MT_CR_NAME, | ||
| EVALHUB_TENANT_LABEL_KEY, | ||
| EVALHUB_VLLM_EMULATOR_PORT, | ||
| ) | ||
| from utilities.certificates_utils import create_ca_bundle_file | ||
| from utilities.constants import Labels, Protocols, Timeout | ||
| from utilities.infra import create_inference_token, create_ns | ||
| from utilities.resources.evalhub import EvalHub | ||
|
|
||
| LOGGER = structlog.get_logger(name=__name__) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # EvalHub instance (shared across the class) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def evalhub_mt_cr( | ||
| admin_client: DynamicClient, | ||
| model_namespace: Namespace, | ||
| ) -> Generator[EvalHub, Any, Any]: | ||
| """Create an EvalHub CR for multi-tenancy tests. | ||
|
|
||
| Uses a distinct name ('evalhub-mt') to avoid RoleBinding name collisions | ||
| with the production EvalHub instance. The operator names tenant RoleBindings | ||
| as '{instance.Name}-{ns}-job-config-rb' and uses Get-or-Create (not Update), | ||
| so two instances named 'evalhub' would collide and the first one wins. | ||
| """ | ||
| with EvalHub( | ||
| client=admin_client, | ||
| name="evalhub-mt", | ||
| namespace=model_namespace.name, | ||
| database={"type": "sqlite"}, | ||
| wait_for_resource=True, | ||
| ) as evalhub: | ||
| yield evalhub | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def evalhub_mt_deployment( | ||
| admin_client: DynamicClient, | ||
| model_namespace: Namespace, | ||
| evalhub_mt_cr: EvalHub, | ||
| ) -> Deployment: | ||
| """Wait for the EvalHub deployment to become available.""" | ||
| deployment = Deployment( | ||
| client=admin_client, | ||
| name=evalhub_mt_cr.name, | ||
| namespace=model_namespace.name, | ||
| ) | ||
| deployment.wait_for_replicas(timeout=Timeout.TIMEOUT_5MIN) | ||
| return deployment | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def evalhub_mt_route( | ||
| admin_client: DynamicClient, | ||
| model_namespace: Namespace, | ||
| evalhub_mt_deployment: Deployment, | ||
| ) -> Route: | ||
| """Get the Route for the EvalHub service.""" | ||
| return Route( | ||
| client=admin_client, | ||
| name=evalhub_mt_deployment.name, | ||
| namespace=model_namespace.name, | ||
| ensure_exists=True, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def evalhub_mt_ca_bundle_file( | ||
| admin_client: DynamicClient, | ||
| ) -> str: | ||
| """CA bundle file for verifying TLS on the EvalHub route.""" | ||
| return create_ca_bundle_file(client=admin_client) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Tenant namespaces | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tenant_a_namespace( | ||
| admin_client: DynamicClient, | ||
| ) -> Generator[Namespace, Any, Any]: | ||
| """Tenant namespace where the test user HAS access.""" | ||
| with create_ns( | ||
| admin_client=admin_client, | ||
| name="test-evalhub-tenant-a", | ||
| labels={EVALHUB_TENANT_LABEL_KEY: "true"}, | ||
| ) as ns: | ||
| yield ns | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tenant_b_namespace( | ||
| admin_client: DynamicClient, | ||
| ) -> Generator[Namespace, Any, Any]: | ||
| """Tenant namespace where the test user does NOT have access.""" | ||
| with create_ns( | ||
| admin_client=admin_client, | ||
| name="test-evalhub-tenant-b", | ||
| labels={EVALHUB_TENANT_LABEL_KEY: "true"}, | ||
| ) as ns: | ||
| yield ns | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # Wait for operator to provision tenant RBAC | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def _tenant_rbac_ready(admin_client: DynamicClient, namespace: str) -> bool: | ||
| """Check if the operator has provisioned job RBAC for the test EvalHub instance.""" | ||
| rbs = list(RoleBinding.get(client=admin_client, namespace=namespace)) | ||
| rb_names = [rb.name for rb in rbs] | ||
| # Look for RoleBindings prefixed with the test instance name to avoid | ||
| # matching RoleBindings from the production EvalHub instance. | ||
| has_job_config = any(name.startswith(EVALHUB_MT_CR_NAME) and "job-config" in name for name in rb_names) | ||
| has_job_writer = any(name.startswith(EVALHUB_MT_CR_NAME) and "job-writer" in name for name in rb_names) | ||
| return has_job_config and has_job_writer | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tenant_a_rbac_ready( | ||
| admin_client: DynamicClient, | ||
| tenant_a_namespace: Namespace, | ||
| evalhub_mt_deployment: Deployment, | ||
| ) -> None: | ||
| """Wait for the operator to provision job RBAC in tenant-a. | ||
|
|
||
| The operator watches for namespaces with the tenant label and | ||
| creates jobs-writer + job-config RoleBindings. This fixture | ||
| blocks until those RoleBindings exist. | ||
| """ | ||
| for ready in TimeoutSampler( | ||
| wait_timeout=120, | ||
| sleep=5, | ||
| func=_tenant_rbac_ready, | ||
| admin_client=admin_client, | ||
| namespace=tenant_a_namespace.name, | ||
| ): | ||
| if ready: | ||
| LOGGER.info(f"Operator RBAC provisioned in {tenant_a_namespace.name}") | ||
| return | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # ServiceAccount and RBAC (only in tenant-a) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| # Mirrors the user RBAC template from resources/evalhub-user-rbac-template.yaml. | ||
| # evaluations/collections/providers are virtual SAR resources — not real CRDs. | ||
| EVALHUB_USER_ROLE_RULES: list[dict] = [ | ||
| { | ||
| "apiGroups": ["trustyai.opendatahub.io"], | ||
| "resources": ["evaluations", "collections", "providers"], | ||
| "verbs": ["get", "list", "create", "update", "delete"], | ||
| }, | ||
| { | ||
| "apiGroups": ["mlflow.kubeflow.org"], | ||
| "resources": ["experiments"], | ||
| "verbs": ["create", "get"], | ||
| }, | ||
| ] | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tenant_a_service_account( | ||
| admin_client: DynamicClient, | ||
| tenant_a_namespace: Namespace, | ||
| ) -> Generator[ServiceAccount, Any, Any]: | ||
| """ServiceAccount in tenant-a for multi-tenancy tests.""" | ||
| with ServiceAccount( | ||
| client=admin_client, | ||
| name="evalhub-test-user", | ||
| namespace=tenant_a_namespace.name, | ||
| wait_for_resource=True, | ||
| ) as sa: | ||
| yield sa | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tenant_a_evalhub_role( | ||
| admin_client: DynamicClient, | ||
| tenant_a_namespace: Namespace, | ||
| ) -> Generator[Role, Any, Any]: | ||
| """Role granting full EvalHub API access in tenant-a (virtual SAR resources).""" | ||
| with Role( | ||
| client=admin_client, | ||
| name="evalhub-test-user-access", | ||
| namespace=tenant_a_namespace.name, | ||
| rules=EVALHUB_USER_ROLE_RULES, | ||
| wait_for_resource=True, | ||
| ) as role: | ||
| yield role | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tenant_a_evalhub_role_binding( | ||
| admin_client: DynamicClient, | ||
| tenant_a_namespace: Namespace, | ||
| tenant_a_service_account: ServiceAccount, | ||
| tenant_a_evalhub_role: Role, | ||
| ) -> Generator[RoleBinding, Any, Any]: | ||
| """RoleBinding granting the test SA EvalHub access in tenant-a only.""" | ||
| with RoleBinding( | ||
| client=admin_client, | ||
| name="evalhub-test-user-binding", | ||
| namespace=tenant_a_namespace.name, | ||
| subjects_kind="ServiceAccount", | ||
| subjects_name=tenant_a_service_account.name, | ||
| role_ref_kind="Role", | ||
| role_ref_name=tenant_a_evalhub_role.name, | ||
| wait_for_resource=True, | ||
| ) as rb: | ||
| yield rb | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tenant_a_token( | ||
| tenant_a_service_account: ServiceAccount, | ||
| tenant_a_evalhub_role_binding: RoleBinding, | ||
| ) -> str: | ||
| """Bearer token for the test SA (has access to tenant-a, not tenant-b).""" | ||
| return create_inference_token(model_service_account=tenant_a_service_account) | ||
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # vLLM emulator (deployed in tenant-a for job submission tests) | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
| VLLM_EMULATOR: str = "vllm-emulator" | ||
| VLLM_EMULATOR_IMAGE: str = ( | ||
| "quay.io/trustyai_testing/vllm_emulator@sha256:c4bdd5bb93171dee5b4c8454f36d7c42b58b2a4ceb74f29dba5760ac53b5c12d" | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def evalhub_vllm_emulator_deployment( | ||
| admin_client: DynamicClient, | ||
| tenant_a_namespace: Namespace, | ||
| tenant_a_rbac_ready: None, | ||
| ) -> Generator[Deployment, Any, Any]: | ||
| """Deploy the vLLM emulator in tenant-a. | ||
|
|
||
| Depends on tenant_a_rbac_ready to ensure the operator has provisioned | ||
| the jobs-writer and job-config RoleBindings before any job is submitted. | ||
| """ | ||
| label = {Labels.Openshift.APP: VLLM_EMULATOR} | ||
| with Deployment( | ||
| client=admin_client, | ||
| namespace=tenant_a_namespace.name, | ||
| name=VLLM_EMULATOR, | ||
| label=label, | ||
| selector={"matchLabels": label}, | ||
| template={ | ||
| "metadata": { | ||
| "labels": label, | ||
| "name": VLLM_EMULATOR, | ||
| }, | ||
| "spec": { | ||
| "containers": [ | ||
| { | ||
| "image": VLLM_EMULATOR_IMAGE, | ||
| "name": VLLM_EMULATOR, | ||
| "securityContext": { | ||
| "allowPrivilegeEscalation": False, | ||
| "capabilities": {"drop": ["ALL"]}, | ||
| "seccompProfile": {"type": "RuntimeDefault"}, | ||
| }, | ||
| } | ||
| ] | ||
| }, | ||
| }, | ||
| replicas=1, | ||
| ) as deployment: | ||
| deployment.wait_for_replicas(timeout=Timeout.TIMEOUT_5MIN) | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| yield deployment | ||
|
|
||
|
|
||
| @pytest.fixture(scope="class") | ||
| def evalhub_vllm_emulator_service( | ||
| admin_client: DynamicClient, | ||
| tenant_a_namespace: Namespace, | ||
| evalhub_vllm_emulator_deployment: Deployment, | ||
| ) -> Generator[Service, Any, Any]: | ||
| """Service fronting the vLLM emulator in tenant-a.""" | ||
| with Service( | ||
| client=admin_client, | ||
| namespace=tenant_a_namespace.name, | ||
| name=f"{VLLM_EMULATOR}-service", | ||
| ports=[ | ||
| { | ||
| "name": f"{VLLM_EMULATOR}-endpoint", | ||
| "port": EVALHUB_VLLM_EMULATOR_PORT, | ||
| "protocol": Protocols.TCP, | ||
| "targetPort": EVALHUB_VLLM_EMULATOR_PORT, | ||
| } | ||
| ], | ||
| selector={Labels.Openshift.APP: VLLM_EMULATOR}, | ||
| ) as service: | ||
| yield service | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.