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.
This commit is contained in:
Aman Agrawal 2019-06-20 21:57:09 +05:30 committed by Tim Abbott
parent 80a3651cf3
commit b2b49089fd
9 changed files with 27 additions and 56 deletions

View File

@ -49,17 +49,12 @@ sys.path.insert(0, ZULIP_PATH)
from tools.lib import sanity_check from tools.lib import sanity_check
sanity_check.check_venv(__file__) 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 tools.lib.test_server import test_server_running
from typing import Iterable, List from typing import Iterable, List
if not options.force: assert_provisioning_status_ok(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)
os.chdir(ZULIP_PATH) os.chdir(ZULIP_PATH)

View File

@ -9,7 +9,7 @@ root_dir = os.path.dirname(tools_dir)
sys.path.insert(0, root_dir) sys.path.insert(0, root_dir)
from tools.lib.test_script import ( from tools.lib.test_script import (
get_provisioning_status, assert_provisioning_status_ok,
) )
def run(): def run():
@ -20,12 +20,7 @@ def run():
help='Run tests despite possible problems.') help='Run tests despite possible problems.')
options = parser.parse_args() options = parser.parse_args()
if not options.force: assert_provisioning_status_ok(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)
if __name__ == '__main__': if __name__ == '__main__':
run() run()

View File

@ -1,6 +1,7 @@
from typing import Optional, Tuple from typing import Optional, Tuple
import os import os
import sys
from distutils.version import LooseVersion from distutils.version import LooseVersion
from version import PROVISION_VERSION from version import PROVISION_VERSION
from scripts.lib.zulip_tools import get_dev_uuid_var_path 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_DOWNGRADE
return False, preamble(version) + NEED_TO_UPGRADE 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)

View File

@ -44,17 +44,12 @@ def run():
from tools.linter_lib.pep8 import check_pep8 from tools.linter_lib.pep8 import check_pep8
from tools.lib.test_script import ( from tools.lib.test_script import (
get_provisioning_status, assert_provisioning_status_ok,
) )
os.chdir(root_dir) os.chdir(root_dir)
if not args.force: assert_provisioning_status_ok(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)
backend_file_types = ['py', 'sh', 'pp', 'json', 'md', 'txt', 'text', 'yaml', 'rst'] backend_file_types = ['py', 'sh', 'pp', 'json', 'md', 'txt', 'text', 'yaml', 'rst']
frontend_file_types = ['js', 'ts', 'css', 'scss', 'handlebars', 'html'] frontend_file_types = ['js', 'ts', 'css', 'scss', 'handlebars', 'html']

View File

@ -44,7 +44,7 @@ to this file.
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__)) TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.dirname(TOOLS_DIR)) sys.path.insert(0, os.path.dirname(TOOLS_DIR))
from tools.lib.test_script import ( from tools.lib.test_script import (
get_provisioning_status, assert_provisioning_status_ok,
) )
parser.add_argument('--test', parser.add_argument('--test',
@ -67,12 +67,7 @@ parser.add_argument('--enable-tornado-logging',
default=False, help='Enable access logs from tornado proxy server.') default=False, help='Enable access logs from tornado proxy server.')
options = parser.parse_args() options = parser.parse_args()
if not options.force: assert_provisioning_status_ok(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)
if options.interface is None: if options.interface is None:
user_id = os.getuid() user_id = os.getuid()

View File

@ -13,7 +13,7 @@ TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
os.chdir(os.path.dirname(TOOLS_DIR)) os.chdir(os.path.dirname(TOOLS_DIR))
sys.path.append(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 = """ exclude = """
stubs/ stubs/
@ -38,12 +38,7 @@ parser.add_argument('--force', action="store_true",
help="run tests despite possible provisioning problems") help="run tests despite possible provisioning problems")
args = parser.parse_args() args = parser.parse_args()
if not args.force: assert_provisioning_status_ok(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)
command_name = "mypy" if (args.no_daemon or args.version) else "dmypy" command_name = "mypy" if (args.no_daemon or args.version) else "dmypy"

View File

@ -14,7 +14,7 @@ os.chdir(ZULIP_PATH)
from zulip import Client 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 tools.lib.test_server import test_server_running
from zerver.lib.api_test_helpers import test_the_api, test_invalid_api_key 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.') default=False, help='Run tests despite possible provisioning problems.')
options = parser.parse_args() options = parser.parse_args()
if not options.force: assert_provisioning_status_ok(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)
with test_server_running(force=options.force, external_host='zulipdev.com:9981'): with test_server_running(force=options.force, external_host='zulipdev.com:9981'):
print("Running API tests...") print("Running API tests...")

View File

@ -196,7 +196,7 @@ def main() -> None:
from zerver.lib.test_fixtures import update_test_databases_if_required from zerver.lib.test_fixtures import update_test_databases_if_required
from tools.lib.test_script import ( from tools.lib.test_script import (
get_provisioning_status, assert_provisioning_status_ok,
) )
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
@ -351,12 +351,7 @@ def main() -> None:
if full_suite and include_webhooks: if full_suite and include_webhooks:
suites.append("zerver.webhooks") suites.append("zerver.webhooks")
if not options.force: assert_provisioning_status_ok(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)
if options.coverage: if options.coverage:
import coverage import coverage

View File

@ -105,14 +105,9 @@ parser.add_argument('--force', dest='force',
parser.add_argument('args', nargs=argparse.REMAINDER) parser.add_argument('args', nargs=argparse.REMAINDER)
options = parser.parse_args() 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: assert_provisioning_status_ok(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)
os.environ['NODE_PATH'] = 'static' os.environ['NODE_PATH'] = 'static'
os.environ['TZ'] = 'UTC' os.environ['TZ'] = 'UTC'