Commit b56e3520 authored by Sebastien Robin's avatar Sebastien Robin

erp5.util.testnode: make sure proxy is really dead before starting new one

in some rare cases, proxy was still alive for unknown reasons,
thus we had troubles to start a new one. some testnodes were failing
randomly because of this
parent 944ffe51
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
# #
############################################################################## ##############################################################################
import os import os
import getpass
import psutil import psutil
import re import re
import subprocess import subprocess
...@@ -187,6 +188,19 @@ class ProcessManager(object): ...@@ -187,6 +188,19 @@ class ProcessManager(object):
help_words = set(help_string.split()) help_words = set(help_string.split())
return help_words.intersection(set(parameter_list)) return help_words.intersection(set(parameter_list))
def killall(self, name):
"""
Allow to kill process with given name.
Will try to kill only process belonging to current user
"""
user_login = getpass.getuser()
to_kill_list = []
for process in psutil.process_iter():
if process.username() == user_login and process.name() == name:
self.log('ProcesssManager, killall on %s having pid %s' % (name, process.pid))
to_kill_list.append(process.pid)
for pid in to_kill_list:
killCommand(pid, self.log)
def killPreviousRun(self, cancellation=False): def killPreviousRun(self, cancellation=False):
self.log('ProcessManager killPreviousRun, going to kill %r' % (self.process_pid_set,)) self.log('ProcessManager killPreviousRun, going to kill %r' % (self.process_pid_set,))
......
...@@ -273,6 +273,8 @@ class SlapOSControler(object): ...@@ -273,6 +273,8 @@ class SlapOSControler(object):
slapproxy_log_fp = open(slapproxy_log, 'w') slapproxy_log_fp = open(slapproxy_log, 'w')
kwargs['stdout'] = slapproxy_log_fp kwargs['stdout'] = slapproxy_log_fp
kwargs['stderr'] = slapproxy_log_fp kwargs['stderr'] = slapproxy_log_fp
# Make sure there is no slapos alive from previous run
process_manager.killall('slapos')
proxy = subprocess.Popen([config['slapos_binary'], proxy = subprocess.Popen([config['slapos_binary'],
'proxy', 'start', '--cfg' , self.slapos_config], **kwargs) 'proxy', 'start', '--cfg' , self.slapos_config], **kwargs)
process_manager.process_pid_set.add(proxy.pid) process_manager.process_pid_set.add(proxy.pid)
......
...@@ -32,6 +32,7 @@ import time ...@@ -32,6 +32,7 @@ import time
import shutil import shutil
import logging import logging
import Utils import Utils
from requests.exceptions import RequestException
import traceback import traceback
...@@ -430,8 +431,8 @@ from the distributor.") ...@@ -430,8 +431,8 @@ from the distributor.")
# break the loop to get latest priorities from master # break the loop to get latest priorities from master
break break
self.cleanUp(test_result) self.cleanUp(test_result)
except (SubprocessError, CalledProcessError) as e: except (SubprocessError, CalledProcessError, RequestException) as e:
log("SubprocessError", exc_info=sys.exc_info()) log("SubprocessError or RequestException", exc_info=sys.exc_info())
if remote_test_result_needs_cleanup: if remote_test_result_needs_cleanup:
status_dict = e.status_dict or {} status_dict = e.status_dict or {}
test_result.reportFailure( test_result.reportFailure(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment