Fix sessions: session_tag

1- Remove session_tag override
2- cast session tag to int while checking

Change-Id: Ie44a4826f0bc2d8614cb5eedd6a622a30b6b6e23
This commit is contained in:
Saad Zaher
2017-02-17 01:36:57 +00:00
committed by Saad Zaher
parent 30040850f7
commit b237802a68
2 changed files with 8 additions and 4 deletions

View File

@@ -157,11 +157,11 @@ class Session(resource.BaseResource):
@property
def session_tag(self):
return self.doc.get('session_tag', 0)
return int(self.doc.get('session_tag', 0))
@session_tag.setter
def session_tag(self, value):
self.doc['session_tag'] = value
self.doc['session_tag'] = int(value)
def execute_action(self, action, params):
if action == 'start':
@@ -206,11 +206,15 @@ class Session(resource.BaseResource):
and sets the need_update member to notify that the stored
document needs to be updated
"""
job_tag = int(job_tag)
self.session_tag = int(self.session_tag)
now = int(time.time())
time_since_last_start = now - self.doc.get('time_start', 0)
if job_tag > self.session_tag:
raise freezer_api_exc.BadDataFormat('requested tag value too high')
raise freezer_api_exc.BadDataFormat(
'requested tag value too high. Session Tag: {0} '
'Job Tag: {1}'.format(self.session_tag, job_tag))
if time_since_last_start <= self.doc.get('hold_off', 60):
# session has been started not so long ago

View File

@@ -187,7 +187,7 @@ class SessionDoc(object):
doc.update({
'user_id': user_id,
'session_id': uuid.uuid4().hex,
'session_tag': 0,
'session_tag': doc.get('session_tag', 0),
'status': 'active',
'last_start': '',
'jobs': []