Merge "[sqlalchemy-20] Use sqlalchemy.orm.DeclarativeBase"
This commit is contained in:
@@ -110,4 +110,10 @@ class NeutronBaseV2(_NeutronBase):
|
|||||||
return cls.__name__.lower() + 's'
|
return cls.__name__.lower() + 's'
|
||||||
|
|
||||||
|
|
||||||
BASEV2 = declarative.declarative_base(cls=NeutronBaseV2)
|
try:
|
||||||
|
# SQLAlchemy 2.0
|
||||||
|
class BASEV2(orm.DeclarativeBase, NeutronBaseV2):
|
||||||
|
pass
|
||||||
|
except AttributeError:
|
||||||
|
# SQLAlchemy < 2.0
|
||||||
|
BASEV2 = declarative.declarative_base(cls=NeutronBaseV2)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import gc
|
import gc
|
||||||
|
|
||||||
from sqlalchemy.ext import declarative
|
from sqlalchemy.ext import declarative
|
||||||
|
from sqlalchemy import orm
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
from neutron_lib.db import standard_attr
|
from neutron_lib.db import standard_attr
|
||||||
@@ -29,8 +30,17 @@ class StandardAttrTestCase(base.BaseTestCase):
|
|||||||
def _make_decl_base(self):
|
def _make_decl_base(self):
|
||||||
# construct a new base so we don't interfere with the main
|
# construct a new base so we don't interfere with the main
|
||||||
# base used in the sql test fixtures
|
# base used in the sql test fixtures
|
||||||
return declarative.declarative_base(
|
try:
|
||||||
cls=standard_attr.model_base.NeutronBaseV2)
|
# SQLAlchemy 2.0
|
||||||
|
class BaseV2(orm.DeclarativeBase,
|
||||||
|
standard_attr.model_base.NeutronBaseV2):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return BaseV2
|
||||||
|
except AttributeError:
|
||||||
|
# SQLAlchemy < 2.0
|
||||||
|
return declarative.declarative_base(
|
||||||
|
cls=standard_attr.model_base.NeutronBaseV2)
|
||||||
|
|
||||||
def test_standard_attr_resource_model_map(self):
|
def test_standard_attr_resource_model_map(self):
|
||||||
rs_map = standard_attr.get_standard_attr_resource_model_map()
|
rs_map = standard_attr.get_standard_attr_resource_model_map()
|
||||||
|
|||||||
@@ -26,14 +26,23 @@ from neutron_lib import exceptions as n_exc
|
|||||||
from neutron_lib.tests import _base as base
|
from neutron_lib.tests import _base as base
|
||||||
|
|
||||||
|
|
||||||
class FakePort(declarative.declarative_base(cls=models.ModelBase)):
|
try:
|
||||||
|
# SQLAlchemy 2.0
|
||||||
|
class ModelBaseV2(orm.DeclarativeBase, models.ModelBase):
|
||||||
|
pass
|
||||||
|
except AttributeError:
|
||||||
|
# SQLAlchemy < 2.0
|
||||||
|
ModelBaseV2 = declarative.declarative_base(cls=models.ModelBase)
|
||||||
|
|
||||||
|
|
||||||
|
class FakePort(ModelBaseV2):
|
||||||
__tablename__ = 'fakeports'
|
__tablename__ = 'fakeports'
|
||||||
port_id = sa.Column(sa.String(36), primary_key=True)
|
port_id = sa.Column(sa.String(36), primary_key=True)
|
||||||
name = sa.Column(sa.String(64))
|
name = sa.Column(sa.String(64))
|
||||||
status = sa.Column(sa.String(16), nullable=False)
|
status = sa.Column(sa.String(16), nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class FakeRouter(declarative.declarative_base(cls=models.ModelBase)):
|
class FakeRouter(ModelBaseV2):
|
||||||
__tablename__ = 'fakerouters'
|
__tablename__ = 'fakerouters'
|
||||||
router_id = sa.Column(sa.String(36), primary_key=True)
|
router_id = sa.Column(sa.String(36), primary_key=True)
|
||||||
gw_port_id = sa.Column(sa.String(36), sa.ForeignKey(FakePort.port_id))
|
gw_port_id = sa.Column(sa.String(36), sa.ForeignKey(FakePort.port_id))
|
||||||
|
|||||||
Reference in New Issue
Block a user