Skip to content
Merged
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
16 changes: 14 additions & 2 deletions acto/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,21 @@
RECOVERY_SNAPSHOT = -2 # the immediate snapshot before the error


ApplyTestCaseFunctionType = Callable[
[
ValueWithSchema,
list[str],
TestCase,
bool,
Optional[list[XorCondition]],
],
jsonpatch.JsonPatch,
]


def apply_testcase(
value_with_schema: ValueWithSchema,
path: list,
path: list[str],
testcase: TestCase,
setup: bool = False,
constraints: Optional[list[XorCondition]] = None,
Expand Down Expand Up @@ -824,7 +836,7 @@ def __init__(
analysis_only: bool,
is_reproduce: bool,
input_model: type[DeterministicInputModel],
apply_testcase_f: Callable,
apply_testcase_f: ApplyTestCaseFunctionType,
mount: Optional[list] = None,
focus_fields: Optional[list] = None,
acto_namespace: int = 0,
Expand Down
76 changes: 60 additions & 16 deletions acto/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,42 @@
from datetime import datetime
from functools import partial
from glob import glob
from typing import List, Optional
from typing import List, Optional, Tuple

Check warning on line 10 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on line 10

import jsonpatch
import yaml

from acto import DEFAULT_KUBERNETES_VERSION
from acto.engine import Acto
from acto.input import k8s_schemas, property_attribute
from acto.input.input import CustomKubernetesMapping, DeterministicInputModel
from acto.input.constraint import XorCondition
from acto.input.input import (

Check warning on line 19 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 18-19
CustomKubernetesMapping,
CustomPropertySchemaMapping,
DeterministicInputModel,
InputMetadata,
)
from acto.input.testcase import TestCase
from acto.input.testplan import TestGroup
from acto.input.value_with_schema import ValueWithSchema
from acto.lib.operator_config import OperatorConfig
from acto.post_process.post_diff_test import PostDiffTest
from acto.result import OracleResults
from acto.schema.base import BaseSchema
from acto.schema.opaque import OpaqueSchema

Check warning on line 32 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on line 32
from acto.schema.schema import extract_schema
from acto.utils import get_thread_logger


def apply_repro_testcase(
value_with_schema: ValueWithSchema,
_: list,
path: list[str],
testcase: TestCase,
__: bool = False,
setup: bool = False,
constraints: Optional[list[XorCondition]] = None,
) -> jsonpatch.JsonPatch:
"""apply_testcase function for reproducing"""
_, _, _ = path, setup, constraints

Check warning on line 45 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on line 45
logger = get_thread_logger(with_prefix=True)
next_cr = testcase.mutator(None) # next cr in yaml format

Expand Down Expand Up @@ -106,7 +115,8 @@
logger.info("%d steps for reproducing", len(self.testcases))
self.num_total_cases = len(cr_list) - 1
self.num_workers = 1
self.metadata = {}

self.metadata = InputMetadata()

Check warning on line 119 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on line 119

override_matches: Optional[list[tuple[BaseSchema, str]]] = None
if custom_module_path is not None:
Expand Down Expand Up @@ -141,6 +151,43 @@
f"but got {type(custom_mapping)}"
)

if hasattr(custom_module, "CUSTOM_PROPERTY_SCHEMA_MAPPING"):
custom_property_schema_mapping = (
custom_module.CUSTOM_PROPERTY_SCHEMA_MAPPING
)
if isinstance(custom_property_schema_mapping, list):
for custom_mapping in custom_property_schema_mapping:
if isinstance(
custom_mapping, CustomPropertySchemaMapping
):
try:
schema = self.get_schema_by_path(
custom_mapping.schema_path
)
except KeyError:
logger.warning(
"Specified schema path does not exist: %s, using opaque schema",
custom_mapping.schema_path,
)
schema = OpaqueSchema(
custom_mapping.schema_path, {}
)
self.set_schema_by_path(
custom_mapping.schema_path,
custom_mapping.custom_schema.from_original_schema(
schema
),
)
logger.info(
"Applying custom schema to property %s",
custom_mapping.schema_path,
)
else:
raise TypeError(

Check warning on line 186 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on lines 154-186
"Expected CustomPropertySchemaMapping in "
f"CUSTOM_PROPERTY_SCHEMA_MAPPING, but got {type(custom_mapping)}"
)

# Do the matching from CRD to Kubernetes schemas
# Match the Kubernetes schemas to subproperties of the root schema
kubernetes_schema_matcher = k8s_schemas.K8sSchemaMatcher.from_version(
Expand Down Expand Up @@ -190,21 +237,23 @@
return self.seed_input

def generate_test_plan(
self, delta_from: str = None, focus_fields: list = None
self,
focus_fields: Optional[list] = None,
) -> dict:
_ = delta_from
_ = focus_fields
return {}

def next_test(self) -> list:
def next_test(

Check warning on line 246 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on line 246
self,
) -> Optional[list[Tuple[TestGroup, tuple[str, TestCase]]]]:
"""
Returns:
- a list of tuples, containing
an empty TreeNode and a test case
"""
test = self.testcases.pop(0)
return [
(TestGroup([test]), ('["spec"]', test))
(TestGroup([('["spec"]', test)]), ('["spec"]', test))
] # return the first test case

def apply_k8s_schema(self, k8s_field):
Expand Down Expand Up @@ -259,7 +308,6 @@
workdir_path=workdir_path,
operator_config=config,
cluster_runtime=kwargs["cluster_runtime"],
preload_images_=[],
context_file=context_cache,
helper_crd=None,
num_workers=1,
Expand All @@ -272,7 +320,7 @@
acto_namespace=acto_namespace,
)

errors = acto.run(modes=["normal"])
errors = acto.run()

Check warning on line 323 in acto/reproduce.py

View workflow job for this annotation

GitHub Actions / coverage-report

Missing coverage

Missing coverage on line 323
return [error for error in errors if error is not None]


Expand Down Expand Up @@ -336,14 +384,10 @@
parser.add_argument("--context", dest="context", help="Cached context data")
args = parser.parse_args()

workdir_path_ = f"testrun-{datetime.now().strftime('%Y-%m-%d-%H-%M')}"

start_time = datetime.now()
reproduce(
workdir_path=workdir_path_,
workdir_path=f"testrun-{datetime.now().strftime('%Y-%m-%d-%H-%M')}",
reproduce_dir=args.reproduce_dir,
operator_config=args.config,
acto_namespace=args.acto_namespace,
cluster_runtime=args.cluster_runtime,
)
end_time = datetime.now()
Loading
Loading