Skip to content

Commit 6606b53

Browse files
committed
Reopen when not alive
1 parent 1fd7a1e commit 6606b53

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pyIOSXR/iosxr.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ def make_rpc_call(self, rpc_command):
140140
:param rpc_command: (str) rpc command such as:
141141
<Get><Operational><LLDP><NodeTable></NodeTable></LLDP></Operational></Get>
142142
"""
143+
# ~~~ hack: ~~~
144+
if not self.is_alive():
145+
self.close() # force close for safety
146+
self.open() # reopen
147+
# ~~~ end hack ~~~
143148
result = self._execute_rpc(rpc_command)
144149
return ET.tostring(result)
145150

@@ -163,14 +168,15 @@ def open(self):
163168
raise ConnectError(au_err.message)
164169

165170
self._cli_prompt = self.device.find_prompt() # get the prompt
166-
167171
self._enter_xml_mode()
168172

169173
def is_alive(self):
170174
"""
171-
Returns the XML agent connection state.
175+
Returns the XML agent connection state (and SSH connection state).
172176
"""
173-
return self._xml_agent_alive
177+
if hasattr(self.device, 'remote_conn'):
178+
return self.device.remote_conn.transport.is_active() and self._xml_agent_alive
179+
return False # remote_conn not there => connection not init => not alive
174180

175181
def _timeout_exceeded(self, start=None, msg='Timeout exceeded!'):
176182
if not start:
@@ -449,9 +455,10 @@ def close(self):
449455
Clean up after you are done and explicitly close the router connection.
450456
"""
451457
if self.lock_on_connect or self.locked:
452-
self.unlock()
453-
self._unlock_xml_agent()
454-
self.device.remote_conn.close()
458+
self.unlock() # this refers to the config DB
459+
self._unlock_xml_agent() # this refers to the XML agent
460+
if hasattr(self.device, 'remote_conn'):
461+
self.device.remote_conn.close() # close the underlying SSH session
455462

456463
def lock(self):
457464
"""

0 commit comments

Comments
 (0)