provision: Early-exit in template_database_status.

This is a pure refactor, and we just early-exit
in case the datbase doesn't exist (knowing that
that can be a bit of a lie now--see the comment
I added.)
This commit is contained in:
Steve Howell 2020-04-19 19:24:38 +00:00 committed by Tim Abbott
parent 4018dcb8e7
commit 33cbb4f688
1 changed files with 38 additions and 30 deletions

View File

@ -224,7 +224,17 @@ def template_database_status(database_type: str) -> str:
if not os.path.exists(status_dir):
os.mkdir(status_dir)
if database_exists(database.database_name):
if not database_exists(database.database_name):
# TODO: It's possible that `database_exists` will
# return `False` even though the database
# exists, but we just have the wrong password,
# probably due to changing the secrets file.
#
# The only problem this causes is that we waste
# some time rebuilding the whole database, but
# it's better to err on that side, generally.
return 'needs_rebuild'
# To ensure Python evaluates all the hash tests (and thus creates the
# hash files about the current state), we evaluate them in a
# list and then process the result
@ -257,8 +267,6 @@ def template_database_status(database_type: str) -> str:
return 'current'
return 'needs_rebuild'
def destroy_leaked_test_databases(expiry_time: int = 60 * 60) -> int:
"""The logic in zerver/lib/test_runner.py tries to delete all the
temporary test databases generated by test-backend threads, but it