Ensure that the zookeeper backend creates missing atoms

When 'create_missing' is true the atom should be created
instead of raising an exception; this is used when a flow
detail is updated with a new detail and then saved.

This also adds test cases that verify this happens so that
we verify this on an ongoing basis.

Fixes bug 1395812

Change-Id: I4851a08ff1ab4101dbec4a6656177908095c3c52
This commit is contained in:
Joshua Harlow
2014-11-21 13:07:47 -08:00
parent a77d192f9c
commit 2832d6e677
2 changed files with 47 additions and 2 deletions

View File

@@ -169,7 +169,11 @@ class ZkConnection(base.Connection):
ad_data, _zstat = self._client.get(ad_path)
except k_exc.NoNodeError:
# Not-existent: create or raise exception.
raise exc.NotFound("No atom details found with id: %s" % ad.uuid)
if not create_missing:
raise exc.NotFound("No atom details found with"
" id: %s" % ad.uuid)
else:
txn.create(ad_path)
else:
# Existent: read it out.
try:

View File

@@ -25,7 +25,48 @@ from taskflow.types import failure
class PersistenceTestMixin(object):
def _get_connection(self):
raise NotImplementedError()
raise NotImplementedError('_get_connection() implementation required')
def test_task_detail_update_not_existing(self):
lb_id = uuidutils.generate_uuid()
lb_name = 'lb-%s' % (lb_id)
lb = logbook.LogBook(name=lb_name, uuid=lb_id)
fd = logbook.FlowDetail('test', uuid=uuidutils.generate_uuid())
lb.add(fd)
td = logbook.TaskDetail("detail-1", uuid=uuidutils.generate_uuid())
fd.add(td)
with contextlib.closing(self._get_connection()) as conn:
conn.save_logbook(lb)
td2 = logbook.TaskDetail("detail-1", uuid=uuidutils.generate_uuid())
fd.add(td2)
with contextlib.closing(self._get_connection()) as conn:
conn.update_flow_details(fd)
with contextlib.closing(self._get_connection()) as conn:
lb2 = conn.get_logbook(lb.uuid)
fd2 = lb2.find(fd.uuid)
self.assertIsNotNone(fd2.find(td.uuid))
self.assertIsNotNone(fd2.find(td2.uuid))
def test_flow_detail_update_not_existing(self):
lb_id = uuidutils.generate_uuid()
lb_name = 'lb-%s' % (lb_id)
lb = logbook.LogBook(name=lb_name, uuid=lb_id)
fd = logbook.FlowDetail('test', uuid=uuidutils.generate_uuid())
lb.add(fd)
with contextlib.closing(self._get_connection()) as conn:
conn.save_logbook(lb)
fd2 = logbook.FlowDetail('test-2', uuid=uuidutils.generate_uuid())
lb.add(fd2)
with contextlib.closing(self._get_connection()) as conn:
conn.save_logbook(lb)
with contextlib.closing(self._get_connection()) as conn:
lb2 = conn.get_logbook(lb.uuid)
self.assertIsNotNone(lb2.find(fd.uuid))
self.assertIsNotNone(lb2.find(fd2.uuid))
def test_logbook_save_retrieve(self):
lb_id = uuidutils.generate_uuid()