Example #1
0
    def run_idl(self, txn):
        try:
            ovn_table = RESOURCE_TYPE_MAP[self.resource_type]
            # TODO(lucasagomes): After OVS 2.8.2 is released all tables should
            # have the external_ids column. We can remove this conditional
            # here by then.
            if not self.api.is_col_present(ovn_table, 'external_ids'):
                return

            ovn_resource = None
            if self.resource_type == ovn_const.TYPE_FLOATINGIPS:
                ovn_resource = self._get_floatingip()
            elif self.resource_type == ovn_const.TYPE_SUBNETS:
                ovn_resource = self._get_subnet()
            else:
                ovn_resource = self.api.lookup(ovn_table, self.name)
        except idlutils.RowNotFound:
            if self.if_exists:
                return
            msg = (_('Failed to check the revision number for %s: Resource '
                     'does not exist') % self.name)
            raise RuntimeError(msg)

        external_ids = getattr(ovn_resource, 'external_ids', {})
        ovn_revision = int(
            external_ids.get(ovn_const.OVN_REV_NUM_EXT_ID_KEY, -1))
        neutron_revision = utils.get_revision_number(self.resource,
                                                     self.resource_type)
        if ovn_revision > neutron_revision:
            raise ovn_exc.RevisionConflict(resource_id=self.name,
                                           resource_type=self.resource_type)

        ovn_resource.verify('external_ids')
        ovn_resource.setkey('external_ids', ovn_const.OVN_REV_NUM_EXT_ID_KEY,
                            str(neutron_revision))
Example #2
0
def bump_revision(resource, resource_type):
    session = db_api.get_writer_session()
    revision_number = utils.get_revision_number(resource, resource_type)
    with session.begin():
        _ensure_revision_row_exist(session, resource, resource_type)
        std_attr_id = _get_standard_attr_id(session, resource['id'],
                                            resource_type)
        row = session.merge(
            models.OVNRevisionNumbers(standard_attr_id=std_attr_id,
                                      resource_uuid=resource['id']))
        if revision_number < row.revision_number:
            LOG.debug(
                'Skip bumping the revision number for %(res_uuid)s (type: '
                '%(res_type)s) to %(rev_num)d. A higher version is already '
                'registered in the database (%(new_rev)d)', {
                    'res_type': resource_type,
                    'res_uuid': resource['id'],
                    'rev_num': revision_number,
                    'new_rev': row.revision_number
                })
            return
        row.revision_number = revision_number
        session.merge(row)
    LOG.info(
        'Successfully bumped revision number for resource '
        '%(res_uuid)s (type: %(res_type)s) to %(rev_num)d', {
            'res_uuid': resource['id'],
            'res_type': resource_type,
            'rev_num': revision_number
        })