Skip to content

Commit b11fb88

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Bump revision number of objects when description is changed" into stable/yoga
2 parents 3d036d5 + edc2680 commit b11fb88

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

neutron/services/revisions/revision_plugin.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,38 @@ def __init__(self):
4949
db_api.sqla_listen(se.Session, 'after_rollback',
5050
self._clear_rev_bumped_flags)
5151

52+
def _get_objects_to_bump_revision(self, dirty_objects):
53+
all_std_attr_objects = []
54+
objects_to_bump_revision = []
55+
for dirty_object in dirty_objects:
56+
if isinstance(dirty_object, standard_attr.HasStandardAttributes):
57+
objects_to_bump_revision.append(dirty_object)
58+
elif isinstance(dirty_object, standard_attr.StandardAttribute):
59+
all_std_attr_objects.append(dirty_object)
60+
61+
# Now as we have all objects divided into 2 groups, we need to ensure
62+
# that we don't have revision number for the same one in both groups.
63+
# It may happen e.g. for the Subnet object, as during update of Subnet,
64+
# both Subnet and StandardAttribute objects of that subnet are dirty.
65+
# But for example for Network, when only description is changed, only
66+
# StandardAttribute object is in the dirty objects set.
67+
std_attr_ids = [o.standard_attr_id for o in objects_to_bump_revision]
68+
69+
# NOTE(slaweq): StandardAttribute objects which have "description"
70+
# field modified, should have revision bumped too
71+
objects_to_bump_revision += [
72+
o for o in all_std_attr_objects
73+
if ('description' not in o._sa_instance_state.unmodified and
74+
o.id not in std_attr_ids)]
75+
76+
return objects_to_bump_revision
77+
5278
def bump_revisions(self, session, context, instances):
5379
self._enforce_if_match_constraints(session)
54-
# bump revision number for any updated objects in the session
80+
# bump revision number for updated objects in the session
5581
self._bump_obj_revisions(
5682
session,
57-
[
58-
obj for obj in session.dirty
59-
if isinstance(obj, standard_attr.HasStandardAttributes)]
60-
)
83+
self._get_objects_to_bump_revision(session.dirty))
6184

6285
# see if any created/updated/deleted objects bump the revision
6386
# of another object

neutron/tests/unit/services/revisions/test_revision_plugin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ def test_port_ip_update_revises(self):
191191
new_rev = response['port']['revision_number']
192192
self.assertGreater(new_rev, rev)
193193

194+
def test_network_description_bumps_revision(self):
195+
with self.network() as net:
196+
rev = net['network']['revision_number']
197+
data = {'network': {'description': 'Test Description'}}
198+
response = self._update('networks', net['network']['id'], data)
199+
new_rev = response['network']['revision_number']
200+
self.assertEqual(rev + 1, new_rev)
201+
202+
def test_subnet_description_bumps_revision(self):
203+
with self.subnet() as subnet:
204+
rev = subnet['subnet']['revision_number']
205+
data = {'subnet': {'description': 'Test Description'}}
206+
response = self._update('subnets', subnet['subnet']['id'], data)
207+
new_rev = response['subnet']['revision_number']
208+
self.assertEqual(rev + 1, new_rev)
209+
194210
def test_security_group_rule_ops_bump_security_group(self):
195211
s = {'security_group': {'tenant_id': 'some_tenant', 'name': '',
196212
'description': 's'}}

0 commit comments

Comments
 (0)