Exemplo n.º 1
0
def flowdetail_get(fd_id):
    """Gets a FlowDetail with matching fd_id, if it exists"""
    # Try to get the FlowDetail
    try:
        fd = flowdetails[fd_id]
    # Raise a NotFound exception if it is not there
    except KeyError:
        raise exception.NotFound("No FlowDetail found with id "
                                 "%s." % (fd_id, ))

    # Acquire a read lock on the FlowDetail
    with fd.acquire_lock(read=True):
        # Get the Flow this FlowDetail represents
        wf = fd.flow

        # Create a FlowDetail to return
        retVal = flowdetail.FlowDetail(fd.name, wf, fd.uuid)

        # Change updated_at to reflect the current data
        retVal.updated_at = fd.updated_at

        # Add the generic TaskDetails to the FlowDetail to return
        for td in fd:
            retVal.add_task_detail(taskdetail_get(td.uuid))

    return retVal
Exemplo n.º 2
0
def _convert_fd_to_external(fd):
    fd_c = flowdetail.FlowDetail(fd.name, uuid=fd.uuid, backend='sqlalchemy')
    fd_c.meta = fd.meta
    fd_c.state = fd.state
    for td in fd.taskdetails:
        fd_c.add(_convert_td_to_external(td))
    return fd_c
Exemplo n.º 3
0
    def test_flowdetail_save(self):
        # Create a generic flowdetail to save
        fd_id = uuidutils.generate_uuid()
        fd_name = 'fd-%s' % (fd_id)
        wf = self.wfs[0]
        fd = flowdetail.FlowDetail(fd_name, wf, fd_id)

        # Save the generic flowdetail to the backend and record its uuid/name
        b_api.flowdetail_save(fd)
        self.fd_names.append(fd_name)
        self.fd_ids.append(fd_id)

        # Check that the saved flowdetail is in the backend
        actual = b_api.flowdetail_get(fd_id)

        self.assertIsNotNone(actual)
        # Check that the saved flowdetail has no taskdetails
        self.assertEquals(len(actual), 0)

        # Add a generic taskdetail to the flowdetail
        td = b_api.taskdetail_get(self.td_ids[0])
        fd.add_task_detail(td)

        # Save the updated flowdetail
        b_api.flowdetail_save(fd)

        # Check that the saved flowdetail is still there
        actual = b_api.flowdetail_get(fd_id)

        self.assertIsNotNone(actual)
        # Check that the addition of a taskdetail was recorded
        self.assertEquals(len(actual), 1)
Exemplo n.º 4
0
    def test_logbook_merge_flow_detail(self):
        lb_id = uuidutils.generate_uuid()
        lb_name = 'lb-%s' % (lb_id)
        lb = logbook.LogBook(name=lb_name,
                             uuid=lb_id,
                             backend=self._get_backend())

        fd = flowdetail.FlowDetail('test', uuid=uuidutils.generate_uuid())
        lb.add(fd)
        lb.save()

        lb2 = logbook.LogBook(name=lb_name,
                              uuid=lb_id,
                              backend=self._get_backend())
        fd = flowdetail.FlowDetail('test2', uuid=uuidutils.generate_uuid())
        lb2.add(fd)
        lb2.save()

        lb3 = logbook.load(lb_id, backend=self._get_backend())
        self.assertEquals(2, len(lb3))
Exemplo n.º 5
0
def temporary_flow_detail():
    """Creates flow detail class for temporary usage

    Creates in-memory logbook and flow detail in it. Should
    be useful for tests and other use cases where persistence
    is not needed
    """
    lb = logbook.LogBook('tmp', backend='memory')
    fd = flowdetail.FlowDetail(name='tmp',
                               uuid=uuidutils.generate_uuid(),
                               backend='memory')
    lb.add(fd)
    lb.save()
    fd.save()
    return fd
Exemplo n.º 6
0
    def test_flow_detail_save(self):
        lb_id = uuidutils.generate_uuid()
        lb_name = 'lb-%s' % (lb_id)
        lb = logbook.LogBook(name=lb_name,
                             uuid=lb_id,
                             backend=self._get_backend())

        fd = flowdetail.FlowDetail('test', uuid=uuidutils.generate_uuid())
        lb.add(fd)

        # Ensure we can't save it since its owning logbook hasn't been
        # saved.
        self.assertRaises(exc.NotFound, fd.save)

        # Ok now we should be able to save it
        lb.save()
        fd.save()
Exemplo n.º 7
0
def flowdetail_get(fd_id):
    """Gets a FlowDetail with matching fd_id, if it exists"""
    # Get a session for interaction with the database
    session = sql_session.get_session()
    with session.begin():
        # Get the FlowDetail model from the database
        fd = _flowdetail_get_model(fd_id, session=session)

    # Create a generic FlowDetail to return
    retVal = flowdetail.FlowDetail(fd.name, None, fd.flowdetail_id)

    # Update attributes to match
    retVal.updated_at = fd.updated_at

    # Add the TaskDetails belonging to this FlowDetail to itself
    for td in fd.taskdetails:
        retVal.add_task_detail(taskdetail_get(td.taskdetail_id))

    return retVal
Exemplo n.º 8
0
    def test_logbook_add_task_detail(self):
        lb_id = uuidutils.generate_uuid()
        lb_name = 'lb-%s' % (lb_id)
        lb = logbook.LogBook(name=lb_name,
                             uuid=lb_id,
                             backend=self._get_backend())

        fd = flowdetail.FlowDetail('test', uuid=uuidutils.generate_uuid())
        td = taskdetail.TaskDetail("detail-1", uuid=uuidutils.generate_uuid())
        fd.add(td)
        lb.add(fd)
        lb.save()

        lb2 = logbook.load(lb_id, backend=self._get_backend())
        self.assertEquals(1, len(lb2))
        tasks = 0
        for fd in lb:
            tasks += len(fd)
        self.assertEquals(1, tasks)