Skip to content

Commit

Permalink
enforce unique application step names (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
blueskyjunkie authored Nov 19, 2021
1 parent 1fe4b64 commit 8bdf08c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions foodx_devops_tools/pipeline_config/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,27 @@ class ApplicationDefinition(pydantic.BaseModel):
depends_on: typing.Optional[DependencyDeclarations]
steps: ApplicationDeploymentSteps

@pydantic.validator("steps")
def check_applications(
cls: pydantic.BaseModel, steps_candidate: ApplicationDeploymentSteps
) -> ApplicationDeploymentSteps:
"""Validate ``steps`` field."""
step_names: typing.List[str] = [
x.name
for x in steps_candidate
if not isinstance(x, ApplicationStepDelay)
]
if len(step_names) != len(set(step_names)):
message = "Application step names must be unique, {0}".format(
str(step_names)
)
# log the message here because pydantic exception handling
# masks the true exception that caused a validation failure.
log.error(message)
raise ValueError(message)

return steps_candidate


ApplicationDeclarations = typing.Dict[str, ApplicationDefinition]

Expand Down
25 changes: 25 additions & 0 deletions tests/ci/unit_tests/pipeline_config/test_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,31 @@ def test_bad_dependency_raises(apply_applications_test):
apply_applications_test(file_text)


def test_duplicate_step_names_raises(apply_applications_test):
file_text = """---
frames:
frames:
f1:
applications:
a1:
steps:
- arm_file: something.json
mode: Incremental
name: same_name
resource_group: a1_group
- arm_file: something_else.json
mode: Incremental
name: same_name
resource_group: other_group
folder: some/f2-path
"""

with pytest.raises(
FrameDefinitionsError, match=r"Application step names must be unique"
):
apply_applications_test(file_text)


def test_missing_name_raises(apply_applications_test):
file_text = """---
frames:
Expand Down

0 comments on commit 8bdf08c

Please sign in to comment.