Skip to content

Commit abc78fb

Browse files
Bobbins228jgarciao
andauthored
test: add postgres sql backend for rag tests (#954)
Co-authored-by: Jorge <jgarciao@users.noreply.github.com>
1 parent 9d5f2a1 commit abc78fb

File tree

1 file changed

+89
-1
lines changed

1 file changed

+89
-1
lines changed

tests/llama_stack/conftest.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,21 @@
2727
LLS_OPENSHIFT_MINIMAL_VERSION,
2828
ModelInfo,
2929
)
30-
30+
from ocp_resources.service import Service
3131

3232
LOGGER = get_logger(name=__name__)
3333

34+
POSTGRES_IMAGE = os.getenv(
35+
"LLS_VECTOR_IO_POSTGRES_IMAGE",
36+
(
37+
"registry.redhat.io/rhel9/postgresql-15@sha256:"
38+
"90ec347a35ab8a5d530c8d09f5347b13cc71df04f3b994bfa8b1a409b1171d59" # postgres 15 # pragma: allowlist secret
39+
),
40+
)
41+
42+
POSTGRESQL_USER = os.getenv("LLS_VECTOR_IO_POSTGRESQL_USER", "ps_user")
43+
POSTGRESQL_PASSWORD = os.getenv("LLS_VECTOR_IO_POSTGRESQL_PASSWORD", "ps_password")
44+
3445
distribution_name = generate_random_name(prefix="llama-stack-distribution")
3546

3647

@@ -102,6 +113,8 @@ def enabled_llama_stack_operator(dsc_resource: DataScienceCluster) -> Generator[
102113
@pytest.fixture(scope="class")
103114
def llama_stack_server_config(
104115
request: FixtureRequest,
116+
postgres_deployment: Deployment,
117+
postgres_service: Service,
105118
vector_io_provider_deployment_config_factory: Callable[[str], list[Dict[str, str]]],
106119
files_provider_config_factory: Callable[[str], list[Dict[str, str]]],
107120
) -> Dict[str, Any]:
@@ -251,6 +264,14 @@ def test_with_remote_milvus(llama_stack_server_config):
251264
# KUBEFLOW_PIPELINES_TOKEN: Get from current client token
252265
env_vars.append({"name": "KUBEFLOW_PIPELINES_TOKEN", "value": str(current_client_token)})
253266

267+
# POSTGRESQL environment variables for sql_default and kvstore_default
268+
env_vars.append({"name": "POSTGRES_HOST", "value": "vector-io-postgres-service"})
269+
env_vars.append({"name": "POSTGRES_PORT", "value": "5432"})
270+
env_vars.append({"name": "POSTGRES_USER", "value": POSTGRESQL_USER})
271+
env_vars.append({"name": "POSTGRES_PASSWORD", "value": POSTGRESQL_PASSWORD})
272+
env_vars.append({"name": "POSTGRES_DB", "value": "ps_db"})
273+
env_vars.append({"name": "POSTGRES_TABLE_NAME", "value": "llamastack_kvstore"})
274+
254275
# Depending on parameter files_provider, configure files provider and obtain required env_vars
255276
files_provider = params.get("files_provider") or "local"
256277
env_vars_files = files_provider_config_factory(provider_name=files_provider)
@@ -681,3 +702,70 @@ def vector_store_with_example_docs(
681702
)
682703

683704
yield vector_store
705+
706+
707+
@pytest.fixture(scope="class")
708+
def postgres_service(
709+
unprivileged_client: DynamicClient,
710+
unprivileged_model_namespace: Namespace,
711+
postgres_deployment: Deployment,
712+
) -> Generator[Service, Any, Any]:
713+
"""Create a service for the postgres deployment."""
714+
with Service(
715+
client=unprivileged_client,
716+
namespace=unprivileged_model_namespace.name,
717+
name="vector-io-postgres-service",
718+
ports=[
719+
{
720+
"port": 5432,
721+
"targetPort": 5432,
722+
}
723+
],
724+
selector={"app": "postgres"},
725+
wait_for_resource=True,
726+
) as service:
727+
yield service
728+
729+
730+
@pytest.fixture(scope="class")
731+
def postgres_deployment(
732+
unprivileged_client: DynamicClient,
733+
unprivileged_model_namespace: Namespace,
734+
) -> Generator[Deployment, Any, Any]:
735+
"""Deploy a Postgres instance for vector I/O provider testing."""
736+
with Deployment(
737+
client=unprivileged_client,
738+
namespace=unprivileged_model_namespace.name,
739+
name="vector-io-postgres-deployment",
740+
min_ready_seconds=5,
741+
replicas=1,
742+
selector={"matchLabels": {"app": "postgres"}},
743+
strategy={"type": "Recreate"},
744+
template=get_postgres_deployment_template(),
745+
teardown=True,
746+
) as deployment:
747+
deployment.wait_for_replicas(deployed=True, timeout=240)
748+
yield deployment
749+
750+
751+
def get_postgres_deployment_template() -> Dict[str, Any]:
752+
"""Return a Kubernetes deployment for PostgreSQL"""
753+
return {
754+
"metadata": {"labels": {"app": "postgres"}},
755+
"spec": {
756+
"containers": [
757+
{
758+
"name": "postgres",
759+
"image": POSTGRES_IMAGE,
760+
"ports": [{"containerPort": 5432}],
761+
"env": [
762+
{"name": "POSTGRESQL_DATABASE", "value": "ps_db"},
763+
{"name": "POSTGRESQL_USER", "value": POSTGRESQL_USER},
764+
{"name": "POSTGRESQL_PASSWORD", "value": POSTGRESQL_PASSWORD},
765+
],
766+
"volumeMounts": [{"name": "postgresdata", "mountPath": "/var/lib/pgsql/data"}],
767+
},
768+
],
769+
"volumes": [{"name": "postgresdata", "emptyDir": {}}],
770+
},
771+
}

0 commit comments

Comments
 (0)