Fix bug with cleanup running for locked tests

Code for lock aquiring modified.

- locks are aquired inside try statement,
 prevents from being interrupted outside of main flow
- prevent 500 error in case process was already stopped
- remove SIGUSR1 interrupt handler with SIG_DFL
 which simply returns 0

Change-Id: Icc31510db705b11c2b628604d0480d8da6aedeca
Closes-Bug: #1318631
This commit is contained in:
Artem Roma 2014-05-14 18:43:11 +03:00 committed by Dima Shulyak
parent 69bdb9729c
commit 353f918197
4 changed files with 30 additions and 26 deletions

View File

@ -69,18 +69,18 @@ class NoseDriver(object):
.filter_by(id=test_run_id)\
.one()
if not os.path.exists(lock_path):
LOG.error('There is no directory to store locks')
raise Exception('There is no directory to store locks')
aquired_locks = []
for serie in testrun.test_set.exclusive_testsets:
lock_name = serie + str(testrun.cluster_id)
fd = open(os.path.join(lock_path, lock_name), 'w')
fcntl.flock(fd, fcntl.LOCK_EX)
aquired_locks.append(fd)
try:
if not os.path.exists(lock_path):
LOG.error('There is no directory to store locks')
raise Exception('There is no directory to store locks')
aquired_locks = []
for serie in testrun.test_set.exclusive_testsets:
lock_name = serie + str(testrun.cluster_id)
fd = open(os.path.join(lock_path, lock_name), 'w')
fcntl.flock(fd, fcntl.LOCK_EX)
aquired_locks.append(fd)
nose_test_runner.SilentTestProgram(
addplugins=[nose_storage_plugin.StoragePlugin(
session, test_run_id, str(cluster_id))],
@ -88,7 +88,9 @@ class NoseDriver(object):
argv=['ostf_tests'] + argv_add)
except InterruptTestRunException:
# (dshulyak) after process is interrupted we need to
# disable existing handler
signal.signal(signal.SIGUSR1, lambda *args: signal.SIG_DFL)
if testrun.test_set.cleanup_path:
cleanup_flag = True
@ -112,10 +114,12 @@ class NoseDriver(object):
testrun.test_set.cleanup_path)
def kill(self, test_run):
if test_run.pid:
os.kill(test_run.pid, signal.SIGUSR1)
return True
try:
if test_run.pid:
os.kill(test_run.pid, signal.SIGUSR1)
return True
except OSError:
return False
return False
def _clean_up(self, session, test_run_id, cluster_id, cleanup):

View File

@ -71,7 +71,7 @@ class TestingAdapterClient(object):
def start_testrun_tests(self, testset, tests, cluster_id,
use_objects=False):
url = ''.join([self.url, '/testruns'])
data = [
data_to_dump = [
{
'testset': testset,
'tests': tests,
@ -79,12 +79,12 @@ class TestingAdapterClient(object):
}
]
if use_objects:
data_to_dump = {'objects': data}
data_to_dump = {'objects': data_to_dump}
return self._request('POST', url, data=dumps(data_to_dump))
def start_multiple_testruns(self, testsets, cluster_id, use_objects=False):
url = ''.join([self.url, '/testruns'])
data = [
data_to_dump = [
{
'testset': testset,
'tests': [],
@ -93,19 +93,19 @@ class TestingAdapterClient(object):
for testset in testsets
]
if use_objects:
data_to_dump = {'objects': data}
data_to_dump = {'objects': data_to_dump}
return self._request('POST', url, data=dumps(data_to_dump))
def stop_testrun(self, testrun_id, use_objects=False):
url = ''.join([self.url, '/testruns'])
data = [
data_to_dump = [
{
"id": testrun_id,
"status": "stopped"
}
]
if use_objects:
data_to_dump = {'objects': data}
data_to_dump = {'objects': data_to_dump}
return self._request("PUT", url, data=dumps(data_to_dump))
def stop_testrun_last(self, testset, cluster_id, use_objects=False):
@ -118,7 +118,7 @@ class TestingAdapterClient(object):
def restart_tests(self, tests, testrun_id, use_objects=False):
url = ''.join([self.url, '/testruns'])
data = [
data_to_dump = [
{
'id': str(testrun_id),
'tests': tests,
@ -126,7 +126,7 @@ class TestingAdapterClient(object):
}
]
if use_objects:
data_to_dump = {'objects': data}
data_to_dump = {'objects': data_to_dump}
return self._request('PUT', url, data=dumps(data_to_dump))
def restart_tests_last(self, testset, tests, cluster_id,

View File

@ -111,4 +111,4 @@ def serve_cluster_attributes(id):
return cluster_fixture[id]['cluster_attributes']
run(host='localhost', port=8888, debug=True)
run(host='localhost', port=8000, debug=True)

View File

@ -27,7 +27,7 @@ class AdapterTests(BaseAdapterTest):
@classmethod
def setUpClass(cls):
url = 'http://0.0.0.0:8989/v1'
url = 'http://0.0.0.0:8777/v1'
cls.mapping = {
('fuel_plugin.testing.fixture.dummy_tests.'