def test_get_object_create_update_delete(self): obj = api.create_object(self.ctxt, self.model, {'name': 'foo'}) new_obj = api.get_object(self.ctxt, self.model, id=obj.id) self.assertEqual(obj, new_obj) obj = new_obj api.update_object(self.ctxt, self.model, {'name': 'bar'}, id=obj.id) new_obj = api.get_object(self.ctxt, self.model, id=obj.id) self.assertEqual(obj, new_obj) obj = new_obj api.delete_object(self.ctxt, self.model, id=obj.id) new_obj = api.get_object(self.ctxt, self.model, id=obj.id) self.assertIsNone(new_obj) # delete_object raises an exception on missing object self.assertRaises( n_exc.ObjectNotFound, api.delete_object, self.ctxt, self.model, id=obj.id) # but delete_objects does not not api.delete_objects(self.ctxt, self.model, id=obj.id)
def test_get_object_create_update_delete(self): obj = api.create_object(self.ctxt, self.model, {'name': 'foo'}) new_obj = api.get_object(self.ctxt, self.model, id=obj.id) self.assertEqual(obj, new_obj) obj = new_obj api.update_object(self.ctxt, self.model, {'name': 'bar'}, id=obj.id) new_obj = api.get_object(self.ctxt, self.model, id=obj.id) self.assertEqual(obj, new_obj) obj = new_obj api.delete_object(self.ctxt, self.model, id=obj.id) new_obj = api.get_object(self.ctxt, self.model, id=obj.id) self.assertIsNone(new_obj) # delete_object raises an exception on missing object self.assertRaises(n_exc.ObjectNotFound, api.delete_object, self.ctxt, self.model, id=obj.id) # but delete_objects does not not api.delete_objects(self.ctxt, self.model, id=obj.id)
def update_object(cls, context, values, validate_filters=True, **kwargs): """Update an object that match filtering criteria from DB. :param context: :param values: multiple keys to update in matching objects :param validate_filters: Raises an error in case of passing an unknown filter :param kwargs: multiple keys defined by key=value pairs :return: The updated version of the object """ if validate_filters: cls.validate_filters(**kwargs) # if we have standard attributes, we will need to fetch records to # update revision numbers db_obj = None if cls.has_standard_attributes(): return super(NeutronDbObject, cls).update_object( context, values, validate_filters=False, **kwargs) else: with cls.db_context_writer(context): db_obj = obj_db_api.update_object( cls, context, cls.modify_fields_to_db(values), **cls.modify_fields_to_db(kwargs)) return cls._load_object(context, db_obj)
def update_object(cls, context, values, validate_filters=True, **kwargs): """ Update an object that match filtering criteria from DB. :param context: :param values: multiple keys to update in matching objects :param validate_filters: Raises an error in case of passing an unknown filter :param kwargs: multiple keys defined by key=value pairs :return: The updated version of the object """ if validate_filters: cls.validate_filters(**kwargs) # if we have standard attributes, we will need to fetch records to # update revision numbers db_obj = None if cls.has_standard_attributes(): return super(NeutronDbObject, cls).update_object( context, values, validate_filters=False, **kwargs) else: with cls.db_context_writer(context): db_obj = obj_db_api.update_object( cls, context, cls.modify_fields_to_db(values), **cls.modify_fields_to_db(kwargs)) return cls._load_object(context, db_obj)
def update(self): updates = self._get_changed_persistent_fields() updates = self._validate_changed_fields(updates) with self.db_context_writer(self.obj_context): db_obj = obj_db_api.update_object( self, self.obj_context, self.modify_fields_to_db(updates), **self.modify_fields_to_db(self._get_composite_keys())) self.from_db_object(db_obj)
def update(self): updates = self._get_changed_persistent_fields() updates = self._validate_changed_fields(updates) if updates: db_obj = obj_db_api.update_object(self._context, self.db_model, updates, **self._get_composite_keys()) self.from_db_object(self, db_obj)
def update(self): updates = self._get_changed_persistent_fields() updates = self._validate_changed_fields(updates) with db_api.autonested_transaction(self.obj_context.session): db_obj = obj_db_api.update_object( self.obj_context, self.db_model, self.modify_fields_to_db(updates), **self.modify_fields_to_db(self._get_composite_keys())) self.from_db_object(db_obj)
def update(self): updates = self._get_changed_persistent_fields() updates = self._validate_changed_fields(updates) with db_api.autonested_transaction(self.obj_context.session): db_obj = obj_db_api.update_object( self.obj_context, self.db_model, self.modify_fields_to_db(updates), **self.modify_fields_to_db( self._get_composite_keys())) self.from_db_object(db_obj)
def update(self): updates = self._get_changed_persistent_fields() updates = self._validate_changed_fields(updates) with self.db_context_writer(self.obj_context): db_obj = obj_db_api.update_object( self, self.obj_context, self.modify_fields_to_db(updates), **self.modify_fields_to_db( self._get_composite_keys())) self.from_db_object(db_obj)