Merge "do not allow redis job reclaim by same owner"

This commit is contained in:
Jenkins 2017-05-31 05:48:00 +00:00 committed by Gerrit Code Review
commit cf0ee0b0c7
2 changed files with 26 additions and 5 deletions

View File

@ -410,12 +410,10 @@ if redis.call("hexists", listings_key, job_key) == 1 then
-- Owner is the same, leave it alone... -- Owner is the same, leave it alone...
redis.call("set", last_modified_key, last_modified_blob) redis.call("set", last_modified_key, last_modified_blob)
apply_ttl(owner_key, ms_expiry) apply_ttl(owner_key, ms_expiry)
result["status"] = "${ok}" end
else
result["status"] = "${error}" result["status"] = "${error}"
result["reason"] = "${already_claimed}" result["reason"] = "${already_claimed}"
result["owner"] = owner result["owner"] = owner
end
else else
redis.call("set", owner_key, expected_owner) redis.call("set", owner_key, expected_owner)
redis.call("set", last_modified_key, last_modified_blob) redis.call("set", last_modified_key, last_modified_blob)

View File

@ -20,6 +20,7 @@ from oslo_utils import uuidutils
import six import six
import testtools import testtools
from taskflow import exceptions as excp
from taskflow.jobs.backends import impl_redis from taskflow.jobs.backends import impl_redis
from taskflow import states from taskflow import states
from taskflow import test from taskflow import test
@ -76,6 +77,28 @@ class RedisJobboardTest(test.TestCase, base.BoardTestMixin):
possible_jobs = list(self.board.iterjobs(only_unclaimed=True)) possible_jobs = list(self.board.iterjobs(only_unclaimed=True))
self.assertEqual(1, len(possible_jobs)) self.assertEqual(1, len(possible_jobs))
def test_posting_claim_same_owner(self):
with base.connect_close(self.board):
with self.flush(self.client):
self.board.post('test', p_utils.temporary_log_book())
self.assertEqual(1, self.board.job_count)
possible_jobs = list(self.board.iterjobs(only_unclaimed=True))
self.assertEqual(1, len(possible_jobs))
j = possible_jobs[0]
self.assertEqual(states.UNCLAIMED, j.state)
with self.flush(self.client):
self.board.claim(j, self.board.name)
possible_jobs = list(self.board.iterjobs())
self.assertEqual(1, len(possible_jobs))
with self.flush(self.client):
self.assertRaises(excp.UnclaimableJob, self.board.claim,
possible_jobs[0], self.board.name)
possible_jobs = list(self.board.iterjobs(only_unclaimed=True))
self.assertEqual(0, len(possible_jobs))
def setUp(self): def setUp(self):
super(RedisJobboardTest, self).setUp() super(RedisJobboardTest, self).setUp()
self.client, self.board = self.create_board() self.client, self.board = self.create_board()