Bump revision of resource on tag add/remove
This updates the tag to bump the revision of the standard attr record it's associated with. This required a small change to include a bump revision method directly on the standard attr records. Closes-Bug: #1643879 Change-Id: Ia096cd342ed3eeec33a8ae64efe13d469c375dd6
This commit is contained in:
parent
c5dde0c87c
commit
6bd3ad2bb3
|
@ -28,3 +28,4 @@ class Tag(model_base.BASEV2):
|
|||
standard_attr = orm.relationship(
|
||||
'StandardAttribute',
|
||||
backref=orm.backref('tags', lazy='joined', viewonly=True))
|
||||
revises_on_change = ('standard_attr', )
|
||||
|
|
|
@ -67,6 +67,12 @@ class StandardAttribute(model_base.BASEV2):
|
|||
"version_id_col": revision_number
|
||||
}
|
||||
|
||||
def bump_revision(self):
|
||||
if self.revision_number is None:
|
||||
# this is a brand new object uncommitted so we don't bump now
|
||||
return
|
||||
self.revision_number += 1
|
||||
|
||||
|
||||
class HasStandardAttributes(object):
|
||||
|
||||
|
@ -149,10 +155,7 @@ class HasStandardAttributes(object):
|
|||
# standard attr record is being modified, but we must call this
|
||||
# for all other modifications or when relevant children are being
|
||||
# modified (e.g. fixed_ips change should bump port revision)
|
||||
if self.standard_attr.revision_number is None:
|
||||
# this is a brand new object uncommitted so we don't bump now
|
||||
return
|
||||
self.standard_attr.revision_number += 1
|
||||
self.standard_attr.bump_revision()
|
||||
|
||||
|
||||
def get_standard_attr_resource_model_map():
|
||||
|
|
|
@ -103,8 +103,8 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase):
|
|||
res = self._get_resource(context, resource, resource_id)
|
||||
with db_api.context_manager.writer.using(context):
|
||||
query = context.session.query(tag_model.Tag)
|
||||
query = query.filter_by(standard_attr_id=res.standard_attr_id)
|
||||
query.delete()
|
||||
for t in query.filter_by(standard_attr_id=res.standard_attr_id):
|
||||
context.session.delete(t)
|
||||
|
||||
@log_helpers.log_method_call
|
||||
def delete_tag(self, context, resource, resource_id, tag):
|
||||
|
@ -113,7 +113,9 @@ class TagPlugin(common_db_mixin.CommonDbMixin, tag_ext.TagPluginBase):
|
|||
query = context.session.query(tag_model.Tag)
|
||||
query = query.filter_by(tag=tag,
|
||||
standard_attr_id=res.standard_attr_id)
|
||||
if not query.delete():
|
||||
try:
|
||||
context.session.delete(query.one())
|
||||
except exc.NoResultFound:
|
||||
raise tag_ext.TagNotFound(tag=tag)
|
||||
|
||||
# support only _apply_dict_extend_functions supported resources
|
||||
|
|
|
@ -34,7 +34,8 @@ class TestRevisionPlugin(test_plugin.Ml2PluginV2TestCase):
|
|||
def get_additional_service_plugins(self):
|
||||
p = super(TestRevisionPlugin, self).get_additional_service_plugins()
|
||||
p.update({'revision_plugin_name': 'revisions',
|
||||
'qos_plugin_name': 'qos'})
|
||||
'qos_plugin_name': 'qos',
|
||||
'tag_name': 'tag'})
|
||||
return p
|
||||
|
||||
def setUp(self):
|
||||
|
@ -175,3 +176,19 @@ class TestRevisionPlugin(test_plugin.Ml2PluginV2TestCase):
|
|||
response = self._update('networks', network['network']['id'], data)
|
||||
new_rev = response['network']['revision_number']
|
||||
self.assertGreater(new_rev, rev)
|
||||
|
||||
def test_net_tag_bumps_net_revision(self):
|
||||
with self.network() as network:
|
||||
rev = network['network']['revision_number']
|
||||
tag_plugin = directory.get_plugin('TAG')
|
||||
tag_plugin.update_tag(self.ctx, 'networks',
|
||||
network['network']['id'], 'mytag')
|
||||
updated = directory.get_plugin().get_network(
|
||||
self.ctx, network['network']['id'])
|
||||
self.assertGreater(updated['revision_number'], rev)
|
||||
tag_plugin.delete_tag(self.ctx, 'networks',
|
||||
network['network']['id'], 'mytag')
|
||||
rev = updated['revision_number']
|
||||
updated = directory.get_plugin().get_network(
|
||||
self.ctx, network['network']['id'])
|
||||
self.assertGreater(updated['revision_number'], rev)
|
||||
|
|
Loading…
Reference in New Issue