Add destructor for SshAgent

There is no indication this is necessary (it seems all code paths
do result in stop() being called), but just in case, add a destructor
to SshAgent to make sure we don't leave an ssh-agent process running
beyond the end of a job.

Change-Id: I10172574d0844e7181a82ae586121e6ba5e3d6ff
This commit is contained in:
James E. Blair 2020-02-24 12:47:12 -08:00
parent bbe2d36495
commit 6c72f6d3dd
1 changed files with 10 additions and 0 deletions

View File

@ -260,6 +260,16 @@ class SshAgent(object):
self.log.debug('Sent SIGTERM to SSH Agent, {}'.format(self.env))
self.env = {}
def __del__(self):
try:
self.stop()
except Exception:
self.log.exception('Exception in SshAgent destructor')
try:
super().__del__(self)
except AttributeError:
pass
def add(self, key_path):
env = os.environ.copy()
env.update(self.env)