Skip to content

Commit

Permalink
Log error device not reachable after commit
Browse files Browse the repository at this point in the history
  • Loading branch information
indy-independence committed Sep 8, 2023
1 parent 66f245a commit 8ba61e5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/reporef/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ Keys for interfaces.yml or interfaces_<model>.yml:
* enabled: Optional. Set the administrative state of the interface. Defaults to true if not set.
* aggregate_id: Optional. Identifier for configuring LACP etc. Integer value.
Special value -1 means configure MLAG and use ID based on indexnum.
* tags: Optional list of strings, custom user defined tags to apply.
* cli_append_str: Optional. Custom configuration to append to this interface.

The "downlink" ifclass is used on DIST devices to specify that this interface
Expand Down
4 changes: 4 additions & 0 deletions src/cnaas_nms/api/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,10 @@ def post(self):

class DeviceConfigApi(Resource):
@jwt_required
@device_api.param("variables_only")
def get(self, hostname: str):
"""Get device configuration"""
args = request.args
result = empty_result()
result["data"] = {"config": None}
if not Device.valid_hostname(hostname):
Expand All @@ -861,6 +863,8 @@ def get(self, hostname: str):
"generated_config": config,
"available_variables": template_vars,
}
if "variables_only" in args and args["variables_only"]:
del result["data"]["config"]["generated_config"]
except Exception as e:
logger.exception(f"Exception while generating config for device {hostname}")
return (
Expand Down
1 change: 1 addition & 0 deletions src/cnaas_nms/db/settings_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class f_interface(BaseModel):
untagged_vlan: Optional[int] = vlan_id_schema_optional
tagged_vlan_list: Optional[List[int]] = None
aggregate_id: Optional[int] = None
tags: Optional[List[str]] = None
cli_append_str: str = ""

@validator("tagged_vlan_list", each_item=True)
Expand Down
15 changes: 14 additions & 1 deletion src/cnaas_nms/devicehandler/sync_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,22 @@ def push_sync_device(
task.run(**task_args)
if confirm_mode != 2:
task.host.close_connection("napalm")
if confirm_mode == 2:
if confirm_mode == 2 and not dry_run:
time.sleep(1)
task.run(task=napalm_get, getters=["facts"], name="Verify reachability")
if task.results[2].failed:
logger.error(
"Could not reach device {} after commit, rollback in: {}s".format(
task.host.name, api_settings.COMMIT_CONFIRMED_TIMEOUT
)
)
else:
short_facts = {"fqdn": "unknown"}
try:
short_facts["fqdn"] = task.results[2].result["facts"]["fqdn"]
task.results[2].result["facts"] = short_facts
except Exception:
pass

if task.results[1].diff:
config = task.results[1].host["config"]
Expand Down

0 comments on commit 8ba61e5

Please sign in to comment.