Page MenuHomeSoftware Heritage

Jenkins > .tox.py3-core-db-server-slow-cover.lib.python3.7.site-packages.swh.core.db.tests.test_db_utils::test_db_utils_upgrade[test.cli_new]
Failed

TEST RESULT

Run At
Feb 2 2022, 2:54 PM
Details
cli_runner = <click.testing.CliRunner object at 0x7fb745a5ab70> postgresql = <connection object at 0x7fb748b30408; dsn: 'user=postgres password=xxx dbname=tests host=127.0.0.1 port=28141 options=''', closed: 0> mock_package_sql = <function mock_package_sql.<locals>.get_sql_for_package_mock at 0x7fb745dca048> module = 'test.cli_new' datadir = '/var/lib/jenkins/workspace/DCORE/tests-on-diff@2/.tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/data' @pytest.mark.parametrize("module", ["test.cli_new"]) def test_db_utils_upgrade(cli_runner, postgresql, mock_package_sql, module, datadir): """Check swh_db_upgrade """ conninfo = craft_conninfo(postgresql) result = cli_runner.invoke(swhdb, ["init-admin", module, "--dbname", conninfo]) assert result.exit_code == 0, f"Unexpected output: {result.output}" result = cli_runner.invoke(swhdb, ["init", module, "--dbname", conninfo]) assert result.exit_code == 0, f"Unexpected output: {result.output}" > new_version = swh_db_upgrade(conninfo, module) .tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/tests/test_db_utils.py:93: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ conninfo = 'postgresql://postgres@127.0.0.1:28141/tests' modname = 'test.cli_new', to_version = 99999999 def swh_db_upgrade( conninfo: str, modname: str, to_version: Optional[int] = None ) -> int: """ Args: db_or_conninfo: A database connection, or a database connection info string sql_dir: directory path where to find upgrade sql files """ if to_version is None: to_version = 99999999 dn_module, db_version, db_flavor = get_database_info(conninfo) if db_version is None: raise ValueError("Unable to retrieve the current version of the database") sqlfiles = [ fname for fname in get_sql_for_package(modname, upgrade=True) if db_version < int(path.splitext(path.basename(fname))[0]) <= to_version ] for sqlfile in sqlfiles: new_version = int(path.splitext(path.basename(sqlfile))[0]) logger.info("Executing migration script {sqlfile}") if db_version is not None and (new_version - db_version) > 1: logger.error( f"There are missing migration steps between {db_version} and " f"{new_version}. It might be expected but it most unlikely is not. " "Will stop here." ) return db_version execute_sqlfiles([sqlfile], conninfo, db_flavor) # check if the db version has been updated by the upgrade script db_version = swh_db_version(conninfo) assert db_version is not None if db_version == new_version: # nothing to do, upgrade script did the job pass elif db_version == new_version - 1: # it has not (new style), so do it swh_set_db_version( conninfo, new_version, desc=f"Upgraded to version {new_version} using {sqlfile}", ) db_version = swh_db_version(conninfo) else: # upgrade script did it wrong logger.error( f"The upgrade script {sqlfile} did not update the dbversion table " f"consistently ({db_version} vs. expected {new_version}). " "Will stop migration here. Please check your migration scripts." ) return db_version > return new_version E UnboundLocalError: local variable 'new_version' referenced before assignment .tox/py3-core-db-server-slow-cover/lib/python3.7/site-packages/swh/core/db/db_utils.py:209: UnboundLocalError