Skip to content

Commit d6ce39c

Browse files
authored
Merge pull request #829 from tisnik/lcore-1029-byok
LCORE-1029: dumping configuration with BYOK section
2 parents 70d6adb + 60e88c1 commit d6ce39c

1 file changed

Lines changed: 179 additions & 0 deletions

File tree

tests/unit/models/config/test_dump_configuration.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
PostgreSQLDatabaseConfiguration,
1515
CORSConfiguration,
1616
Configuration,
17+
ByokRag,
1718
QuotaHandlersConfiguration,
1819
QuotaLimiterConfiguration,
1920
QuotaSchedulerConfiguration,
@@ -499,3 +500,181 @@ def test_dump_configuration_with_quota_limiters(tmp_path: Path) -> None:
499500
"enable_token_history": True,
500501
},
501502
}
503+
504+
505+
def test_dump_configuration_byok(tmp_path: Path) -> None:
506+
"""
507+
Test that the Configuration object can be serialized to a JSON file and
508+
that the resulting file contains all expected sections and values.
509+
"""
510+
cfg = Configuration(
511+
name="test_name",
512+
service=ServiceConfiguration(
513+
tls_config=TLSConfiguration(
514+
tls_certificate_path=Path("tests/configuration/server.crt"),
515+
tls_key_path=Path("tests/configuration/server.key"),
516+
tls_key_password=Path("tests/configuration/password"),
517+
),
518+
cors=CORSConfiguration(
519+
allow_origins=["foo_origin", "bar_origin", "baz_origin"],
520+
allow_credentials=False,
521+
allow_methods=["foo_method", "bar_method", "baz_method"],
522+
allow_headers=["foo_header", "bar_header", "baz_header"],
523+
),
524+
),
525+
llama_stack=LlamaStackConfiguration(
526+
use_as_library_client=True,
527+
library_client_config_path="tests/configuration/run.yaml",
528+
api_key=SecretStr("whatever"),
529+
),
530+
user_data_collection=UserDataCollection(
531+
feedback_enabled=False, feedback_storage=None
532+
),
533+
database=DatabaseConfiguration(
534+
sqlite=None,
535+
postgres=PostgreSQLDatabaseConfiguration(
536+
db="lightspeed_stack",
537+
user="ls_user",
538+
password=SecretStr("ls_password"),
539+
port=5432,
540+
ca_cert_path=None,
541+
ssl_mode="require",
542+
gss_encmode="disable",
543+
),
544+
),
545+
mcp_servers=[],
546+
customization=None,
547+
inference=InferenceConfiguration(
548+
default_provider="default_provider",
549+
default_model="default_model",
550+
),
551+
byok_rag=[
552+
ByokRag(
553+
rag_id="rag_id",
554+
vector_db_id="vector_db_id",
555+
db_path="tests/configuration/rag.txt",
556+
),
557+
],
558+
)
559+
assert cfg is not None
560+
dump_file = tmp_path / "test.json"
561+
cfg.dump(dump_file)
562+
563+
with open(dump_file, "r", encoding="utf-8") as fin:
564+
content = json.load(fin)
565+
# content should be loaded
566+
assert content is not None
567+
568+
# all sections must exists
569+
assert "name" in content
570+
assert "service" in content
571+
assert "llama_stack" in content
572+
assert "user_data_collection" in content
573+
assert "mcp_servers" in content
574+
assert "authentication" in content
575+
assert "authorization" in content
576+
assert "customization" in content
577+
assert "inference" in content
578+
assert "database" in content
579+
assert "byok_rag" in content
580+
assert "quota_handlers" in content
581+
582+
# check the whole deserialized JSON file content
583+
assert content == {
584+
"name": "test_name",
585+
"service": {
586+
"host": "localhost",
587+
"port": 8080,
588+
"auth_enabled": False,
589+
"workers": 1,
590+
"color_log": True,
591+
"access_log": True,
592+
"tls_config": {
593+
"tls_certificate_path": "tests/configuration/server.crt",
594+
"tls_key_password": "tests/configuration/password",
595+
"tls_key_path": "tests/configuration/server.key",
596+
},
597+
"cors": {
598+
"allow_credentials": False,
599+
"allow_headers": [
600+
"foo_header",
601+
"bar_header",
602+
"baz_header",
603+
],
604+
"allow_methods": [
605+
"foo_method",
606+
"bar_method",
607+
"baz_method",
608+
],
609+
"allow_origins": [
610+
"foo_origin",
611+
"bar_origin",
612+
"baz_origin",
613+
],
614+
},
615+
},
616+
"llama_stack": {
617+
"url": None,
618+
"use_as_library_client": True,
619+
"api_key": "**********",
620+
"library_client_config_path": "tests/configuration/run.yaml",
621+
},
622+
"user_data_collection": {
623+
"feedback_enabled": False,
624+
"feedback_storage": None,
625+
"transcripts_enabled": False,
626+
"transcripts_storage": None,
627+
},
628+
"mcp_servers": [],
629+
"authentication": {
630+
"module": "noop",
631+
"skip_tls_verification": False,
632+
"k8s_ca_cert_path": None,
633+
"k8s_cluster_api": None,
634+
"jwk_config": None,
635+
"rh_identity_config": None,
636+
},
637+
"customization": None,
638+
"inference": {
639+
"default_provider": "default_provider",
640+
"default_model": "default_model",
641+
},
642+
"database": {
643+
"sqlite": None,
644+
"postgres": {
645+
"host": "localhost",
646+
"port": 5432,
647+
"db": "lightspeed_stack",
648+
"user": "ls_user",
649+
"password": "**********",
650+
"ssl_mode": "require",
651+
"gss_encmode": "disable",
652+
"namespace": "lightspeed-stack",
653+
"ca_cert_path": None,
654+
},
655+
},
656+
"authorization": None,
657+
"conversation_cache": {
658+
"memory": None,
659+
"postgres": None,
660+
"sqlite": None,
661+
"type": None,
662+
},
663+
"byok_rag": [
664+
{
665+
"db_path": "tests/configuration/rag.txt",
666+
"embedding_dimension": 768,
667+
"embedding_model": "sentence-transformers/all-mpnet-base-v2",
668+
"rag_id": "rag_id",
669+
"rag_type": "inline::faiss",
670+
"vector_db_id": "vector_db_id",
671+
},
672+
],
673+
"quota_handlers": {
674+
"sqlite": None,
675+
"postgres": None,
676+
"limiters": [],
677+
"scheduler": {"period": 1},
678+
"enable_token_history": False,
679+
},
680+
}

0 commit comments

Comments
 (0)