-
Notifications
You must be signed in to change notification settings - Fork 594
Proper check of the existence of SSH tunnel attribute #1380
Proper check of the existence of SSH tunnel attribute #1380
Conversation
@@ -122,7 +122,7 @@ def establish_ssh_tunnel(self): | |||
return localport | |||
|
|||
def terminate_ssh_tunnel(self): | |||
if self.tunnel: | |||
if hasattr(self, 'tunnel'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it has the attribute but the value is None? Should we be doing this?
if hasattr(self, 'tunnel') and self.tunnel:
or is that redundant? Not sure if hasattr
also covers self.tunnel not None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question. Since self.tunnel
is only set at this line and I tried a meaningless command to open a subprocess, the Popen
still gave me back an object instead of a None
, I think not checking None
should be fine here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import subprocess
p = subprocess.Popen(['ssh', 'twitter.com']) # should fail
p
is still an object instead of a None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but I think we can add this check just to be safe...
👍 once ci passes. |
@objmagic - it will be good to add the check as @billonahill suggested. |
It works! 👍 |
The attribute
tunnel
is only added to the (Zookeeper) StateManager object when socket connection cannot be established and SSH is used instead.When one is trying to shutdown the tracker, the (Zookeeper) state manager will be shutdown first. However, the original way of check if SSH tunnel has been establish is wrong. If one wants to check if the attribute
tunnel
exists in the StateManager object, he should usehasattr
instead ofif self.tunnel
. The latter one assumes the attributetunnel
already exists in the object.This PR should fix #1379