test_fixtures: Move test_db_status state under UUID_VAR_PATH.

This should mean that maintaining two Zulip development environments
using the same Git checkout no longer has caching problems keeping
track of the migration status.
This commit is contained in:
Tim Abbott 2017-10-17 19:23:06 -07:00
parent b7c3b4df0c
commit 3983ebce9a
5 changed files with 22 additions and 7 deletions

View File

@ -13,7 +13,7 @@ sh "$(dirname "$0")/../scripts/setup/flush-memcached"
./manage.py purge_queue --all ./manage.py purge_queue --all
./manage.py migrate --noinput ./manage.py migrate --noinput
./manage.py get_migration_status --settings=zproject.settings --output="var/migration_status_dev" ./manage.py get_migration_status --settings=zproject.settings --output="migration_status_dev"
./manage.py createcachetable third_party_api_results ./manage.py createcachetable third_party_api_results
./manage.py populate_db -n100 --threads=1 ./manage.py populate_db -n100 --threads=1
# Ensure that the local user's API key is synced from ~/.zuliprc # Ensure that the local user's API key is synced from ~/.zuliprc

View File

@ -328,8 +328,9 @@ def main(options):
else: else:
print("RabbitMQ is already configured.") print("RabbitMQ is already configured.")
migration_status_path = os.path.join(UUID_VAR_PATH, "migration_status_dev")
if options.is_force or not is_template_database_current( if options.is_force or not is_template_database_current(
migration_status="var/migration_status_dev", migration_status=migration_status_path,
settings="zproject.settings", settings="zproject.settings",
database_name="zulip", database_name="zulip",
): ):

View File

@ -23,7 +23,7 @@ sh "$(dirname "$0")/../../scripts/setup/flush-memcached"
./manage.py migrate --noinput --settings=zproject.test_settings ./manage.py migrate --noinput --settings=zproject.test_settings
./manage.py get_migration_status --settings=zproject.test_settings \ ./manage.py get_migration_status --settings=zproject.test_settings \
--output="var/migration_status_test" --output="migration_status_test"
# This next line can be simplified to "-n0" once we fix our app (and tests) with 0 messages. # This next line can be simplified to "-n0" once we fix our app (and tests) with 0 messages.
./manage.py populate_db --settings=zproject.test_settings --test-suite -n30 \ ./manage.py populate_db --settings=zproject.test_settings --test-suite -n30 \

View File

@ -2,6 +2,7 @@
import os import os
import re import re
import hashlib import hashlib
import sys
from typing import Any, List, Optional, Text from typing import Any, List, Optional, Text
from importlib import import_module from importlib import import_module
from six.moves import cStringIO as StringIO from six.moves import cStringIO as StringIO
@ -9,9 +10,14 @@ from six.moves import cStringIO as StringIO
from django.db import connections, DEFAULT_DB_ALIAS from django.db import connections, DEFAULT_DB_ALIAS
from django.db.utils import OperationalError from django.db.utils import OperationalError
from django.apps import apps from django.apps import apps
from django.conf import settings
from django.core.management import call_command from django.core.management import call_command
from django.utils.module_loading import module_has_submodule from django.utils.module_loading import module_has_submodule
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
from scripts.lib.zulip_tools import get_dev_uuid_var_path
UUID_VAR_DIR = get_dev_uuid_var_path()
FILENAME_SPLITTER = re.compile('[\W\-_]') FILENAME_SPLITTER = re.compile('[\W\-_]')
def database_exists(database_name, **options): def database_exists(database_name, **options):
@ -94,9 +100,9 @@ def _check_hash(target_hash_file, status_dir):
def is_template_database_current( def is_template_database_current(
database_name='zulip_test_template', database_name='zulip_test_template',
migration_status='var/migration_status_test', migration_status=None,
settings='zproject.test_settings', settings='zproject.test_settings',
status_dir='var/test_db_status', status_dir=None,
check_files=None): check_files=None):
# type: (str, str, str, str, Optional[List[str]]) -> bool # type: (str, str, str, str, Optional[List[str]]) -> bool
# Using str type for check_files because re.split doesn't accept unicode # Using str type for check_files because re.split doesn't accept unicode
@ -107,6 +113,10 @@ def is_template_database_current(
'tools/setup/postgres-init-test-db', 'tools/setup/postgres-init-test-db',
'tools/setup/postgres-init-dev-db', 'tools/setup/postgres-init-dev-db',
] ]
if status_dir is None:
status_dir = os.path.join(UUID_VAR_DIR, 'test_db_status')
if migration_status is None:
migration_status = os.path.join(UUID_VAR_DIR, 'migration_status_test')
if not os.path.exists(status_dir): if not os.path.exists(status_dir):
os.mkdir(status_dir) os.mkdir(status_dir)

View File

@ -1,11 +1,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import argparse import argparse
import os
from typing import Any from typing import Any
from django.conf import settings
from django.db import DEFAULT_DB_ALIAS from django.db import DEFAULT_DB_ALIAS
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from zerver.lib.test_fixtures import get_migration_status from zerver.lib.test_fixtures import get_migration_status
from scripts.lib.zulip_tools import get_dev_uuid_var_path
class Command(BaseCommand): class Command(BaseCommand):
help = "Get status of migrations." help = "Get status of migrations."
@ -26,7 +28,9 @@ class Command(BaseCommand):
# type: (*Any, **Any) -> None # type: (*Any, **Any) -> None
result = get_migration_status(**options) result = get_migration_status(**options)
if options['output'] is not None: if options['output'] is not None:
with open(options['output'], 'w') as f: uuid_var_path = get_dev_uuid_var_path()
path = os.path.join(uuid_var_path, options['output'])
with open(path, 'w') as f:
f.write(result) f.write(result)
else: else:
self.stdout.write(result) self.stdout.write(result)