From d53b9ef84674dfa0367299bbe8c37df8d4fac5fc Mon Sep 17 00:00:00 2001 From: Karel van Klink <karel.vanklink@geant.org> Date: Thu, 12 Dec 2024 14:13:16 +0100 Subject: [PATCH] Put repeated strings in reusable constants --- gso/cli/imports.py | 11 ++++++----- gso/services/lso_client.py | 11 +++++++---- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gso/cli/imports.py b/gso/cli/imports.py index 7bfcbd2a..fad9d1e1 100644 --- a/gso/cli/imports.py +++ b/gso/cli/imports.py @@ -53,6 +53,7 @@ from gso.utils.types.ip_address import ( from gso.utils.types.virtual_identifiers import VC_ID, VLAN_ID app: typer.Typer = typer.Typer() +IMPORT_WAIT_MESSAGE = "Waiting for the dust to settle before importing new products..." class CreatePartner(BaseModel): @@ -451,7 +452,7 @@ def _generic_import_product( except ValidationError as e: typer.echo(f"Validation error: {e}") - typer.echo("Waiting for the dust to settle before moving on the importing new products...") + typer.echo(IMPORT_WAIT_MESSAGE) time.sleep(1) # Migrate new products from imported to "full" counterpart. @@ -539,7 +540,7 @@ def import_edge_port(filepath: str = common_filepath_option) -> None: except ValidationError as e: typer.echo(f"Validation error: {e}") - typer.echo("Waiting for the dust to settle before moving on the importing new products...") + typer.echo(IMPORT_WAIT_MESSAGE) time.sleep(1) edge_port_ids = get_subscriptions( @@ -610,7 +611,7 @@ def import_iptrunks(filepath: str = common_filepath_option) -> None: except ValidationError as e: typer.echo(f"Validation error: {e}") - typer.echo("Waiting for the dust to settle before moving on the importing new products...") + typer.echo(IMPORT_WAIT_MESSAGE) time.sleep(1) trunk_ids = get_subscriptions( @@ -670,7 +671,7 @@ def import_l3_core_service(filepath: str = common_filepath_option) -> None: except ValidationError as e: typer.echo(f"Validation error: {e}") - typer.echo("Waiting for the dust to settle before importing new products...") + typer.echo(IMPORT_WAIT_MESSAGE) time.sleep(1) # Migrate new products from imported to "full" counterpart. @@ -728,7 +729,7 @@ def import_layer_2_circuit_service(filepath: str = common_filepath_option) -> No ) except ValidationError as e: typer.echo(f"Validation error: {e}") - typer.echo("Waiting for the dust to settle before importing new products...") + typer.echo(IMPORT_WAIT_MESSAGE) time.sleep(1) # Migrate new products from imported to "full" counterpart. diff --git a/gso/services/lso_client.py b/gso/services/lso_client.py index 9280cbc4..6f5d8599 100644 --- a/gso/services/lso_client.py +++ b/gso/services/lso_client.py @@ -22,6 +22,7 @@ from unidecode import unidecode from gso import settings logger = logging.getLogger(__name__) +RUNNING_ANSIBLE_PLAYBOOK_STEP_NAME = "Running Ansible playbook" class _LSOState(TypedDict): # noqa: PYI049 @@ -211,7 +212,7 @@ def lso_interaction(provisioning_step: Step) -> StepList: >> _inventory_is_not_empty( begin >> callback_step( - name="Running Ansible playbook", action_step=_execute_playbook, validate_step=_evaluate_results + name=RUNNING_ANSIBLE_PLAYBOOK_STEP_NAME, action_step=_execute_playbook, validate_step=_evaluate_results ) >> step("Inject result title")(lambda: {"lso_result_title": provisioning_step.name}) >> _show_results @@ -243,7 +244,7 @@ def indifferent_lso_interaction(provisioning_step: Step) -> StepList: >> _inventory_is_not_empty( begin >> callback_step( - name="Running Ansible playbook", action_step=_execute_playbook, validate_step=_ignore_results + name=RUNNING_ANSIBLE_PLAYBOOK_STEP_NAME, action_step=_execute_playbook, validate_step=_ignore_results ) >> step("Inject result title")(lambda: {"lso_result_title": provisioning_step.name}) >> _show_results @@ -268,7 +269,9 @@ def anonymous_lso_interaction(provisioning_step: Step, validation_step: Step = _ begin >> provisioning_step >> _inventory_is_not_empty( - callback_step(name="Running Ansible playbook", action_step=_execute_playbook, validate_step=validation_step) + callback_step( + name=RUNNING_ANSIBLE_PLAYBOOK_STEP_NAME, action_step=_execute_playbook, validate_step=validation_step + ) ) >> _clean_state ) @@ -287,7 +290,7 @@ def anonymous_indifferent_lso_interaction(provisioning_step: Step) -> StepList: >> provisioning_step >> _inventory_is_not_empty( callback_step( - name="Running Ansible playbook", + name=RUNNING_ANSIBLE_PLAYBOOK_STEP_NAME, action_step=_execute_playbook, validate_step=_ignore_results, ) -- GitLab