05-07-2024 03:09 AM
Hi all
I have a small script that collects information from a list of devices, but it takes a long time.
I have found out that there is a disconnection time of 10s I think I am hitting.
I have found the documentation that says I can change the settings but when I test it out there is still a delay after the disconnect.
def atswrapper_bfd(dev_ip, cli_username, cli_password):
atsbfd = None
testbed = loader.load(
{
"devices": {
device["name"]: {
"connections": {
"cli": {
"protocol": "ssh",
"ip": dev_ip,
"init_exec_commands": [],
"init_config_commands": []
},
"settings": {
"GRACEFUL_DISCONNECT_WAIT_SEC": 1,
"POST_DISCONNECT_WAIT_SEC": 1
}
}, # Find a better way to do this: https://github.com/CiscoTestAutomation/genielibs/issues/12
"credentials": {
"default": {
"username": cli_username,
"password": cli_password,
}
},
"type": "Device",
"os": "iosxe"
}
}
}
)
atsdevice = testbed.devices[device["name"]]
atsdevice.connect(via='cli', log_stdout=True, learn_hostname=True, connection_timeout=2)
atsbfd = atsdevice.parse('show bfd neighbors details')
atsdevice.disconnect()
return atsbfd
05-07-2024 03:17 AM
Hmm... from what you describe, it seems that the 10-second delay you are see is not directly related to GRACEFUL_DISCONNECT_WAIT_SEC
/ POST_DISCONNECT_WAIT_SEC
settings. It might be caused by a combination a few things such as network latency, connection timeouts, or device-specific limitations. I am also unsure if the genielibs
library might have additional logic for disconnection that overrides your settings too (guessing here)?
05-07-2024 05:14 AM
When I look at the logs it gives from log_stdout=True it completes the show command, hangs for 10 seconds and then continue.
I have tried to add the following lines and then the function is a lot faster.
atsdevice = testbed.devices[device["name"]]
atsdevice.connect(via='cli', log_stdout=True, learn_hostname=True, connection_timeout=2)
atsdevice.settings.GRACEFUL_DISCONNECT_WAIT_SEC = 0
atsdevice.settings.POST_DISCONNECT_WAIT_SEC = 0
atsbfd = atsdevice.parse('show bfd neighbors details')
atsdevice.disconnect()
But I still cannot get it to work when using the dictionary with configuration.
05-07-2024 05:44 AM
Not sure if this would work, but try this idea below, the GRACEFUL_DISCONNECT_WAIT_SEC and POST_DISCONNECT_WAIT_SEC settings are now set within the settings key of the device dictionary, it _should_ correctly set the values and reduce the delay between sending the show command and disconnecting from the device. (I hope!)
def atswrapper_bfd(dev_ip, cli_username, cli_password):
atsbfd = None
testbed = loader.load(
{
"devices": {
device["name"]: {
"connections": {
"cli": {
"protocol": "ssh",
"ip": dev_ip,
"init_exec_commands": [],
"init_config_commands": []
}
},
"credentials": {
"default": {
"username": cli_username,
"password": cli_password,
}
},
"type": "Device",
"os": "iosxe",
"settings": {
"GRACEFUL_DISCONNECT_WAIT_SEC": 0,
"POST_DISCONNECT_WAIT_SEC": 0
}
}
}
}
)
atsdevice = testbed.devices[device["name"]]
atsdevice.connect(via='cli', log_stdout=True, learn_hostname=True, connection_timeout=2)
atsbfd = atsdevice.parse('show bfd neighbors details')
atsdevice.disconnect()
return atsbfd
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide