diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-06-16 11:19:34 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-06-16 11:19:34 +0200 |
commit | 303e8cb27560ade4bf0c9e6b9bc453c2f00fe799 (patch) | |
tree | 6e07f506fb0822e39c7d2eabe6a2ed4a4a61fb84 /python/vyos/configsession.py | |
parent | 6b5f0dd5e59b4e0b0170a087a50bfd61bc5f14ac (diff) | |
download | vyos-1x-303e8cb27560ade4bf0c9e6b9bc453c2f00fe799.tar.gz vyos-1x-303e8cb27560ade4bf0c9e6b9bc453c2f00fe799.zip |
T1432: add a finalizer to vyos.configsession to avoid leaking sessions.
Diffstat (limited to 'python/vyos/configsession.py')
-rw-r--r-- | python/vyos/configsession.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/python/vyos/configsession.py b/python/vyos/configsession.py index a27470eeb..39a9713e0 100644 --- a/python/vyos/configsession.py +++ b/python/vyos/configsession.py @@ -14,6 +14,7 @@ import os import re +import sys import subprocess CLI_SHELL_API = '/bin/cli-shell-api' @@ -50,6 +51,7 @@ class ConfigSession(object): """ env_str = subprocess.check_output([CLI_SHELL_API, 'getSessionEnv', str(session_id)]) + self.__session_id = session_id # Extract actual variables from the chunk of shell it outputs # XXX: it's better to extend cli-shell-api to provide easily readable output @@ -64,6 +66,14 @@ class ConfigSession(object): self.__run_command([CLI_SHELL_API, 'setupSession']) + def __del__(self): + try: + output = subprocess.check_output([CLI_SHELL_API, 'teardownSession'], env=self.__session_env).decode().strip() + if output: + print("cli-shell-api teardownSession output for sesion {0}: {1}".format(self.__session_id, output), file=sys.stderr) + except Exception as e: + print("Could not tear down session {0}: {1}".format(self.__session_id, e), file=sys.stderr) + def __run_command(self, cmd_list): p = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=self.__session_env) result = p.wait() |