From b237802a684fc031fbe43b2183577f72a778e710 Mon Sep 17 00:00:00 2001 From: Saad Zaher Date: Fri, 17 Feb 2017 01:36:57 +0000 Subject: [PATCH] Fix sessions: session_tag 1- Remove session_tag override 2- cast session tag to int while checking Change-Id: Ie44a4826f0bc2d8614cb5eedd6a622a30b6b6e23 --- freezer_api/api/v1/sessions.py | 10 +++++++--- freezer_api/common/utils.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/freezer_api/api/v1/sessions.py b/freezer_api/api/v1/sessions.py index 93639c35..0281a921 100644 --- a/freezer_api/api/v1/sessions.py +++ b/freezer_api/api/v1/sessions.py @@ -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 diff --git a/freezer_api/common/utils.py b/freezer_api/common/utils.py index 92a767e1..11549705 100644 --- a/freezer_api/common/utils.py +++ b/freezer_api/common/utils.py @@ -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': []