diff options
author | 2016-08-24 00:59:18 +0000 | |
---|---|---|
committer | 2016-08-24 00:59:18 +0000 | |
commit | 6c24c80943a59ac224fc89bb4aaacdb898b1dbcd (patch) | |
tree | 040acbf0110e1fa0e8eaafb797e0fe2120c9aaf9 | |
parent | c58b0ca140ca0edb33e78e221a04d9e1aadd8234 (diff) | |
parent | 54dc0d512764ef68b3831bfc59932cf2d9daa187 (diff) |
Merge "Add some state change functions in db.py."
-rw-r--r-- | restful_server/db.py | 24 | ||||
-rw-r--r-- | restful_server/qtip_server.py | 6 | ||||
-rw-r--r-- | tests/qtip_server_test.py | 6 |
3 files changed, 28 insertions, 8 deletions
diff --git a/restful_server/db.py b/restful_server/db.py index b8314de2..42808b80 100644 --- a/restful_server/db.py +++ b/restful_server/db.py @@ -21,7 +21,7 @@ def create_job(args): 'installer_ip': args["installer_ip"], 'pod_name': args["pod_name"], 'suite_name': args["suite_name"], - 'deadline': args["deadline"], + 'max-minutes': args["max-minutes"], 'type': args["type"], 'start-time': str(datetime.now()), 'end-time': None, @@ -34,7 +34,7 @@ def create_job(args): def delete_job(job_id): if job_id in jobs.keys(): - jobs[job_id]['end_time'] = datetime.now() + jobs[job_id]['end_time'] = str(datetime.now()) jobs[job_id]['state'] = 'terminated' return True else: @@ -46,3 +46,23 @@ def get_job_info(job_id): return jobs[job_id] else: return None + + +def finish_job(job_id, state): + jobs[job_id]['end-time'] = str(datetime.now()) + jobs[job_id]['state'] = state + + +def update_job_state_detail(job_id, state_detail): + jobs[job_id][state_detail] = state_detail + + +def update_job_result(job_id, result): + jobs[job_id][result] = result + + +def is_job_timeout(job_id): + period = datetime.now() - datetime.strptime(jobs[job_id]['start_time'], + "%Y-%m-%d %H:%M:%S.%f") + return True if jobs[job_id]['max-minutes'] * 60 < period.total_seconds()\ + else False diff --git a/restful_server/qtip_server.py b/restful_server/qtip_server.py index 59588363..00d598a0 100644 --- a/restful_server/qtip_server.py +++ b/restful_server/qtip_server.py @@ -21,7 +21,7 @@ class JobModel: resource_fields = { 'installer_type': fields.String, 'installer_ip': fields.String, - 'deadline': fields.Integer, + 'max-minutes': fields.Integer, 'pod_name': fields.String, 'suite_name': fields.String, 'type': fields.String @@ -88,7 +88,7 @@ class JobList(Resource): "installer_ip": The installer ip of the pod, -"deadline": If specified, the maximum duration in minutes +"max-minutes": If specified, the maximum duration in minutes for any single test iteration, default is '10', "pod_name": If specified, the Pod name, default is 'default', @@ -122,7 +122,7 @@ default is 'all' parser = reqparse.RequestParser() parser.add_argument('installer_type', type=str, required=True, help='Installer_type is required') parser.add_argument('installer_ip', type=str, required=True, help='Installer_ip is required') - parser.add_argument('deadline', type=int, required=False, default=10, help='dealine should be integer') + parser.add_argument('max-minutes', type=int, required=False, default=10, help='max-minutes should be integer') parser.add_argument('pod_name', type=str, required=False, default='default', help='pod_name should be string') parser.add_argument('suite_name', type=str, required=False, default='all', help='suite_name should be string') parser.add_argument('type', type=str, required=False, default='BM', help='type should be BM, VM and ALL') diff --git a/tests/qtip_server_test.py b/tests/qtip_server_test.py index 31aa96dc..c2b12974 100644 --- a/tests/qtip_server_test.py +++ b/tests/qtip_server_test.py @@ -23,7 +23,7 @@ class TestClass: 'installer_ip': '10.20.0.2', 'pod_name': 'default', 'suite_name': 'all', - 'deadline': 10, + 'max-minutes': 10, 'type': 'BM', 'state': 'processing', 'state_detail': [], @@ -31,7 +31,7 @@ class TestClass: ({'installer_type': 'fuel', 'installer_ip': '10.20.0.2', 'pod_name': 'zte-pod1', - 'deadline': 20, + 'max-minutes': 20, 'suite_name': 'compute', 'type': 'VM'}, {'job_id': '', @@ -39,7 +39,7 @@ class TestClass: 'installer_ip': '10.20.0.2', 'pod_name': 'zte-pod1', 'suite_name': 'compute', - 'deadline': 20, + 'max-minutes': 20, 'type': 'VM', 'state': 'processing', 'state_detail': [], |