Skip to content

Commit 38b8973

Browse files
authored
Merge branch 'main' into feature/user-creation-tests
2 parents bf68a76 + 24b9c65 commit 38b8973

14 files changed

Lines changed: 955 additions & 863 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ repos:
3636
exclude: .*/__snapshots__/.*|.*-input\.json$
3737

3838
- repo: https://github.com/astral-sh/ruff-pre-commit
39-
rev: v0.14.4
39+
rev: v0.14.5
4040
hooks:
4141
- id: ruff
4242
- id: ruff-format

tests/conftest.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
from utilities.minio import create_minio_data_connection_secret
6262
from utilities.operator_utils import get_csv_related_images, get_cluster_service_version
6363
from ocp_resources.authentication_config_openshift_io import Authentication
64+
from utilities.user_utils import get_unprivileged_context
6465

6566
LOGGER = get_logger(name=__name__)
6667

@@ -409,8 +410,14 @@ def unprivileged_client(
409410

410411
elif is_byoidc:
411412
# this requires a pre-existing context in $KUBECONFIG with a unprivileged user
412-
current_context = run_command(command=["oc", "config", "current-context"])[1].strip()
413-
unprivileged_context = current_context + "-unprivileged"
413+
try:
414+
unprivileged_context, _ = get_unprivileged_context()
415+
except ValueError as e:
416+
raise ValueError(
417+
f"Failed to get unprivileged context for BYOIDC mode. "
418+
f"Ensure the context naming follows the convention: <context>-unprivileged. "
419+
f"Error: {e}"
420+
) from e
414421

415422
unprivileged_client = get_client(config_file=kubconfig_filepath, context=unprivileged_context)
416423

tests/fixtures/vector_io.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def _factory(provider_name: str) -> list[Dict[str, str]]:
6666
env_vars.append({"name": "MILVUS_ENDPOINT", "value": "http://vector-io-milvus-service:19530"})
6767
env_vars.append({"name": "MILVUS_TOKEN", "value": MILVUS_TOKEN})
6868
env_vars.append({"name": "MILVUS_CONSISTENCY_LEVEL", "value": "Bounded"})
69+
elif provider_name == "faiss":
70+
env_vars.append({"name": "ENABLE_FAISS", "value": "faiss"})
71+
env_vars.append({
72+
"name": "FAISS_KVSTORE_DB_PATH",
73+
"value": "/opt/app-root/src/.llama/distributions/rh/sqlite_vec.db",
74+
})
6975

7076
return env_vars
7177

tests/llama_stack/vector_io/test_vector_stores.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@
2424
{"vector_io_provider": "milvus"},
2525
id="vector_io_provider_milvus",
2626
),
27+
pytest.param(
28+
{"name": "test-llamastack-vector-stores", "randomize_name": True},
29+
{
30+
"llama_stack_storage_size": "2Gi",
31+
"vector_io_provider": "faiss",
32+
},
33+
{"vector_io_provider": "faiss"},
34+
id="vector_io_provider_faiss",
35+
),
2736
pytest.param(
2837
{"name": "test-llamastack-vector-stores", "randomize_name": True},
2938
{

tests/model_registry/conftest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from ocp_resources.data_science_cluster import DataScienceCluster
2525
from ocp_resources.deployment import Deployment
2626

27+
2728
from ocp_resources.model_registry_modelregistry_opendatahub_io import ModelRegistry
2829
from ocp_resources.resource import ResourceEditor
2930

@@ -481,7 +482,10 @@ def mr_access_role_binding(
481482

482483
@pytest.fixture(scope="module")
483484
def test_idp_user(
484-
request: pytest.FixtureRequest, original_user: str, api_server_url: str, is_byoidc: bool
485+
request: pytest.FixtureRequest,
486+
original_user: str,
487+
api_server_url: str,
488+
is_byoidc: bool,
485489
) -> Generator[UserTestSession, None, None]:
486490
"""
487491
Session-scoped fixture that creates a test IDP user and cleans it up after all tests.

tests/model_registry/model_catalog/conftest.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
execute_get_command,
2727
get_model_str,
2828
)
29-
from utilities.infra import get_openshift_token, login_with_user_password, create_inference_token
29+
from utilities.infra import get_openshift_token, create_inference_token
3030
from utilities.user_utils import UserTestSession
3131

3232

@@ -106,17 +106,8 @@ def user_token_for_api_calls(
106106
LOGGER.info("Logging in as admin user")
107107
yield get_openshift_token()
108108
elif user == "test":
109-
login_with_user_password(
110-
api_address=api_server_url,
111-
user=test_idp_user.username,
112-
password=test_idp_user.password,
113-
)
109+
# TODO: implement byoidc check in get_openshift_token
114110
yield get_openshift_token()
115-
LOGGER.info(f"Logging in as {original_user}")
116-
login_with_user_password(
117-
api_address=api_server_url,
118-
user=original_user,
119-
)
120111
elif user == "sa_user":
121112
yield create_inference_token(service_account)
122113
else:

tests/model_registry/rbac/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from kubernetes.dynamic import DynamicClient
2020

2121
from tests.model_registry.rbac.utils import create_role_binding
22-
from utilities.infra import login_with_user_password
2322
from utilities.user_utils import UserTestSession
23+
from utilities.infra import login_with_user_password
2424
from tests.model_registry.rbac.group_utils import create_group
2525
from tests.model_registry.constants import (
2626
MR_INSTANCE_NAME,

tests/model_registry/rbac/test_mr_rbac.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@
2323
from ocp_resources.service import Service
2424
from ocp_resources.deployment import Deployment
2525
from tests.model_registry.rbac.multiple_instance_utils import MR_MULTIPROJECT_TEST_SCENARIO_PARAMS
26-
from tests.model_registry.rbac.utils import build_mr_client_args, assert_positive_mr_registry, assert_forbidden_access
26+
from tests.model_registry.rbac.utils import (
27+
build_mr_client_args,
28+
assert_positive_mr_registry,
29+
assert_forbidden_access,
30+
should_skip_rbac_tests,
31+
)
2732
from tests.model_registry.constants import NUM_MR_INSTANCES
2833
from utilities.infra import get_openshift_token
2934
from mr_openapi.exceptions import ForbiddenException
@@ -34,8 +39,15 @@
3439
from tests.model_registry.rbac.utils import grant_mr_access, revoke_mr_access
3540
from utilities.constants import Protocols
3641

42+
3743
LOGGER = get_logger(name=__name__)
38-
pytestmark = [pytest.mark.usefixtures("original_user", "test_idp_user")]
44+
pytestmark = [
45+
pytest.mark.usefixtures("original_user", "test_idp_user"),
46+
pytest.mark.skipif(
47+
should_skip_rbac_tests(),
48+
reason="RBAC tests are not supported in OpenShift 4.20 and later with OIDC authentication",
49+
),
50+
]
3951

4052

4153
@pytest.mark.usefixtures(

tests/model_registry/rbac/test_mr_rbac_sa.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
from utilities.infra import create_inference_token
88
from mr_openapi.exceptions import ForbiddenException
99
from ocp_resources.service_account import ServiceAccount
10+
from tests.model_registry.rbac.utils import should_skip_rbac_tests
1011

1112
LOGGER = get_logger(name=__name__)
13+
pytestmark = [
14+
pytest.mark.skipif(
15+
should_skip_rbac_tests(),
16+
reason="RBAC tests are not supported in OpenShift 4.20 and later with OIDC authentication",
17+
),
18+
]
1219

1320

1421
@pytest.mark.usefixtures(

tests/model_registry/rbac/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
from typing import Any, Dict, Generator, List
22

33
from kubernetes.dynamic import DynamicClient
4+
from semver.version import Version
45
from timeout_sampler import TimeoutSampler
56

7+
from ocp_resources.authentication_config_openshift_io import Authentication
68
from ocp_resources.deployment import Deployment
79
from ocp_resources.role import Role
810
from ocp_resources.role_binding import RoleBinding
11+
from ocp_utilities.cluster_versions import get_cluster_version
912
from utilities.constants import Protocols
1013
import logging
1114
from model_registry import ModelRegistry as ModelRegistryClient
@@ -178,3 +181,20 @@ def assert_forbidden_access(endpoint: str, token: str) -> None:
178181
except ForbiddenException:
179182
# This is what we want - access is properly forbidden
180183
pass
184+
185+
186+
def should_skip_rbac_tests() -> bool:
187+
"""Check if RBAC tests should be skipped"""
188+
# Need to get these details here to use this in the skipif statement.
189+
# Skip RBAC tests on OpenShift 4.20+ with OIDC authentication
190+
# Check BYOIDC
191+
try:
192+
auth = Authentication(name="cluster")
193+
if not auth.exists:
194+
return False
195+
is_byoidc = auth.instance.spec.type == "OIDC"
196+
except Exception:
197+
return False
198+
if not is_byoidc:
199+
return False
200+
return get_cluster_version() >= Version.parse("4.20.0")

0 commit comments

Comments
 (0)