Merge "objects: stop using internal _context attribute"
This commit is contained in:
commit
97ec121502
@ -345,7 +345,7 @@ class NeutronDbObject(NeutronObject):
|
||||
if len(objclass.foreign_keys.keys()) > 1:
|
||||
raise NeutronSyntheticFieldMultipleForeignKeys(field=field)
|
||||
objs = objclass.get_objects(
|
||||
self._context, **{
|
||||
self.obj_context, **{
|
||||
k: getattr(
|
||||
self, v) for k, v in objclass.foreign_keys.items()})
|
||||
if isinstance(self.fields[field], obj_fields.ObjectField):
|
||||
@ -356,10 +356,10 @@ class NeutronDbObject(NeutronObject):
|
||||
|
||||
def create(self):
|
||||
fields = self._get_changed_persistent_fields()
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
try:
|
||||
db_obj = obj_db_api.create_object(
|
||||
self._context, self.db_model,
|
||||
self.obj_context, self.db_model,
|
||||
self.modify_fields_to_db(fields))
|
||||
except obj_exc.DBDuplicateEntry as db_exc:
|
||||
raise NeutronDbObjectDuplicateEntry(
|
||||
@ -396,13 +396,13 @@ class NeutronDbObject(NeutronObject):
|
||||
updates = self._validate_changed_fields(updates)
|
||||
|
||||
if updates:
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
db_obj = obj_db_api.update_object(
|
||||
self._context, self.db_model,
|
||||
self.obj_context, self.db_model,
|
||||
self.modify_fields_to_db(updates),
|
||||
**self._get_composite_keys())
|
||||
self.from_db_object(db_obj)
|
||||
|
||||
def delete(self):
|
||||
obj_db_api.delete_object(self._context, self.db_model,
|
||||
obj_db_api.delete_object(self.obj_context, self.db_model,
|
||||
**self._get_composite_keys())
|
||||
|
@ -73,7 +73,7 @@ class QosPolicy(base.NeutronDbObject):
|
||||
self.reload_rules()
|
||||
|
||||
def reload_rules(self):
|
||||
rules = rule_obj_impl.get_rules(self._context, self.id)
|
||||
rules = rule_obj_impl.get_rules(self.obj_context, self.id)
|
||||
setattr(self, 'rules', rules)
|
||||
self.obj_reset_changes(['rules'])
|
||||
|
||||
@ -139,14 +139,14 @@ class QosPolicy(base.NeutronDbObject):
|
||||
|
||||
# TODO(QoS): Consider extending base to trigger registered methods for us
|
||||
def create(self):
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
super(QosPolicy, self).create()
|
||||
self.reload_rules()
|
||||
|
||||
def delete(self):
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
for object_type, model in self.binding_models.items():
|
||||
binding_db_obj = obj_db_api.get_object(self._context, model,
|
||||
binding_db_obj = obj_db_api.get_object(self.obj_context, model,
|
||||
policy_id=self.id)
|
||||
if binding_db_obj:
|
||||
raise exceptions.QosPolicyInUse(
|
||||
@ -157,32 +157,32 @@ class QosPolicy(base.NeutronDbObject):
|
||||
super(QosPolicy, self).delete()
|
||||
|
||||
def attach_network(self, network_id):
|
||||
qos_db_api.create_policy_network_binding(self._context,
|
||||
qos_db_api.create_policy_network_binding(self.obj_context,
|
||||
policy_id=self.id,
|
||||
network_id=network_id)
|
||||
|
||||
def attach_port(self, port_id):
|
||||
qos_db_api.create_policy_port_binding(self._context,
|
||||
qos_db_api.create_policy_port_binding(self.obj_context,
|
||||
policy_id=self.id,
|
||||
port_id=port_id)
|
||||
|
||||
def detach_network(self, network_id):
|
||||
qos_db_api.delete_policy_network_binding(self._context,
|
||||
qos_db_api.delete_policy_network_binding(self.obj_context,
|
||||
policy_id=self.id,
|
||||
network_id=network_id)
|
||||
|
||||
def detach_port(self, port_id):
|
||||
qos_db_api.delete_policy_port_binding(self._context,
|
||||
qos_db_api.delete_policy_port_binding(self.obj_context,
|
||||
policy_id=self.id,
|
||||
port_id=port_id)
|
||||
|
||||
def get_bound_networks(self):
|
||||
return qos_db_api.get_network_ids_by_network_policy_binding(
|
||||
self._context, self.id)
|
||||
self.obj_context, self.id)
|
||||
|
||||
def get_bound_ports(self):
|
||||
return qos_db_api.get_port_ids_by_port_policy_binding(
|
||||
self._context, self.id)
|
||||
self.obj_context, self.id)
|
||||
|
||||
@classmethod
|
||||
def _get_bound_tenant_ids(cls, session, binding_db, bound_db,
|
||||
|
@ -182,10 +182,10 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin,
|
||||
'tenant_id': tenant_id,
|
||||
'object_type': obj_type,
|
||||
'action': models.ACCESS_SHARED}}
|
||||
return self.create_rbac_policy(self._context, rbac_policy)
|
||||
return self.create_rbac_policy(self.obj_context, rbac_policy)
|
||||
|
||||
def update_shared(self, is_shared_new, obj_id):
|
||||
admin_context = self._context.elevated()
|
||||
admin_context = self.obj_context.elevated()
|
||||
shared_prev = obj_db_api.get_object(admin_context, self.rbac_db_model,
|
||||
object_id=obj_id, target_tenant='*',
|
||||
action=models.ACCESS_SHARED)
|
||||
@ -195,13 +195,13 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin,
|
||||
|
||||
# 'shared' goes False -> True
|
||||
if not is_shared_prev and is_shared_new:
|
||||
self.attach_rbac(obj_id, self._context.tenant_id)
|
||||
self.attach_rbac(obj_id, self.obj_context.tenant_id)
|
||||
return
|
||||
|
||||
# 'shared' goes True -> False is actually an attempt to delete
|
||||
# rbac rule for sharing obj_id with target_tenant = '*'
|
||||
self._validate_rbac_policy_delete(self._context, obj_id, '*')
|
||||
return self._context.session.delete(shared_prev)
|
||||
self._validate_rbac_policy_delete(self.obj_context, obj_id, '*')
|
||||
return self.obj_context.session.delete(shared_prev)
|
||||
|
||||
|
||||
def _update_post(self):
|
||||
@ -209,27 +209,27 @@ def _update_post(self):
|
||||
|
||||
|
||||
def _update_hook(self, update_orig):
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
update_orig(self)
|
||||
_update_post(self)
|
||||
|
||||
|
||||
def _create_post(self):
|
||||
if self.shared:
|
||||
self.attach_rbac(self.id, self._context.tenant_id)
|
||||
self.attach_rbac(self.id, self.obj_context.tenant_id)
|
||||
|
||||
|
||||
def _create_hook(self, orig_create):
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
orig_create(self)
|
||||
_create_post(self)
|
||||
|
||||
|
||||
def _to_dict_hook(self, to_dict_orig):
|
||||
dct = to_dict_orig(self)
|
||||
dct['shared'] = self.is_shared_with_tenant(self._context,
|
||||
dct['shared'] = self.is_shared_with_tenant(self.obj_context,
|
||||
self.id,
|
||||
self._context.tenant_id)
|
||||
self.obj_context.tenant_id)
|
||||
return dct
|
||||
|
||||
|
||||
|
@ -77,7 +77,7 @@ class SubnetPool(base.NeutronDbObject):
|
||||
prefixes = [
|
||||
obj.cidr
|
||||
for obj in SubnetPoolPrefix.get_objects(
|
||||
self._context,
|
||||
self.obj_context,
|
||||
subnetpool_id=self.id)
|
||||
]
|
||||
setattr(self, 'prefixes', prefixes)
|
||||
@ -109,28 +109,28 @@ class SubnetPool(base.NeutronDbObject):
|
||||
# TODO(ihrachys): Consider extending base to trigger registered methods
|
||||
def create(self):
|
||||
synthetic_changes = self._get_changed_synthetic_fields()
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
super(SubnetPool, self).create()
|
||||
if 'prefixes' in synthetic_changes:
|
||||
for prefix in self.prefixes:
|
||||
prefix = SubnetPoolPrefix(
|
||||
self._context, subnetpool_id=self.id, cidr=prefix)
|
||||
self.obj_context, subnetpool_id=self.id, cidr=prefix)
|
||||
prefix.create()
|
||||
self.reload_prefixes()
|
||||
|
||||
# TODO(ihrachys): Consider extending base to trigger registered methods
|
||||
def update(self):
|
||||
with db_api.autonested_transaction(self._context.session):
|
||||
with db_api.autonested_transaction(self.obj_context.session):
|
||||
synthetic_changes = self._get_changed_synthetic_fields()
|
||||
super(SubnetPool, self).update()
|
||||
if synthetic_changes:
|
||||
if 'prefixes' in synthetic_changes:
|
||||
old = SubnetPoolPrefix.get_objects(
|
||||
self._context, subnetpool_id=self.id)
|
||||
self.obj_context, subnetpool_id=self.id)
|
||||
for prefix in old:
|
||||
prefix.delete()
|
||||
for prefix in self.prefixes:
|
||||
prefix_obj = SubnetPoolPrefix(self._context,
|
||||
prefix_obj = SubnetPoolPrefix(self.obj_context,
|
||||
subnetpool_id=self.id,
|
||||
cidr=prefix)
|
||||
prefix_obj.create()
|
||||
|
@ -281,7 +281,7 @@ class RbacNeutronDbObjectTestCase(test_base.BaseObjectIfaceTestCase,
|
||||
target_tenant='*', action=rbac_db_models.ACCESS_SHARED)
|
||||
|
||||
attach_rbac_mock.assert_called_with(
|
||||
obj_id, test_neutron_obj._context.tenant_id)
|
||||
obj_id, test_neutron_obj.obj_context.tenant_id)
|
||||
|
||||
@mock.patch.object(_test_class, 'attach_rbac')
|
||||
@mock.patch.object(obj_db_api, 'get_object',
|
||||
|
Loading…
Reference in New Issue
Block a user