b8ff450f58
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
64 lines
1.9 KiB
Python
Executable File
64 lines
1.9 KiB
Python
Executable File
#
|
|
# Copyright (c) 2016-2023 Wind River Systems, Inc.
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
from nfv_vim import database
|
|
from nfv_vim import tables
|
|
|
|
from nfv_unit_tests.tests import testcase
|
|
|
|
|
|
class TestNFVDatabaseUpgrade(testcase.NFVTestCase):
|
|
|
|
def setUp(self):
|
|
super(TestNFVDatabaseUpgrade, self).setUp()
|
|
root_dir = os.environ['VIRTUAL_ENV']
|
|
# create a directory to hold the DB, randomly named, under the tox env
|
|
self.db_dir = tempfile.mkdtemp(dir=root_dir)
|
|
|
|
def tearDown(self):
|
|
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
|
|
"""
|
|
root_dir = os.environ['VIRTUAL_ENV']
|
|
# stage some old data
|
|
devnull = open(os.devnull, 'w')
|
|
try:
|
|
vim_cmd = ("nfv-vim-manage db-load-data -d %s "
|
|
"-f %s/nfv_vim_db_stx_19.12" % (self.db_dir, root_dir))
|
|
|
|
subprocess.check_call([vim_cmd], shell=True, stderr=devnull)
|
|
except subprocess.CalledProcessError:
|
|
raise
|
|
|
|
# migrate the old data
|
|
config = dict()
|
|
config['database_dir'] = self.db_dir
|
|
database.database_initialize(config)
|
|
database.database_migrate_data()
|
|
tables.tables_initialize()
|