1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
14 from api.database.handlers import TasksHandler
17 class DaemonThread(threading.Thread):
19 def __init__(self, method, args):
20 super(DaemonThread, self).__init__(target=method, args=args)
22 self.command_list = args[0]
23 self.task_dict = args[1]
26 self.task_dict['status'] = 0
27 task_id = self.task_dict['task_id']
30 task_handler = TasksHandler()
31 task = task_handler.insert(self.task_dict)
33 self.method(self.command_list, task_id)
35 task_handler.update_status(task, 1)
36 except Exception as e:
37 task_handler.update_status(task, 2)
38 task_handler.update_error(task, str(e))
40 _handle_testsuite_file(task_id)
43 def _handle_testsuite_file(task_id):
45 os.remove(os.path.join(conf.TEST_SUITE_PATH, task_id + '.yaml'))
47 if e.errno != errno.ENOENT: