1- from typing import Generator , Any
1+ from typing import Any , Generator
22
33import pytest
4- from ocp_resources .route import Route
5- from ocp_resources .secret import Secret
6- from ocp_resources .service import Service
7- from pytest import FixtureRequest
84from kubernetes .dynamic import DynamicClient
95from ocp_resources .config_map import ConfigMap
106from ocp_resources .deployment import Deployment
139from ocp_resources .persistent_volume_claim import PersistentVolumeClaim
1410from ocp_resources .pod import Pod
1511from ocp_resources .resource import ResourceEditor
12+ from ocp_resources .route import Route
13+ from ocp_resources .secret import Secret
14+ from ocp_resources .service import Service
15+ from pytest import Config , FixtureRequest
1616from pytest_testconfig import py_config
1717
1818from tests .model_explainability .lm_eval .utils import get_lmevaljob_pod
19- from utilities .constants import Labels , Timeout , Annotations , Protocols , MinIo
19+ from utilities .constants import Annotations , Labels , MinIo , Protocols , Timeout
20+ from utilities .exceptions import MissingParameter
2021
2122VLLM_EMULATOR : str = "vllm-emulator"
2223VLLM_EMULATOR_PORT : int = 8000
@@ -29,6 +30,7 @@ def lmevaljob_hf(
2930 admin_client : DynamicClient ,
3031 model_namespace : Namespace ,
3132 patched_trustyai_operator_configmap_allow_online : ConfigMap ,
33+ lmeval_hf_access_token : Secret ,
3234) -> Generator [LMEvalJob , None , None ]:
3335 with LMEvalJob (
3436 client = admin_client ,
@@ -45,6 +47,26 @@ def lmevaljob_hf(
4547 "enabled" : True ,
4648 },
4749 limit = "0.01" ,
50+ pod = {
51+ "container" : {
52+ "resources" : {
53+ "limits" : {"cpu" : "1" , "memory" : "8Gi" },
54+ "requests" : {"cpu" : "1" , "memory" : "8Gi" },
55+ },
56+ "env" : [
57+ {
58+ "name" : "HF_TOKEN" ,
59+ "valueFrom" : {
60+ "secretKeyRef" : {
61+ "name" : "hf-secret" ,
62+ "key" : "HF_ACCESS_TOKEN" ,
63+ },
64+ },
65+ },
66+ {"name" : "HF_ALLOW_CODE_EVAL" , "value" : "1" },
67+ ],
68+ },
69+ },
4870 ) as job :
4971 yield job
5072
@@ -127,7 +149,10 @@ def patched_trustyai_operator_configmap_allow_online(admin_client: DynamicClient
127149 patches = {
128150 configmap : {
129151 "metadata" : {"annotations" : {Annotations .OpenDataHubIo .MANAGED : "false" }},
130- "data" : {"lmes-allow-online" : "true" , "lmes-allow-code-execution" : "true" },
152+ "data" : {
153+ "lmes-allow-online" : "true" ,
154+ "lmes-allow-code-execution" : "true" ,
155+ },
131156 }
132157 }
133158 ):
@@ -404,3 +429,27 @@ def lmevaljob_vllm_emulator_pod(
404429@pytest .fixture (scope = "function" )
405430def lmevaljob_s3_offline_pod (admin_client : DynamicClient , lmevaljob_s3_offline : LMEvalJob ) -> Generator [Pod , Any , Any ]:
406431 yield get_lmevaljob_pod (client = admin_client , lmevaljob = lmevaljob_s3_offline )
432+
433+
434+ @pytest .fixture (scope = "function" )
435+ def lmeval_hf_access_token (
436+ admin_client : DynamicClient ,
437+ model_namespace : Namespace ,
438+ pytestconfig : Config ,
439+ ) -> Secret :
440+ hf_access_token = pytestconfig .option .hf_access_token
441+ if not hf_access_token :
442+ raise MissingParameter (
443+ "HF access token is not set. "
444+ "Either pass with `--hf-access-token` or set `HF_ACCESS_TOKEN` environment variable"
445+ )
446+ with Secret (
447+ client = admin_client ,
448+ name = "hf-secret" ,
449+ namespace = model_namespace .name ,
450+ string_data = {
451+ "HF_ACCESS_TOKEN" : hf_access_token ,
452+ },
453+ wait_for_resource = True ,
454+ ) as secret :
455+ yield secret
0 commit comments