Merge "Handle event id in node requests"
This commit is contained in:
commit
476364142f
@ -606,6 +606,7 @@ class TestZooKeeper(tests.DBTestCase):
|
||||
|
||||
def test_storeNodeRequest(self):
|
||||
req = self._create_node_request()
|
||||
self.assertNotEqual(req.event_id, None)
|
||||
req2 = self.zk.getNodeRequest(req.id)
|
||||
self.assertEqual(req, req2)
|
||||
|
||||
@ -872,6 +873,9 @@ class TestZKModel(tests.BaseTestCase):
|
||||
o.nodes.append('100')
|
||||
o.reuse = False
|
||||
o.requestor = 'zuul'
|
||||
o.provider = "test"
|
||||
o.relative_priority = 1
|
||||
o.event_id = "deadbeef"
|
||||
d = o.toDict()
|
||||
self.assertNotIn('id', d)
|
||||
self.assertIn('state', d)
|
||||
@ -881,6 +885,9 @@ class TestZKModel(tests.BaseTestCase):
|
||||
self.assertEqual(d['nodes'], o.nodes)
|
||||
self.assertEqual(d['reuse'], o.reuse)
|
||||
self.assertEqual(d['requestor'], o.requestor)
|
||||
self.assertEqual(d['provider'], o.provider)
|
||||
self.assertEqual(d['relative_priority'], o.relative_priority)
|
||||
self.assertEqual(d['event_id'], o.event_id)
|
||||
|
||||
def test_NodeRequest_fromDict(self):
|
||||
now = int(time.time())
|
||||
@ -893,6 +900,9 @@ class TestZKModel(tests.BaseTestCase):
|
||||
'nodes': ['100'],
|
||||
'reuse': False,
|
||||
'requestor': 'zuul',
|
||||
'provider': 'test',
|
||||
'relative_priority': 1,
|
||||
'event_id': 'deadbeef',
|
||||
}
|
||||
|
||||
o = zk.NodeRequest.fromDict(d, req_id)
|
||||
@ -904,6 +914,9 @@ class TestZKModel(tests.BaseTestCase):
|
||||
self.assertEqual(o.nodes, d['nodes'])
|
||||
self.assertEqual(o.reuse, d['reuse'])
|
||||
self.assertEqual(o.requestor, d['requestor'])
|
||||
self.assertEqual(o.provider, d['provider'])
|
||||
self.assertEqual(o.relative_priority, d['relative_priority'])
|
||||
self.assertEqual(o.event_id, d['event_id'])
|
||||
|
||||
def test_Node_toDict(self):
|
||||
o = zk.Node('123')
|
||||
|
@ -16,6 +16,8 @@ import abc
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from kazoo.client import KazooClient, KazooState
|
||||
from kazoo import exceptions as kze
|
||||
from kazoo.handlers.threading import KazooTimeoutError
|
||||
@ -448,6 +450,7 @@ class NodeRequest(BaseModel):
|
||||
self.requestor = None
|
||||
self.provider = None
|
||||
self.relative_priority = 0
|
||||
self.event_id = None
|
||||
|
||||
def __repr__(self):
|
||||
d = self.toDict()
|
||||
@ -480,6 +483,7 @@ class NodeRequest(BaseModel):
|
||||
d['requestor'] = self.requestor
|
||||
d['provider'] = self.provider
|
||||
d['relative_priority'] = self.relative_priority
|
||||
d['event_id'] = self.event_id
|
||||
return d
|
||||
|
||||
@staticmethod
|
||||
@ -506,6 +510,7 @@ class NodeRequest(BaseModel):
|
||||
self.requestor = d.get('requestor')
|
||||
self.provider = d.get('provider')
|
||||
self.relative_priority = d.get('relative_priority', 0)
|
||||
self.event_id = d.get('event_id')
|
||||
|
||||
|
||||
class Node(BaseModel):
|
||||
@ -1733,6 +1738,8 @@ class ZooKeeper(object):
|
||||
:param str priority: Priority of a new request. Ignored on updates.
|
||||
'''
|
||||
if not request.id:
|
||||
if not request.event_id:
|
||||
request.event_id = uuid.uuid4().hex
|
||||
path = "%s/%s-" % (self.REQUEST_ROOT, priority)
|
||||
path = self.client.create(
|
||||
path,
|
||||
|
Loading…
x
Reference in New Issue
Block a user