Skip to content

Commit

Permalink
Merge pull request #4804 from opsmill/pog-workflow-names
Browse files Browse the repository at this point in the history
Work on workflow & flow names
  • Loading branch information
ogenstad authored Oct 31, 2024
2 parents 507c9d7 + f051e5f commit 78ea8a8
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/infrahub/core/ipam/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


@flow(
name="ipam-reconciliation",
name="ipam_reconciliation",
flow_run_name="branch-{branch}",
description="Ensure the IPAM Tree is up to date",
persist_result=False,
Expand Down
2 changes: 1 addition & 1 deletion backend/infrahub/core/migrations/schema/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from infrahub.core.schema import MainSchemaTypes


@flow(name="schema-migrations-apply")
@flow(name="schema_apply_migrations")
async def schema_apply_migrations(message: SchemaApplyMigrationData) -> list[str]:
service = services.service
await add_branch_tag(branch_name=message.branch.name)
Expand Down
2 changes: 1 addition & 1 deletion backend/infrahub/core/validators/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .models.validate_migration import SchemaValidateMigrationData # noqa: TCH001


@flow(name="schema-migrations-validate")
@flow(name="schema_validate_migrations")
async def schema_validate_migrations(message: SchemaValidateMigrationData) -> list[str]:
batch = InfrahubBatch(return_exceptions=True)
error_messages: list[str] = []
Expand Down
6 changes: 3 additions & 3 deletions backend/infrahub/git/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
log = get_logger()


@flow(name="git-repositories-branch-create")
@flow(name="git_repositories_create_branch")
async def create_branch(branch: str, branch_id: str) -> None:
"""Request to the creation of git branches in available repositories."""
service = services.service
Expand All @@ -42,7 +42,7 @@ async def create_branch(branch: str, branch_id: str) -> None:
pass


@flow(name="git-repository-sync")
@flow(name="git_repositories_sync")
async def sync_remote_repositories() -> None:
service = services.service

Expand Down Expand Up @@ -162,7 +162,7 @@ async def generate_artifact(model: RequestArtifactGenerate) -> None:
await artifact.save()


@flow(name="artifact-definition-generate")
@flow(name="request_artifact_definitions_generate")
async def generate_request_artifact_definition(model: RequestArtifactDefinitionGenerate) -> None:
await add_branch_tag(branch_name=model.branch)

Expand Down
2 changes: 1 addition & 1 deletion backend/infrahub/tasks/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def post_telemetry_data(service: InfrahubServices, url: str, payload: dict
response.raise_for_status()


@flow(name="anonymous-telemetry-push")
@flow(name="anonymous_telemetry_send")
async def send_telemetry_push() -> None:
service = services.service
log = get_run_logger()
Expand Down
4 changes: 2 additions & 2 deletions backend/infrahub/transformations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
log = get_logger()


@flow(name="transform-render-python")
@flow(name="transform_render_python")
async def transform_python(message: TransformPythonData) -> Any:
service = services.service
await add_branch_tag(branch_name=message.branch)
Expand All @@ -35,7 +35,7 @@ async def transform_python(message: TransformPythonData) -> Any:
return transformed_data


@flow(name="transform-render-jinja2")
@flow(name="transform_render_jinja2_template")
async def transform_render_jinja2_template(message: TransformJinjaTemplateData) -> str:
service = services.service
await add_branch_tag(branch_name=message.branch)
Expand Down
2 changes: 1 addition & 1 deletion backend/infrahub/workflows/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
)

REQUEST_ARTIFACT_DEFINITION_GENERATE = WorkflowDefinition(
name="artifact-definition-generate",
name="request_artifact_definitions_generate",
type=WorkflowType.INTERNAL,
module="infrahub.git.tasks",
function="generate_request_artifact_definition",
Expand Down
17 changes: 17 additions & 0 deletions backend/tests/unit/workflows/test_catalogue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from collections import Counter
from typing import TYPE_CHECKING

import pytest
Expand All @@ -14,3 +15,19 @@
def test_workflow_definition(workflow: WorkflowDefinition) -> None:
"""Validate that we can import the function for each workflow."""
workflow.validate_workflow()


@pytest.mark.parametrize("workflow", [pytest.param(workflow, id=workflow.name) for workflow in workflows])
def test_workflow_definition_matches(workflow: WorkflowDefinition) -> None:
"""Validate that the name of the workflow matches the name of the flow"""
flow = workflow.get_function()
assert hasattr(flow, "name")
assert workflow.name == flow.name


def test_workflow_definition_flow_names() -> None:
"""Validate that each workflow has a unique name defined"""
flow_names = [workflow.name for workflow in workflows]
name_counter = Counter(flow_names)
duplicates = [name for name, count in name_counter.items() if count > 1]
assert not duplicates, f"Duplicate flow names found: {', '.join(duplicates)}"

0 comments on commit 78ea8a8

Please sign in to comment.