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
31 changes: 6 additions & 25 deletions integration-tests/tests/package_tests/clp_json/test_clp_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,18 @@
import logging

import pytest
from clp_py_utils.clp_config import (
ClpConfig,
Package,
QueryEngine,
StorageEngine,
)

from tests.package_tests.clp_json.utils.mode import CLP_JSON_MODE
from tests.utils.asserting_utils import (
validate_package_instance,
validate_package_running,
verify_package_compression,
)
from tests.utils.clp_mode_utils import CLP_API_SERVER_COMPONENT, CLP_BASE_COMPONENTS
from tests.utils.config import PackageCompressionJob, PackageInstance, PackageModeConfig
from tests.utils.config import PackageCompressionJob, PackageInstance
from tests.utils.package_utils import run_package_compression_script

logger = logging.getLogger(__name__)


# Mode description for this module.
CLP_JSON_MODE = PackageModeConfig(
mode_name="clp-json",
clp_config=ClpConfig(
package=Package(
storage_engine=StorageEngine.CLP_S,
query_engine=QueryEngine.CLP_S,
),
),
component_list=(*CLP_BASE_COMPONENTS, CLP_API_SERVER_COMPONENT),
)


# Pytest markers for this module.
pytestmark = [
pytest.mark.package,
Expand All @@ -51,7 +32,7 @@ def test_clp_json_startup(fixt_package_instance: PackageInstance) -> None:
"""
logger.info("Starting test: 'test_clp_json_startup'")

validate_package_instance(fixt_package_instance)
validate_package_running(fixt_package_instance)

logger.info("Test complete: 'test_clp_json_startup'")

Expand All @@ -65,7 +46,7 @@ def test_clp_json_compression_json_multifile(fixt_package_instance: PackageInsta
"""
logger.info("Starting test: 'test_clp_json_compression_json_multifile'")

validate_package_instance(fixt_package_instance)
validate_package_running(fixt_package_instance)

# Clear archives before compressing.
package_test_config = fixt_package_instance.package_test_config
Expand Down Expand Up @@ -105,7 +86,7 @@ def test_clp_json_search(fixt_package_instance: PackageInstance) -> None:
"""
logger.info("Starting test: 'test_clp_json_search'")

validate_package_instance(fixt_package_instance)
validate_package_running(fixt_package_instance)

# TODO: compress a dataset

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
CLP_API_SERVER_COMPONENT,
CLP_BASE_COMPONENTS,
CLP_GARBAGE_COLLECTOR_COMPONENT,
CLP_LOG_INGESTOR_COMPONENT,
CLP_QUERY_COMPONENTS,
CLP_REDUCER_COMPONENT,
)
Expand All @@ -33,6 +32,5 @@
*CLP_QUERY_COMPONENTS,
CLP_GARBAGE_COLLECTOR_COMPONENT,
CLP_API_SERVER_COMPONENT,
CLP_LOG_INGESTOR_COMPONENT,
),
)
31 changes: 5 additions & 26 deletions integration-tests/tests/package_tests/clp_text/test_clp_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,18 @@
import logging

import pytest
from clp_py_utils.clp_config import (
ClpConfig,
Package,
QueryEngine,
StorageEngine,
)

from tests.package_tests.clp_text.utils.mode import CLP_TEXT_MODE
from tests.utils.asserting_utils import (
validate_package_instance,
validate_package_running,
verify_package_compression,
)
from tests.utils.clp_mode_utils import CLP_BASE_COMPONENTS
from tests.utils.config import PackageCompressionJob, PackageInstance, PackageModeConfig
from tests.utils.config import PackageCompressionJob, PackageInstance
from tests.utils.package_utils import run_package_compression_script

logger = logging.getLogger(__name__)


# Mode description for this module.
CLP_TEXT_MODE = PackageModeConfig(
mode_name="clp-text",
clp_config=ClpConfig(
package=Package(
storage_engine=StorageEngine.CLP,
query_engine=QueryEngine.CLP,
),
api_server=None,
log_ingestor=None,
),
component_list=(*CLP_BASE_COMPONENTS,),
)


# Pytest markers for this module.
pytestmark = [
pytest.mark.package,
Expand All @@ -49,7 +28,7 @@ def test_clp_text_startup(fixt_package_instance: PackageInstance) -> None:
"""Tests package startup."""
logger.info("Starting test: 'test_clp_text_startup'")

validate_package_instance(fixt_package_instance)
validate_package_running(fixt_package_instance)

logger.info("Test complete: 'test_clp_text_startup'")

Expand All @@ -63,7 +42,7 @@ def test_clp_text_compression_text_multifile(fixt_package_instance: PackageInsta
"""
logger.info("Starting test: 'test_clp_text_compression_text_multifile'")

validate_package_instance(fixt_package_instance)
validate_package_running(fixt_package_instance)

# Clear archives before compressing.
package_test_config = fixt_package_instance.package_test_config
Expand Down
54 changes: 6 additions & 48 deletions integration-tests/tests/utils/asserting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,31 @@

import pytest
from clp_package_utils.general import EXTRACT_FILE_CMD
from clp_py_utils.clp_config import ClpConfig
from pydantic import ValidationError

from tests.utils.clp_mode_utils import compare_mode_signatures
from tests.utils.config import PackageInstance, PackageTestConfig
from tests.utils.docker_utils import list_running_services_in_compose_project
from tests.utils.subprocess_utils import run_and_log_subprocess
from tests.utils.utils import (
clear_directory,
is_dir_tree_content_equal,
load_yaml_to_dict,
)

logger = logging.getLogger(__name__)


def validate_package_instance(package_instance: PackageInstance) -> None:
"""
Validate that the given package instance is running by performing two checks: validate that the
instance has exactly the set of running components that it should have, and validate that the
instance is running in the correct mode.

:param package_instance:
"""
log_msg = (
f"Validating the '{package_instance.package_test_config.mode_config.mode_name}' package."
)
logger.info(log_msg)

# Ensure that all package components are running.
_validate_package_running(package_instance)

# Ensure that the package is running in the correct mode.
_validate_running_mode_correct(package_instance)


def _validate_package_running(package_instance: PackageInstance) -> None:
def validate_package_running(package_instance: PackageInstance) -> None:
"""
Validate that the given package instance is running by checking that the set of services running
in the Compose project exactly matches the list of required components.

:param package_instance:
:raise pytest.fail: if the sets of running services and required components do not match.
"""
logger.info(
"Validating the '%s' package.",
package_instance.package_test_config.mode_config.mode_name,
)

# Get list of services currently running in the Compose project.
instance_id = package_instance.clp_instance_id
project_name = f"clp-package-{instance_id}"
Expand All @@ -72,29 +53,6 @@ def _validate_package_running(package_instance: PackageInstance) -> None:
pytest.fail(fail_msg)


def _validate_running_mode_correct(package_instance: PackageInstance) -> None:
"""
Validate that the mode described in the shared config of the instance matches the intended mode
defined by the instance configuration. Calls pytest.fail if the shared config fails validation
or if the running mode does not match the intended mode.

:param package_instance:
:raise: Propagates `load_yaml_to_dict`'s errors.
:raise pytest.fail: if the ClpConfig object cannot be validated.
:raise pytest.fail: if the running ClpConfig does not match the intended ClpConfig.
"""
shared_config_dict = load_yaml_to_dict(package_instance.shared_config_file_path)
try:
running_config = ClpConfig.model_validate(shared_config_dict)
except ValidationError as err:
pytest.fail(f"Shared config failed validation: {err}")

intended_config = package_instance.package_test_config.mode_config.clp_config

if not compare_mode_signatures(intended_config, running_config):
pytest.fail("Mode mismatch: running configuration does not match intended configuration.")


def verify_package_compression(
path_to_original_dataset: Path,
package_test_config: PackageTestConfig,
Expand Down
94 changes: 0 additions & 94 deletions integration-tests/tests/utils/clp_mode_utils.py

This file was deleted.

Loading