Example #1
0
def calculate(session, operation, object_type, object_uuid, data):
    """Calculate resource deps in journaled operations.

    As a rule of thumb validation takes into consideration only operations in
    pending or processing state, other states are irrelevant.
    :param session: db session
    :param row: entry in journal entry to be validated
    """
    deps = []
    if operation == odl_const.ODL_DELETE:
        return _get_delete_dependencies(session, object_type, object_uuid)
    elif operation == odl_const.ODL_UPDATE:
        deps.extend(
            db.get_pending_or_processing_ops(session,
                                             object_uuid,
                                             operation=(odl_const.ODL_CREATE,
                                                        odl_const.ODL_UPDATE)))
    elif operation != odl_const.ODL_CREATE:
        raise ValueError(_("unsupported operation {}").format(operation))

    # Validate deps if there are any to validate.
    dep_generator = _CREATE_OR_UPDATE_DEP_GENERATOR.get(object_type)
    if dep_generator is not None:
        object_ids = dep_generator(data)
        if object_ids is not None:
            deps.extend(_get_older_operations(session, object_ids))

    return deps
def calculate(context, operation, object_type, object_uuid, data):
    """Calculate resource deps in journaled operations.

    As a rule of thumb validation takes into consideration only operations in
    pending or processing state, other states are irrelevant.
    :param context: enginefacade context
    :param row: entry in journal entry to be validated
    """
    deps = []
    if operation == odl_const.ODL_DELETE:
        return _get_delete_dependencies(context, object_type, object_uuid)
    elif operation == odl_const.ODL_UPDATE:
        deps.extend(
            db.get_pending_or_processing_ops(
                context, object_uuid,
                operation=(odl_const.ODL_CREATE, odl_const.ODL_UPDATE)))
    elif operation != odl_const.ODL_CREATE:
        raise ValueError(_("unsupported operation {}").format(operation))

    # Validate deps if there are any to validate.
    dep_generator = _CREATE_OR_UPDATE_DEP_GENERATOR.get(object_type)
    if dep_generator is not None:
        object_ids = dep_generator(data)
        if object_ids is not None:
            deps.extend(_get_older_operations(context, object_ids))

    return deps
Example #3
0
    def _test_validate_updates(self, first_entry, second_entry, expected_deps,
                               state=None):
        db.create_pending_row(self.db_context, *first_entry)
        if state:
            row = db.get_all_db_rows(self.db_context)[0]
            row.state = state
            self._update_row(row)

        deps = db.get_pending_or_processing_ops(
            self.db_context, second_entry[1], second_entry[2])
        self.assertEqual(expected_deps, len(deps) != 0)
Example #4
0
def _get_older_operations(session, object_ids):
    """Get any older operations.

    Return any operations still in the queue for the given ID(s).
    """
    if not isinstance(object_ids, (list, tuple)):
        object_ids = (object_ids, )

    deps = []
    for object_id in object_ids:
        deps.extend(db.get_pending_or_processing_ops(session, object_id))

    return deps
def _get_older_operations(context, object_ids):
    """Get any older operations.

    Return any operations still in the queue for the given ID(s).
    """
    if not isinstance(object_ids, (list, tuple)):
        object_ids = (object_ids,)

    deps = []
    for object_id in object_ids:
        deps.extend(
            db.get_pending_or_processing_ops(context, object_id))

    return deps
Example #6
0
    def _test_validate_updates(self,
                               first_entry,
                               second_entry,
                               expected_deps,
                               state=None):
        db.create_pending_row(self.db_session, *first_entry)
        if state:
            row = db.get_all_db_rows(self.db_session)[0]
            row.state = state
            self._update_row(row)

        deps = db.get_pending_or_processing_ops(self.db_session,
                                                second_entry[1],
                                                second_entry[2])
        self.assertEqual(expected_deps, len(deps) != 0)
def _get_delete_dependencies(context, object_type, object_uuid):
    """Get dependent operations for a delete operation.

    Return any operations that pertain to the delete: Either create
    or update operations on the same object, or delete operations on other
    objects that depend on the deleted object.
    """
    # Get any pending or processing create or update ops on the row itself
    deps = db.get_pending_or_processing_ops(
        context, object_uuid, operation=(odl_const.ODL_UPDATE,
                                         odl_const.ODL_CREATE))

    # Get dependent operations of other dependent types
    dependent_resource_types = _DELETE_DEPENDENCIES.get(object_type)
    if dependent_resource_types is not None:
        for resource_type in dependent_resource_types:
            deps.extend(db.get_pending_delete_ops_with_parent(
                context, resource_type, object_uuid))

    return deps
Example #8
0
def _get_delete_dependencies(session, object_type, object_uuid):
    """Get dependent operations for a delete operation.

    Return any operations that pertain to the delete: Either create
    or update operations on the same object, or delete operations on other
    objects that depend on the deleted object.
    """
    # Get any pending or processing create or update ops on the row itself
    deps = db.get_pending_or_processing_ops(session,
                                            object_uuid,
                                            operation=(odl_const.ODL_UPDATE,
                                                       odl_const.ODL_CREATE))

    # Get dependent operations of other dependent types
    dependent_resource_types = _DELETE_DEPENDENCIES.get(object_type)
    if dependent_resource_types is not None:
        for resource_type in dependent_resource_types:
            deps.extend(
                db.get_pending_delete_ops_with_parent(session, resource_type,
                                                      object_uuid))

    return deps
Example #9
0
def _canary_network_not_in_journal(context):
    return not db.get_pending_or_processing_ops(
        context.session, _CANARY_NETWORK_ID, operation=odl_const.ODL_CREATE)
Example #10
0
def _canary_network_not_in_journal(context):
    return not db.get_pending_or_processing_ops(
        context, _CANARY_NETWORK_ID, operation=odl_const.ODL_CREATE)