Skip to content
Snippets Groups Projects
Commit 513f4541 authored by Karel van Klink's avatar Karel van Klink :smiley_cat: Committed by Neda Moeini
Browse files

add router validation task

parent 552452e3
No related branches found
No related tags found
1 merge request!139Feature/add validation workflows
"""Add router validation task.
Revision ID: 6c986f219e3f
Revises: f0764c6f392c
Create Date: 2023-09-22 17:13:01.223133
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = '6c986f219e3f'
down_revision = 'f0764c6f392c'
branch_labels = None
depends_on = None
from orchestrator.migrations.helpers import create_workflow, delete_workflow
new_workflows = [
{
"name": "validate_router",
"target": "SYSTEM",
"description": "Validate router configuration",
"product_type": "Router"
}
]
def upgrade() -> None:
conn = op.get_bind()
for workflow in new_workflows:
create_workflow(conn, workflow)
def downgrade() -> None:
conn = op.get_bind()
for workflow in new_workflows:
delete_workflow(conn, workflow["name"])
"""Add IP Trunk workflows.
Revision ID: 6dbd6c4c04b4
Revises: 815033570ad7
Revises: 0c31b60487c8
Create Date: 2023-11-21 12:55:29.689402
"""
......
"""Add router workflows.
Revision ID: 815033570ad7
Revises: 0c31b60487c8
Revises: 0c904cf0b66b
Create Date: 2023-11-21 12:53:26.413333
"""
......
"""Add TWAMP deployment workflow.
Revision ID: f0764c6f392c
Revises: 815033570ad7
Revises: b689d4636694
Create Date: 2023-12-27 14:31:42.285180
"""
......
......@@ -223,9 +223,7 @@ class NetboxClient:
# Assign interface to :term:`LAG`, ensuring it does not already belong to a :term:`LAG`.
if iface.lag:
msg = f"The interface: {iface_name} on device: {device_name} already belongs to a LAG: {iface.lag.name}."
raise WorkflowStateError(
msg,
)
raise WorkflowStateError(msg)
iface.lag = lag.id
# Set description if provided
......
......@@ -55,6 +55,7 @@
"import_router": "NOT FOR HUMANS -- Finalize import into a Router product",
"import_iptrunk": "NOT FOR HUMANS -- Finalize import into an IP trunk product",
"import_office_router": "NOT FOR HUMANS -- Finalize import into an Office router product",
"import_super_pop_switch": "NOT FOR HUMANS -- Finalize import into a Super PoP switch"
"import_super_pop_switch": "NOT FOR HUMANS -- Finalize import into a Super PoP switch",
"validate_router": "Validate router configuration"
}
}
......@@ -63,3 +63,4 @@ LazyWorkflowInstance("gso.workflows.office_router.create_imported_office_router"
# Opengear workflows
LazyWorkflowInstance("gso.workflows.opengear.create_imported_opengear", "create_imported_opengear")
LazyWorkflowInstance("gso.workflows.opengear.import_opengear", "import_opengear")
......@@ -7,6 +7,7 @@ from orchestrator.forms import FormPage
from orchestrator.forms.validators import Choice, Label
from orchestrator.targets import Target
from orchestrator.types import FormGenerator, State, SubscriptionLifecycle, UUIDstr
from orchestrator.utils.errors import ProcessFailureError
from orchestrator.workflow import StepList, conditional, done, init, inputstep, step, workflow
from orchestrator.workflows.steps import resync, set_status, store_process_subscription
from orchestrator.workflows.utils import wrap_create_initial_input_form
......@@ -143,13 +144,15 @@ def create_netbox_device(subscription: RouterInactive) -> State:
@step("Verify IPAM resources for loopback interface")
def verify_ipam_loopback(subscription: RouterInactive) -> State:
"""Validate the :term:`IPAM` resources for the loopback interface."""
def verify_ipam_loopback(subscription: RouterInactive) -> None:
"""Validate the :term:`IPAM` resources for the loopback interface.
Raises an :class:`orchestrator.utils.errors.ProcessFailureError` if IPAM is configured incorrectly.
"""
host_record = infoblox.find_host_by_fqdn(f"lo0.{subscription.router.router_fqdn}")
if not host_record or str(subscription.subscription_id) not in host_record.comment:
return {"ipam_warning": "Loopback record is incorrectly configured in IPAM, please investigate this manually!"}
return {"subscription": subscription}
msg = "Loopback record is incorrectly configured in IPAM, please investigate this manually!"
raise ProcessFailureError(msg)
@inputstep("Prompt to reboot", assignee=Assignee.SYSTEM)
......
import json
from orchestrator.targets import Target
from orchestrator.types import State
from orchestrator.utils.json import json_dumps
from orchestrator.workflow import StepList, init, workflow, done, step
from orchestrator.workflows.steps import store_process_subscription, unsync, resync
from gso.services.provisioning_proxy import pp_interaction, execute_playbook
from gso.workflows.router.create_router import verify_ipam_loopback
from products import Router
@step("Validate router configuration")
def validate_router_config(subscription: Router, callback_route: str) -> None:
extra_vars = {"wfo_router_json": json.loads(json_dumps(subscription)), "verb": "validate"}
execute_playbook(
playbook_name="base_config.yaml",
callback_route=callback_route,
inventory=subscription.router.router_fqdn,
extra_vars=extra_vars
)
@workflow("Validate router configuration", target=Target.SYSTEM)
def validate_router() -> StepList:
"""Validate an existing, active Router subscription.
* Run an Ansible playbook to verify the configuration is intact.
* Verify that the loopback interface is correctly configured in IPAM.
"""
return (
init
>> store_process_subscription(Target.SYSTEM)
>> unsync
>> pp_interaction(validate_router_config)
>> verify_ipam_loopback
>> resync
>> done
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment