add-data: warn and exit if database is frozen

This commit is contained in:
marc tobias 2024-08-05 14:25:46 +02:00
parent a4d7cdd2ad
commit f0390cfe85
4 changed files with 40 additions and 27 deletions

View File

@ -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

View File

@ -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.

View File

@ -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))

View File

@ -36,30 +36,6 @@ 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
@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 mock_run_legacy.called == 1
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')
assert cli_call('add-data', '--tiger-data', 'somewhere') == 0
assert mock.called == 1
def test_cli_serve_php(cli_call, mock_func_factory):
func = mock_func_factory(nominatim_db.cli, 'run_php_server')
@ -73,11 +49,37 @@ def test_cli_serve_php(cli_call, mock_func_factory):
class TestCliWithDb:
@pytest.fixture(autouse=True)
def setup_cli_call(self, cli_call, temp_db, cli_tokenizer_mock):
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')
@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
@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 mock_run_legacy.called == 1
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')
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')
mock_flatnode = mock_func_factory(nominatim_db.tools.freeze, 'drop_flatnode_file')