Module: check_mk
Branch: master
Commit: 42677d9ddfd64f7fbd86871eb42e98c56f03b72a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=42677d9ddfd64f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Apr 4 13:09:22 2019 +0200
Try to fix broken exception handling in remote calls
Change-Id: Iecce3418c377838409bd5e9dd2a418aa7a7fb628
---
agents/windows/it/remote.py | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/agents/windows/it/remote.py b/agents/windows/it/remote.py
index cc63851..8788c01 100644
--- a/agents/windows/it/remote.py
+++ b/agents/windows/it/remote.py
@@ -67,24 +67,27 @@ def wait_agent():
def actual_output(write_config, wait_agent):
if platform.system() == 'Windows':
# Run agent and yield telnet output.
+ telnet, p = None, None
try:
save_cwd = os.getcwd()
os.chdir(remotedir)
p = subprocess.Popen([agent_exe, 'adhoc'])
+
# Override wait_agent in tests to wait for async processes to start.
wait_agent()
+
telnet = telnetlib.Telnet(host, port) # nosec
yield telnet.read_all().splitlines()
finally:
- try:
+ if telnet:
telnet.close()
+
+ if p:
p.terminate()
- # Possibly wait for async processes to stop.
- wait_agent()
- # Thrown if something goes wrong before variable assigment
- except UnboundLocalError as e:
- sys.stderr.write('%s\n' % str(e))
- assert 0, '%s' % str(e)
+
+ # Possibly wait for async processes to stop.
+ wait_agent()
+
os.chdir(save_cwd)
else:
# Not on Windows, test run remotely, nothing to be done.