Add some state change functions in db.py. 27/19127/3
authorzhifeng.jiang <jiang.zhifeng@zte.com.cn>
Sun, 21 Aug 2016 13:40:44 +0000 (21:40 +0800)
committerzhifeng.jiang <jiang.zhifeng@zte.com.cn>
Tue, 23 Aug 2016 11:39:38 +0000 (19:39 +0800)
modification:
   Add some functions in db.py
   Unit test will be added after functions called by restful server.
   Rename 'deadline' to 'max-minutes'

JIRA:QTIP-99

Change-Id: I74ed93df3f2dd91fa154fa0fcb52605983ee2719
Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
restful_server/db.py
restful_server/qtip_server.py
tests/qtip_server_test.py

index b8314de..42808b8 100644 (file)
@@ -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
index 5958836..00d598a 100644 (file)
@@ -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')
index 31aa96d..c2b1297 100644 (file)
@@ -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': [],