def test_object_nullable_match_db(self): # This test is to keep nullable of every field in corresponding # db model and object match. def _check_table_matched(db_model, cls): for column in db_model.__table__.columns: # NOTE(jdg): Model and Object don't match intentionally here if (column.name in cls.fields and (column.name == 'uuid' and name == 'Service')): continue # NOTE(xyang): Skip the comparison of the colume name # group_type_id in table Group because group_type_id # is in the object Group but it is stored in a different # table in the database, not in the Group table. if (column.name in cls.fields and (column.name != 'group_type_id' and name != 'Group')): self.assertEqual( column.nullable, cls.fields[column.name].nullable, 'Column %(c)s in table %(t)s not match.' % {'c': column.name, 't': name}) classes = base.CinderObjectRegistry.obj_classes() for name, cls in classes.items(): if issubclass(cls[0], base.CinderPersistentObject): db_model = db.get_model_for_versioned_object(cls[0]) _check_table_matched(db_model, cls[0])
def registration_hook(self, cls, index): setattr(objects, cls.obj_name(), cls) # For Versioned Object Classes that have a model store the model in # a Class attribute named model try: cls.model = db.get_model_for_versioned_object(cls) except (ImportError, AttributeError): pass
def cinder_ovo_cls_init(cls): """This method is called on OVO registration and sets the DB model.""" # Persistent Versioned Objects Classes should have a DB model, and if # they don't, then we have a problem and we must raise an exception on # registration. try: cls.model = db.get_model_for_versioned_object(cls) except (ImportError, AttributeError): msg = _("Couldn't find ORM model for Persistent Versioned " "Object %s.") % cls.obj_name() raise exception.ProgrammingError(reason=msg)
def get_by_id(cls, context, id, *args, **kwargs): # To get by id we need to have a model and for the model to # have an id field if "id" not in cls.fields: msg = _("VersionedObject %s cannot retrieve object by id.") % (cls.obj_name()) raise NotImplementedError(msg) model = db.get_model_for_versioned_object(cls) orm_obj = db.get_by_id(context, model, id, *args, **kwargs) kargs = {} if hasattr(cls, "DEFAULT_EXPECTED_ATTR"): kargs = {"expected_attrs": getattr(cls, "DEFAULT_EXPECTED_ATTR")} return cls._from_db_object(context, cls(context), orm_obj, **kargs)
def get_by_id(cls, context, id, *args, **kwargs): # To get by id we need to have a model and for the model to # have an id field if 'id' not in cls.fields: msg = (_('VersionedObject %s cannot retrieve object by id.') % (cls.obj_name())) raise NotImplementedError(msg) model = db.get_model_for_versioned_object(cls) orm_obj = db.get_by_id(context, model, id, *args, **kwargs) expected_attrs = cls._get_expected_attrs(context) kargs = {} if expected_attrs: kargs = {'expected_attrs': expected_attrs} return cls._from_db_object(context, cls(context), orm_obj, **kargs)
def test_object_nullable_match_db(self): # This test is to keep nullable of every field in corresponding # db model and object match. def _check_table_matched(db_model, cls): for column in db_model.__table__.columns: if column.name in cls.fields: self.assertEqual( column.nullable, cls.fields[column.name].nullable, 'Column %(c)s in table %(t)s not match.' % {'c': column.name, 't': name}) classes = base.CinderObjectRegistry.obj_classes() for name, cls in classes.items(): if issubclass(cls[0], base.CinderPersistentObject): db_model = db.get_model_for_versioned_object(cls[0]) _check_table_matched(db_model, cls[0])
def test_object_nullable_match_db(self): # This test is to keep nullable of every field in corresponding # db model and object match. def _check_table_matched(db_model, cls): for column in db_model.__table__.columns: # NOTE(xyang): Skip the comparison of the colume name # group_type_id in table Group because group_type_id # is in the object Group but it is stored in a different # table in the database, not in the Group table. if (column.name in cls.fields and (column.name != 'group_type_id' and name != 'Group')): self.assertEqual( column.nullable, cls.fields[column.name].nullable, 'Column %(c)s in table %(t)s not match.' % { 'c': column.name, 't': name }) classes = base.CinderObjectRegistry.obj_classes() for name, cls in classes.items(): if issubclass(cls[0], base.CinderPersistentObject): db_model = db.get_model_for_versioned_object(cls[0]) _check_table_matched(db_model, cls[0])
def exists(cls, context, id_): model = db.get_model_for_versioned_object(cls) return db.resource_exists(context, model, id_)