def teardown_test_environment(self, *args: Any, **kwargs: Any) -> Any: # The test environment setup clones the zulip_test_template # database, creating databases with names: # 'zulip_test_template_N_<worker_id>', # where N is `random_id_range_start`, and `worker_id` is a # value between <1, self.parallel>. # # We need to delete those databases to avoid leaking disk # (Django is smart and calls this on SIGINT too). if self.parallel > 1: for index in range(self.parallel): destroy_test_databases(index + 1) else: destroy_test_databases() # Clean up our record of which databases this process created. filepath = os.path.join(get_dev_uuid_var_path(), TEMPLATE_DATABASE_DIR, get_database_id()) os.remove(filepath) # Clean up our test runs root directory. try: shutil.rmtree(TEST_RUN_DIR) except OSError: print("Unable to clean up the test run's directory.") return super().teardown_test_environment(*args, **kwargs)
def handle(self, *args: Any, **options: Any) -> None: result = get_migration_status(**options) if options['output'] is not None: 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) else: self.stdout.write(result)
def handle(self, *args: Any, **options: Any) -> None: result = get_migration_status(**options) if options['output'] is not None: 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) else: self.stdout.write(result)
def setup_test_environment(self, *args: Any, **kwargs: Any) -> Any: settings.DATABASES['default'][ 'NAME'] = settings.BACKEND_DATABASE_TEMPLATE # We create/destroy the test databases in run_tests to avoid # duplicate work when running in parallel mode. # Write the template database ids to a file that we can # reference for cleaning them up if they leak. filepath = os.path.join(get_dev_uuid_var_path(), TEMPLATE_DATABASE_DIR, str(random_id_range_start)) os.makedirs(os.path.dirname(filepath), exist_ok=True) with open(filepath, "w") as f: if self.parallel > 1: for index in range(self.parallel): f.write(str(random_id_range_start + (index + 1)) + "\n") else: f.write(str(random_id_range_start) + "\n") return super().setup_test_environment(*args, **kwargs)
def teardown_test_environment(self, *args: Any, **kwargs: Any) -> Any: # The test environment setup clones the zulip_test_template # database, creating databases with names: # 'zulip_test_template_<N, N + self.parallel - 1>', # where N is random_id_range_start. # # We need to delete those databases to avoid leaking disk # (Django is smart and calls this on SIGINT too). if self.parallel > 1: for index in range(self.parallel): destroy_test_databases(index + 1) else: destroy_test_databases() # Clean up our record of which databases this process created. filepath = os.path.join(get_dev_uuid_var_path(), TEMPLATE_DATABASE_DIR, str(random_id_range_start)) os.remove(filepath) return super().teardown_test_environment(*args, **kwargs)
def setup_test_environment(self, *args: Any, **kwargs: Any) -> Any: settings.DATABASES["default"]["NAME"] = settings.BACKEND_DATABASE_TEMPLATE # We create/destroy the test databases in run_tests to avoid # duplicate work when running in parallel mode. # Write the template database ids to a file that we can # reference for cleaning them up if they leak. filepath = os.path.join(get_dev_uuid_var_path(), TEMPLATE_DATABASE_DIR, get_database_id()) os.makedirs(os.path.dirname(filepath), exist_ok=True) with open(filepath, "w") as f: if self.parallel > 1: for index in range(self.parallel): f.write(get_database_id(index + 1) + "\n") else: f.write(get_database_id() + "\n") # Check if we are in serial mode to avoid unnecessarily making a directory. # We add "worker_0" in the path for consistency with parallel mode. if self.parallel == 1: initialize_worker_path(0) return super().setup_test_environment(*args, **kwargs)
sys.exit(1) # Check the RAM on the user's system, and throw an effort if <1.5GB. # This avoids users getting segfaults running `pip install` that are # generally more annoying to debug. with open("/proc/meminfo") as meminfo: ram_size = meminfo.readlines()[0].strip().split(" ")[-2] ram_gb = float(ram_size) / 1024.0 / 1024.0 if ram_gb < 1.5: print("You have insufficient RAM (%s GB) to run the Zulip development environment." % ( round(ram_gb, 2),)) print("We recommend at least 2 GB of RAM, and require at least 1.5 GB.") sys.exit(1) try: UUID_VAR_PATH = get_dev_uuid_var_path(create_if_missing=True) os.makedirs(UUID_VAR_PATH, exist_ok=True) if os.path.exists(os.path.join(VAR_DIR_PATH, 'zulip-test-symlink')): os.remove(os.path.join(VAR_DIR_PATH, 'zulip-test-symlink')) os.symlink( os.path.join(ZULIP_PATH, 'README.md'), os.path.join(VAR_DIR_PATH, 'zulip-test-symlink') ) os.remove(os.path.join(VAR_DIR_PATH, 'zulip-test-symlink')) except OSError: print(FAIL + "Error: Unable to create symlinks." "Make sure you have permission to create symbolic links." + ENDC) print("See this page for more information:") print(" https://zulip.readthedocs.io/en/latest/development/setup-vagrant.html#os-symlink-error") sys.exit(1)
import sys from typing import Any, List, Optional from importlib import import_module from io import StringIO from django.db import connections, DEFAULT_DB_ALIAS from django.db.utils import OperationalError from django.apps import apps from django.conf import settings from django.core.management import call_command 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, run UUID_VAR_DIR = get_dev_uuid_var_path() FILENAME_SPLITTER = re.compile(r'[\W\-_]') def run_db_migrations(platform: str) -> None: if platform == 'dev': migration_status_file = 'migration_status_dev' settings = 'zproject.settings' db_name = 'ZULIP_DB_NAME=zulip' elif platform == 'test': migration_status_file = 'migration_status_test' settings = 'zproject.test_settings' db_name = 'ZULIP_DB_NAME=zulip_test_template' # We shell out to `manage.py` and pass `DJANGO_SETTINGS_MODULE` on # the command line rather than just calling the migration
sys.path.append(ZULIP_PATH) from pygments import __version__ as pygments_version from scripts.lib.zulip_tools import ( ENDC, OKBLUE, get_dev_uuid_var_path, is_digest_obsolete, run, write_new_digest, ) from tools.setup.generate_zulip_bots_static_files import generate_zulip_bots_static_files from version import PROVISION_VERSION VENV_PATH = "/srv/zulip-py3-venv" UUID_VAR_PATH = get_dev_uuid_var_path() def create_var_directories() -> None: # create var/coverage, var/log, etc. var_dir = os.path.join(ZULIP_PATH, 'var') sub_dirs = [ 'coverage', 'log', 'node-coverage', 'test_uploads', 'uploads', 'xunit-test-results', ] for sub_dir in sub_dirs: path = os.path.join(var_dir, sub_dir)
def get_version_file() -> str: uuid_var_path = get_dev_uuid_var_path() return os.path.join(uuid_var_path, "provision_version")
import sys from typing import Any, List, Optional, Text from importlib import import_module from io import StringIO from django.db import connections, DEFAULT_DB_ALIAS from django.db.utils import OperationalError from django.apps import apps from django.conf import settings from django.core.management import call_command 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\-_]') def database_exists(database_name: Text, **options: Any) -> bool: db = options.get('database', DEFAULT_DB_ALIAS) try: connection = connections[db] with connection.cursor() as cursor: cursor.execute("SELECT 1 from pg_database WHERE datname='{}';".format(database_name)) return_value = bool(cursor.fetchone()) connections.close_all() return return_value except OperationalError: return False
def get_version_file(): # type: () -> str uuid_var_path = get_dev_uuid_var_path() return os.path.join(uuid_var_path, 'provision_version')
def get_version_file(): # type: () -> str uuid_var_path = get_dev_uuid_var_path() return os.path.join(uuid_var_path, 'provision_version')