Add support for SQLAlchemy 1.4 to NFV

An internal variable was dropped in SQLALchemy 1.4.

This update attempts to use the newer syntax from 1.4
and falls back to the older syntax if the newer mechanism
cannot be used.

This will allow StarlingX to migrate to a newer version of
SQLALchemy without breaking the NFV database code.

Test Plan:
  PASS: verify coverage using SQLAlchemy 1.2 that the
 exception code is executed and unit tests pass.
  PASS: verify coverage using SQLAlchemy 1.4 that the
 exception code is not executed and unit tests pass.
  PASS: Build/Install/Bootstrap/Unlock AIO-SX to verify
 existing runtime behaviour is not impacted.

Story: 2010531
Task: 47237

Signed-off-by: Al Bailey <al.bailey@windriver.com>
Change-Id: I4063dac0b3229b4c1fdb6c5121154665ffc32903
This commit is contained in:
Al Bailey 2023-01-18 14:19:49 +00:00
parent 2debfbc72a
commit b8ff450f58
2 changed files with 26 additions and 1 deletions

View File

@ -26,6 +26,20 @@ class TestNFVDatabaseUpgrade(testcase.NFVTestCase):
super(TestNFVDatabaseUpgrade, self).tearDown()
shutil.rmtree(self.db_dir)
def test_nfv_vim_database_load_and_dump(self):
"""
Test VIM database load
"""
root_dir = os.environ['VIRTUAL_ENV']
config = dict()
config['database_dir'] = self.db_dir
database.database_initialize(config)
data_input = "%s/nfv_vim_db_stx_19.12" % root_dir
data_output = "%s/nfv_vim_db_stx_19.12.dump" % root_dir
database.database_load_data(data_input)
database.database_dump_data(data_output)
database.database_finalize()
def test_nfv_vim_database_upgrade_from_19_12(self):
"""
Test VIM database upgrades from stx 19_12

View File

@ -23,8 +23,19 @@ class AsDictMixin(object):
setattr(self, column, data[column])
def get_Base_registry():
try:
# SQLAlchemy 1.4 got rid of _decl_class_registry
# so we need to use the new way if it exists
# otherwise fail over to the old attribute
return Base.registry._class_registry
except AttributeError: # SQLAlchemy <1.4
return Base._decl_class_registry
def lookup_class_by_table(table_name):
for c in list(Base._decl_class_registry.values()):
for c in list(get_Base_registry().values()):
if hasattr(c, '__table__'):
if table_name == str(c.__table__):
return c
# TODO(abailey): add an explicit return None