objects: remove support for multiple db models in from_db_object
This was once implemented to allow objects that aggregate attributes from multiple models. Specifically, that was the original design for QoS rules, where we had a model with common attributes, and then a separate model with rule specific attributes. After a while, struggling to make it work without huge hacks, and after rethinking database schema, we dropped the original design for QoS rules, replacing it with a single model per type. This patch cleans up the remnants of those dark ages of QoS. This should make the code a bit more clear to readers who currently wonder why we may have multiple database models for the same versioned object. Change-Id: I6a083f95ec02f61ced8f7ad0117560347d64b369 Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
This commit is contained in:
parent
1cf8e5ab5a
commit
c8fea2b392
neutron
@ -294,15 +294,12 @@ class NeutronDbObject(NeutronObject):
|
||||
# in to_dict()
|
||||
# obj_extra_fields = []
|
||||
|
||||
def from_db_object(self, *objs):
|
||||
db_objs = [self.modify_fields_from_db(db_obj) for db_obj in objs]
|
||||
def from_db_object(self, db_obj):
|
||||
fields = self.modify_fields_from_db(db_obj)
|
||||
for field in self.fields:
|
||||
for db_obj in db_objs:
|
||||
if field in db_obj and not self.is_synthetic(field):
|
||||
setattr(self, field, db_obj[field])
|
||||
break
|
||||
for obj in objs:
|
||||
self.load_synthetic_db_fields(obj)
|
||||
if field in fields and not self.is_synthetic(field):
|
||||
setattr(self, field, fields[field])
|
||||
self.load_synthetic_db_fields(db_obj)
|
||||
self.obj_reset_changes()
|
||||
|
||||
@classmethod
|
||||
|
@ -59,12 +59,8 @@ class SecurityGroup(base.NeutronDbObject):
|
||||
self.is_default = True
|
||||
self.obj_reset_changes(['is_default'])
|
||||
|
||||
def from_db_object(self, *objs):
|
||||
super(SecurityGroup, self).from_db_object(*objs)
|
||||
for obj in objs:
|
||||
self._load_is_default(obj)
|
||||
|
||||
def _load_is_default(self, db_obj):
|
||||
def from_db_object(self, db_obj):
|
||||
super(SecurityGroup, self).from_db_object(db_obj)
|
||||
setattr(self, 'is_default', bool(db_obj.get('default_security_group')))
|
||||
self.obj_reset_changes(['is_default'])
|
||||
|
||||
|
@ -209,10 +209,9 @@ class Subnet(base.NeutronDbObject):
|
||||
setattr(self, 'shared', shared)
|
||||
self.obj_reset_changes(['shared'])
|
||||
|
||||
def from_db_object(self, *objs):
|
||||
super(Subnet, self).from_db_object(*objs)
|
||||
for obj in objs:
|
||||
self._load_shared(obj)
|
||||
def from_db_object(self, db_obj):
|
||||
super(Subnet, self).from_db_object(db_obj)
|
||||
self._load_shared(db_obj)
|
||||
|
||||
@classmethod
|
||||
def modify_fields_from_db(cls, db_obj):
|
||||
|
@ -93,10 +93,10 @@ class SecurityGroupDbObjTestCase(test_base.BaseDbObjectTestCase,
|
||||
def test_get_objects_queries_constant(self):
|
||||
# TODO(electrocucaracha) SecurityGroup is using SecurityGroupRule
|
||||
# object to reload rules, which costs extra SQL query each time
|
||||
# _load_is_default are called in get_object(s). SecurityGroup has
|
||||
# defined relationship for SecurityGroupRules, so it should be possible
|
||||
# to reuse side loaded values fo this. To be reworked in follow-up
|
||||
# patch.
|
||||
# is_default field is loaded as part of get_object(s). SecurityGroup
|
||||
# has defined relationship for SecurityGroupRules, so it should be
|
||||
# possible to reuse side loaded values fo this. To be reworked in
|
||||
# follow-up patch.
|
||||
pass
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user