From: marc tobias Date: Mon, 5 Aug 2024 12:25:46 +0000 (+0200) Subject: add-data: warn and exit if database is frozen X-Git-Tag: deploy~4^2~1^2 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/f0390cfe85c27f74f07972541f23cd2d9ef6435d?ds=sidebyside;hp=a4d7cdd2ad7b1e087751e55a56454781aa6580bc add-data: warn and exit if database is frozen --- diff --git a/.pylintrc b/.pylintrc index d47a1693..c5915096 100644 --- a/.pylintrc +++ b/.pylintrc @@ -16,3 +16,7 @@ ignored-classes=NominatimArgs,closing disable=too-few-public-methods,duplicate-code,too-many-ancestors,bad-option-value,no-self-use,not-context-manager,use-dict-literal,chained-comparison,attribute-defined-outside-init,too-many-boolean-expressions,contextmanager-generator-missing-cleanup good-names=i,j,x,y,m,t,fd,db,cc,x1,x2,y1,y2,pt,k,v,nr + +[DESIGN] + +max-returns=7 \ No newline at end of file diff --git a/docs/admin/Advanced-Installations.md b/docs/admin/Advanced-Installations.md index 8bca2783..f8232fb2 100644 --- a/docs/admin/Advanced-Installations.md +++ b/docs/admin/Advanced-Installations.md @@ -239,6 +239,6 @@ If you are using the legacy tokenizer you might also have to switch to the PostgreSQL module that was compiled on your target machine. If you get errors that PostgreSQL cannot find or access `nominatim.so` then rerun - nominatim refresh --functions + nominatim refresh --functions on the target machine to update the the location of the module. diff --git a/src/nominatim_db/clicmd/add_data.py b/src/nominatim_db/clicmd/add_data.py index a690435c..e2058b74 100644 --- a/src/nominatim_db/clicmd/add_data.py +++ b/src/nominatim_db/clicmd/add_data.py @@ -15,6 +15,8 @@ import asyncio import psutil from .args import NominatimArgs +from ..db.connection import connect +from ..tools.freeze import is_frozen # Do not repeat documentation of subcommand classes. # pylint: disable=C0111 @@ -36,7 +38,7 @@ class UpdateAddData: The command can also be used to add external non-OSM data to the database. At the moment the only supported format is TIGER housenumber data. See the online documentation at - https://nominatim.org/release-docs/latest/admin/Import/#installing-tiger-housenumber-data-for-the-us + https://nominatim.org/release-docs/latest/customize/Tiger/ for more information. """ @@ -67,6 +69,11 @@ class UpdateAddData: def run(self, args: NominatimArgs) -> int: from ..tools import add_osm_data + with connect(args.config.get_libpq_dsn()) as conn: + if is_frozen(conn): + print('Database is marked frozen. New data can\'t be added.') + return 1 + if args.tiger_data: return asyncio.run(self._add_tiger_data(args)) diff --git a/test/python/cli/test_cli.py b/test/python/cli/test_cli.py index 6586c5ec..2831f84f 100644 --- a/test/python/cli/test_cli.py +++ b/test/python/cli/test_cli.py @@ -36,47 +36,49 @@ def test_cli_version(cli_call, capsys): captured = capsys.readouterr() assert captured.out.startswith('Nominatim version') -@pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc')]) -def test_cli_add_data_file_command(cli_call, mock_func_factory, name, oid): - mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_data_from_file') - assert cli_call('add-data', '--' + name, str(oid)) == 0 - assert mock_run_legacy.called == 1 +def test_cli_serve_php(cli_call, mock_func_factory): + func = mock_func_factory(nominatim_db.cli, 'run_php_server') + cli_call('serve', '--engine', 'php') == 0 -@pytest.mark.parametrize("name,oid", [('node', 12), ('way', 8), ('relation', 32)]) -def test_cli_add_data_object_command(cli_call, mock_func_factory, name, oid): - mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_osm_object') - assert cli_call('add-data', '--' + name, str(oid)) == 0 + assert func.called == 1 - assert mock_run_legacy.called == 1 +class TestCliWithDb: -def test_cli_add_data_tiger_data(cli_call, cli_tokenizer_mock, async_mock_func_factory): - mock = async_mock_func_factory(nominatim_db.tools.tiger_data, 'add_tiger_data') + @pytest.fixture(autouse=True) + def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock, table_factory): + self.call_nominatim = cli_call + self.tokenizer_mock = cli_tokenizer_mock + # Make sure tools.freeze.is_frozen doesn't report database as frozen. Monkeypatching failed + table_factory('place') - assert cli_call('add-data', '--tiger-data', 'somewhere') == 0 - assert mock.called == 1 + @pytest.mark.parametrize("name,oid", [('file', 'foo.osm'), ('diff', 'foo.osc')]) + def test_cli_add_data_file_command(self, cli_call, mock_func_factory, name, oid): + mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_data_from_file') + assert cli_call('add-data', '--' + name, str(oid)) == 0 + assert mock_run_legacy.called == 1 -def test_cli_serve_php(cli_call, mock_func_factory): - func = mock_func_factory(nominatim_db.cli, 'run_php_server') - cli_call('serve', '--engine', 'php') == 0 + @pytest.mark.parametrize("name,oid", [('node', 12), ('way', 8), ('relation', 32)]) + def test_cli_add_data_object_command(self, cli_call, mock_func_factory, name, oid): + mock_run_legacy = mock_func_factory(nominatim_db.tools.add_osm_data, 'add_osm_object') + assert cli_call('add-data', '--' + name, str(oid)) == 0 - assert func.called == 1 + assert mock_run_legacy.called == 1 -class TestCliWithDb: + def test_cli_add_data_tiger_data(self, cli_call, cli_tokenizer_mock, async_mock_func_factory): + mock = async_mock_func_factory(nominatim_db.tools.tiger_data, 'add_tiger_data') - @pytest.fixture(autouse=True) - def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock): - self.call_nominatim = cli_call - self.tokenizer_mock = cli_tokenizer_mock + assert cli_call('add-data', '--tiger-data', 'somewhere') == 0 + assert mock.called == 1 def test_freeze_command(self, mock_func_factory): mock_drop = mock_func_factory(nominatim_db.tools.freeze, 'drop_update_tables')