@@ -140,6 +140,11 @@ def make_rpc_call(self, rpc_command):
140
140
:param rpc_command: (str) rpc command such as:
141
141
<Get><Operational><LLDP><NodeTable></NodeTable></LLDP></Operational></Get>
142
142
"""
143
+ # ~~~ hack: ~~~
144
+ if not self .is_alive ():
145
+ self .close () # force close for safety
146
+ self .open () # reopen
147
+ # ~~~ end hack ~~~
143
148
result = self ._execute_rpc (rpc_command )
144
149
return ET .tostring (result )
145
150
@@ -163,14 +168,15 @@ def open(self):
163
168
raise ConnectError (au_err .message )
164
169
165
170
self ._cli_prompt = self .device .find_prompt () # get the prompt
166
-
167
171
self ._enter_xml_mode ()
168
172
169
173
def is_alive (self ):
170
174
"""
171
- Returns the XML agent connection state.
175
+ Returns the XML agent connection state (and SSH connection state) .
172
176
"""
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
174
180
175
181
def _timeout_exceeded (self , start = None , msg = 'Timeout exceeded!' ):
176
182
if not start :
@@ -449,9 +455,10 @@ def close(self):
449
455
Clean up after you are done and explicitly close the router connection.
450
456
"""
451
457
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
455
462
456
463
def lock (self ):
457
464
"""
0 commit comments