Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions ols/app/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,6 @@ def validate_yaml(self) -> None:
"""Validate reference content index config."""
if self.product_docs_index_path is not None:
try:
fallback_to_default = False
checks.dir_check(
self.product_docs_index_path, "Reference content index path"
)
Expand All @@ -887,22 +886,16 @@ def validate_yaml(self) -> None:
try:
checks.dir_check(default_path, "Reference content index path")
self.product_docs_index_path = FilePath(default_path)
# load all index in the default path
# we don't know the index_id for "latest" so ignore what
# the config says and load whatever index is there
self.product_docs_index_id = None
fallback_to_default = True
except checks.InvalidConfigurationError:
raise e_original
if self.product_docs_index_id is None and not fallback_to_default:
else:
if self.product_docs_index_id is not None:
raise checks.InvalidConfigurationError(
"product_docs_index_path is specified but product_docs_index_id is missing"
"product_docs_index_id is specified but product_docs_index_path is missing"
)
if (
self.product_docs_index_id is not None
and self.product_docs_index_path is None
):
raise checks.InvalidConfigurationError(
"product_docs_index_id is specified but product_docs_index_path is missing"
)


class ReferenceContent(BaseModel):
Expand Down
20 changes: 15 additions & 5 deletions tests/unit/app/models/test_config.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Unit tests for data models."""

import copy
import errno
import logging
import os
from unittest import mock

import pytest
from pydantic import ValidationError
Expand Down Expand Up @@ -2928,14 +2930,19 @@ def test_reference_content_index_yaml_validation():
# should not raise an exception
reference_content_index.validate_yaml()

# existing docs index path with set up product ID
# existing docs index path with set up index ID
reference_content_index.product_docs_index_path = "."
reference_content_index.product_docs_index_id = "foo"
reference_content_index.validate_yaml()

# existing docs index path, but no product ID
# existing docs index path, but no index ID
reference_content_index.product_docs_index_path = "."
reference_content_index.product_docs_index_id = None
reference_content_index.validate_yaml()

# no docs index path, but with index id
reference_content_index.product_docs_index_path = None
reference_content_index.product_docs_index_id = "foo"
with pytest.raises(InvalidConfigurationError):
reference_content_index.validate_yaml()

Expand All @@ -2952,9 +2959,12 @@ def test_reference_content_index_yaml_validation():

# docs index point to a proper directory, that is not
# readable by the service
reference_content_index.product_docs_index_path = "/root"
with pytest.raises(InvalidConfigurationError):
reference_content_index.validate_yaml()
with mock.patch(
"os.stat", side_effect=PermissionError(errno.EACCES, "Permission denied")
):
reference_content_index.product_docs_index_path = "/root"
with pytest.raises(InvalidConfigurationError):
reference_content_index.validate_yaml()


def test_reference_content_constructor():
Expand Down
28 changes: 0 additions & 28 deletions tests/unit/utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,34 +544,6 @@ def test_invalid_config_improper_reference_content():
check_expected_exception(
"""
---
llm_providers:
- name: p1
type: bam
credentials_path: tests/config/secret/apitoken
models:
- name: m1
credentials_path: tests/config/secret/apitoken
ols_config:
reference_content:
indexes:
- product_docs_index_path: "/tmp"
conversation_cache:
type: memory
memory:
max_entries: 1000
dev_config:
temperature_override: 0.1
enable_dev_ui: true
disable_auth: false
""",
InvalidConfigurationError,
"product_docs_index_path is specified but product_docs_index_id is missing",
)

check_expected_exception(
"""
---
llm_providers:
- name: p1
type: bam
Expand Down