Skip to content

Commit daf13fb

Browse files
authored
[model server] Move to using unprivileged_client in tests (#273)
* feat: use unprivileged_client * feat: use unprivileged_client * feat: use unprivileged_client * feat: use unprivileged_client * feat: use unprivileged_client * feat: use unprivileged_client * fix: unpri selection
1 parent be5b35e commit daf13fb

File tree

59 files changed

+419
-314
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+419
-314
lines changed

docs/GETTING_STARTED.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ To check only specific operator, pass `--tc=dependent_operators:<operator_name>`
7474
For example, to check only `Serveless` and `Service Mesh` operators, pass `--tc=dependent_operators:serverless-operator,servicemeshoperator`.
7575

7676

77+
### Running tests with admin client instead of unprivileged client
78+
To run tests with admin client only, pass `--tc=use_unprivileged_client:False` to pytest.
79+
80+
7781
### jira integration
7882
To skip running tests which have open bugs, [pytest_jira](https://github.com/rhevm-qe-automation/pytest_jira) plugin is used.
7983
To run tests with jira integration, you need to set `PYTEST_JIRA_URL` and `PYTEST_JIRA_TOKEN` environment variables.

tests/conftest.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import base64
22
import os
33
import shutil
4+
from ast import literal_eval
45
from typing import Any, Callable, Generator
56

67
import pytest
@@ -24,7 +25,6 @@
2425

2526
from utilities.data_science_cluster_utils import update_components_in_dsc
2627
from utilities.exceptions import ClusterLoginError
27-
from utilities.general import get_s3_secret_dict
2828
from utilities.infra import (
2929
verify_cluster_sanity,
3030
create_ns,
@@ -35,14 +35,13 @@
3535
)
3636
from utilities.constants import (
3737
AcceleratorType,
38-
ApiGroups,
3938
DscComponents,
4039
Labels,
4140
MinIo,
4241
Protocols,
4342
)
4443
from utilities.infra import update_configmap_data
45-
44+
from utilities.minio import create_minio_data_connection_secret
4645

4746
LOGGER = get_logger(name=__name__)
4847

@@ -111,7 +110,7 @@ def model_namespace(
111110
ns.clean_up()
112111
else:
113112
with create_ns(
114-
admin_client=admin_client,
113+
client=admin_client,
115114
pytest_request=request,
116115
teardown=teardown_resources,
117116
) as ns:
@@ -233,10 +232,31 @@ def vllm_runtime_image(pytestconfig: pytest.Config) -> str | None:
233232

234233

235234
@pytest.fixture(scope="session")
236-
def non_admin_user_password(admin_client: DynamicClient) -> tuple[str, str] | None:
235+
def use_unprivileged_client(pytestconfig: pytest.Config) -> bool:
236+
_use_unprivileged_client = py_config.get("use_unprivileged_client")
237+
238+
if isinstance(_use_unprivileged_client, bool):
239+
return _use_unprivileged_client
240+
241+
elif isinstance(_use_unprivileged_client, str):
242+
return literal_eval(_use_unprivileged_client)
243+
244+
else:
245+
raise ValueError(
246+
"use_unprivileged_client is not defined.\n"
247+
"Either pass with `--use-unprivileged-client` or "
248+
"set in `use_unprivileged_client` in `tests/global_config.py`"
249+
)
250+
251+
252+
@pytest.fixture(scope="session")
253+
def non_admin_user_password(admin_client: DynamicClient, use_unprivileged_client: bool) -> tuple[str, str] | None:
237254
def _decode_split_data(_data: str) -> list[str]:
238255
return base64.b64decode(_data).decode().split(",")
239256

257+
if not use_unprivileged_client:
258+
return None
259+
240260
if ldap_Secret := list(
241261
Secret.get(
242262
dyn_client=admin_client,
@@ -269,13 +289,18 @@ def kubconfig_filepath() -> str:
269289
@pytest.fixture(scope="session")
270290
def unprivileged_client(
271291
admin_client: DynamicClient,
292+
use_unprivileged_client: bool,
272293
kubconfig_filepath: str,
273294
non_admin_user_password: tuple[str, str],
274295
) -> Generator[DynamicClient, Any, Any]:
275296
"""
276297
Provides none privileged API client. If non_admin_user_password is None, then it will raise.
277298
"""
278-
if non_admin_user_password is None:
299+
if not use_unprivileged_client:
300+
LOGGER.warning("Unprivileged client is not enabled, using admin client")
301+
yield admin_client
302+
303+
elif non_admin_user_password is None:
279304
raise ValueError("Unprivileged user not provisioned")
280305

281306
else:
@@ -380,7 +405,7 @@ def unprivileged_model_namespace(
380405
def minio_namespace(admin_client: DynamicClient) -> Generator[Namespace, Any, Any]:
381406
with create_ns(
382407
name=f"{MinIo.Metadata.NAME}-{shortuuid.uuid().lower()}",
383-
admin_client=admin_client,
408+
client=admin_client,
384409
) as ns:
385410
yield ns
386411

@@ -451,29 +476,13 @@ def minio_data_connection(
451476
model_namespace: Namespace,
452477
minio_service: Service,
453478
) -> Generator[Secret, Any, Any]:
454-
data_dict = get_s3_secret_dict(
455-
aws_access_key=MinIo.Credentials.ACCESS_KEY_VALUE,
456-
aws_secret_access_key=MinIo.Credentials.SECRET_KEY_VALUE, # pragma: allowlist secret
479+
with create_minio_data_connection_secret(
480+
minio_service=minio_service,
481+
model_namespace=model_namespace.name,
457482
aws_s3_bucket=request.param["bucket"],
458-
aws_s3_endpoint=f"{Protocols.HTTP}://{minio_service.instance.spec.clusterIP}:{str(MinIo.Metadata.DEFAULT_PORT)}", # noqa: E501
459-
aws_s3_region="us-south",
460-
)
461-
462-
with Secret(
463483
client=admin_client,
464-
name="aws-connection-minio-data-connection",
465-
namespace=model_namespace.name,
466-
data_dict=data_dict,
467-
label={
468-
Labels.OpenDataHub.DASHBOARD: "true",
469-
Labels.OpenDataHubIo.MANAGED: "true",
470-
},
471-
annotations={
472-
f"{ApiGroups.OPENDATAHUB_IO}/connection-type": "s3",
473-
"openshift.io/display-name": "Minio Data Connection",
474-
},
475-
) as minio_secret:
476-
yield minio_secret
484+
) as secret:
485+
yield secret
477486

478487

479488
@pytest.fixture(scope="session")

tests/global_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
dsci_name: str = "default-dsci"
77
dependent_operators: str = "servicemeshoperator,authorino-operator,serverless-operator"
88

9+
use_unprivileged_client: bool = True
10+
911
for _dir in dir():
1012
val = locals()[_dir]
1113
if type(val) not in [bool, list, dict, str, int]:

tests/model_registry/negative_tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def model_registry_namespace_for_negative_tests(
2727
) -> Generator[Namespace, Any, Any]:
2828
with create_ns(
2929
name=request.param.get("namespace_name", CUSTOM_NEGATIVE_NS),
30-
admin_client=admin_client,
30+
client=admin_client,
3131
) as ns:
3232
yield ns
3333

0 commit comments

Comments
 (0)