From f3489625f0da86be3506f3ef7fb2268ebda365cf 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 c58d22b2..7892bf97 100644 --- a/freezer_api/api/v1/sessions.py +++ b/freezer_api/api/v1/sessions.py @@ -156,11 +156,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': @@ -205,11 +205,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 d2eb19a6..ec9c4311 100644 --- a/freezer_api/common/utils.py +++ b/freezer_api/common/utils.py @@ -203,7 +203,7 @@ class SessionDoc: 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': []