From b2b49089fd3ce75f73f911a9c16fc64dd4efdcba Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Thu, 20 Jun 2019 21:57:09 +0530 Subject: [PATCH] tools: Extract get_provisioning_status check logic. Move get_provisioning_status check logic into assert_provisioning_status_ok and use it instead of duplicating the check code. --- frontend_tests/run-casper | 9 ++------- tools/check-provision | 9 ++------- tools/lib/test_script.py | 11 +++++++++++ tools/lint | 9 ++------- tools/run-dev.py | 9 ++------- tools/run-mypy | 9 ++------- tools/test-api | 9 ++------- tools/test-backend | 9 ++------- tools/test-js-with-node | 9 ++------- 9 files changed, 27 insertions(+), 56 deletions(-) diff --git a/frontend_tests/run-casper b/frontend_tests/run-casper index 20d4fec9f5..43f6044490 100755 --- a/frontend_tests/run-casper +++ b/frontend_tests/run-casper @@ -49,17 +49,12 @@ sys.path.insert(0, ZULIP_PATH) from tools.lib import sanity_check sanity_check.check_venv(__file__) -from tools.lib.test_script import get_provisioning_status +from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_server import test_server_running from typing import Iterable, List -if not options.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) +assert_provisioning_status_ok(options.force) os.chdir(ZULIP_PATH) diff --git a/tools/check-provision b/tools/check-provision index bdb3744e3d..72da67e780 100755 --- a/tools/check-provision +++ b/tools/check-provision @@ -9,7 +9,7 @@ root_dir = os.path.dirname(tools_dir) sys.path.insert(0, root_dir) from tools.lib.test_script import ( - get_provisioning_status, + assert_provisioning_status_ok, ) def run(): @@ -20,12 +20,7 @@ def run(): help='Run tests despite possible problems.') options = parser.parse_args() - if not options.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) + assert_provisioning_status_ok(options.force) if __name__ == '__main__': run() diff --git a/tools/lib/test_script.py b/tools/lib/test_script.py index 9c8c01c9b0..51139de3ac 100644 --- a/tools/lib/test_script.py +++ b/tools/lib/test_script.py @@ -1,6 +1,7 @@ from typing import Optional, Tuple import os +import sys from distutils.version import LooseVersion from version import PROVISION_VERSION from scripts.lib.zulip_tools import get_dev_uuid_var_path @@ -70,3 +71,13 @@ def get_provisioning_status(): return False, preamble(version) + NEED_TO_DOWNGRADE return False, preamble(version) + NEED_TO_UPGRADE + + +def assert_provisioning_status_ok(force): + # type: (bool) -> None + if not force: + ok, msg = get_provisioning_status() + if not ok: + print(msg) + print('If you really know what you are doing, use --force to run anyway.') + sys.exit(1) diff --git a/tools/lint b/tools/lint index 2f20e52a51..f2a6814ee8 100755 --- a/tools/lint +++ b/tools/lint @@ -44,17 +44,12 @@ def run(): from tools.linter_lib.pep8 import check_pep8 from tools.lib.test_script import ( - get_provisioning_status, + assert_provisioning_status_ok, ) os.chdir(root_dir) - if not args.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) + assert_provisioning_status_ok(args.force) backend_file_types = ['py', 'sh', 'pp', 'json', 'md', 'txt', 'text', 'yaml', 'rst'] frontend_file_types = ['js', 'ts', 'css', 'scss', 'handlebars', 'html'] diff --git a/tools/run-dev.py b/tools/run-dev.py index 026291bb6f..48364165ff 100755 --- a/tools/run-dev.py +++ b/tools/run-dev.py @@ -44,7 +44,7 @@ to this file. TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(TOOLS_DIR)) from tools.lib.test_script import ( - get_provisioning_status, + assert_provisioning_status_ok, ) parser.add_argument('--test', @@ -67,12 +67,7 @@ parser.add_argument('--enable-tornado-logging', default=False, help='Enable access logs from tornado proxy server.') options = parser.parse_args() -if not options.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) +assert_provisioning_status_ok(options.force) if options.interface is None: user_id = os.getuid() diff --git a/tools/run-mypy b/tools/run-mypy index cafb3fcb6b..1284e3f346 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -13,7 +13,7 @@ TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) os.chdir(os.path.dirname(TOOLS_DIR)) sys.path.append(os.path.dirname(TOOLS_DIR)) -from lib.test_script import get_provisioning_status +from lib.test_script import assert_provisioning_status_ok exclude = """ stubs/ @@ -38,12 +38,7 @@ parser.add_argument('--force', action="store_true", help="run tests despite possible provisioning problems") args = parser.parse_args() -if not args.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) +assert_provisioning_status_ok(args.force) command_name = "mypy" if (args.no_daemon or args.version) else "dmypy" diff --git a/tools/test-api b/tools/test-api index 14534721a4..75194dfdb9 100755 --- a/tools/test-api +++ b/tools/test-api @@ -14,7 +14,7 @@ os.chdir(ZULIP_PATH) from zulip import Client -from tools.lib.test_script import get_provisioning_status +from tools.lib.test_script import assert_provisioning_status_ok from tools.lib.test_server import test_server_running from zerver.lib.api_test_helpers import test_the_api, test_invalid_api_key @@ -31,12 +31,7 @@ parser.add_argument('--force', dest='force', default=False, help='Run tests despite possible provisioning problems.') options = parser.parse_args() -if not options.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) +assert_provisioning_status_ok(options.force) with test_server_running(force=options.force, external_host='zulipdev.com:9981'): print("Running API tests...") diff --git a/tools/test-backend b/tools/test-backend index 70d346c028..d1558c6af7 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -196,7 +196,7 @@ def main() -> None: from zerver.lib.test_fixtures import update_test_databases_if_required from tools.lib.test_script import ( - get_provisioning_status, + assert_provisioning_status_ok, ) os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings' @@ -351,12 +351,7 @@ def main() -> None: if full_suite and include_webhooks: suites.append("zerver.webhooks") - if not options.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) + assert_provisioning_status_ok(options.force) if options.coverage: import coverage diff --git a/tools/test-js-with-node b/tools/test-js-with-node index e4ac1b5522..d331c1d4c8 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -105,14 +105,9 @@ parser.add_argument('--force', dest='force', parser.add_argument('args', nargs=argparse.REMAINDER) options = parser.parse_args() -from tools.lib.test_script import get_provisioning_status +from tools.lib.test_script import assert_provisioning_status_ok -if not options.force: - ok, msg = get_provisioning_status() - if not ok: - print(msg) - print('If you really know what you are doing, use --force to run anyway.') - sys.exit(1) +assert_provisioning_status_ok(options.force) os.environ['NODE_PATH'] = 'static' os.environ['TZ'] = 'UTC'