py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-06-07 11:48:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import signal
|
|
|
|
import subprocess
|
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
2016-07-24 18:03:40 +02:00
|
|
|
from typing import IO
|
2016-06-07 11:48:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def start_server(logfile):
|
|
|
|
# type: (IO[str]) -> bool
|
2016-06-07 11:48:48 +02:00
|
|
|
failure = True
|
|
|
|
key = "Quit the server with CTRL-C."
|
|
|
|
for i in range(200):
|
|
|
|
time.sleep(0.5)
|
|
|
|
print("Polling run-dev...")
|
|
|
|
logfile.seek(0)
|
|
|
|
if key in logfile.read():
|
|
|
|
failure = False
|
|
|
|
break
|
|
|
|
|
|
|
|
return failure
|
|
|
|
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def test_nagios(nagios_logfile):
|
|
|
|
# type: (IO[str]) -> bool
|
2016-06-07 11:48:48 +02:00
|
|
|
ZULIP_DIR = os.path.join(TOOLS_DIR, '..')
|
|
|
|
API_DIR = os.path.join(ZULIP_DIR, 'api')
|
|
|
|
os.chdir(API_DIR)
|
2016-11-22 01:44:16 +01:00
|
|
|
subprocess.call(['./setup.py', 'install'])
|
2016-06-07 11:48:48 +02:00
|
|
|
PUPPET_DIR = os.path.join(ZULIP_DIR, 'puppet')
|
|
|
|
os.chdir(ZULIP_DIR)
|
|
|
|
my_env = os.environ.copy()
|
|
|
|
my_env['PYTHONPATH'] = ZULIP_DIR
|
|
|
|
args = [
|
|
|
|
os.path.join(PUPPET_DIR,
|
|
|
|
'zulip/files/nagios_plugins/zulip_app_frontend/check_send_receive_time'),
|
|
|
|
'--nagios',
|
2016-11-03 17:34:51 +01:00
|
|
|
'--site=http://127.0.0.1:9991',
|
2016-06-07 11:48:48 +02:00
|
|
|
]
|
2016-07-19 16:58:56 +02:00
|
|
|
result = subprocess.check_output(args, env=my_env, universal_newlines=True,
|
2016-06-07 11:48:48 +02:00
|
|
|
stderr=nagios_logfile)
|
|
|
|
|
2016-08-10 07:58:02 +02:00
|
|
|
if result.startswith("OK:"):
|
2016-06-07 11:48:48 +02:00
|
|
|
return True
|
|
|
|
|
2016-06-16 07:22:22 +02:00
|
|
|
print(result)
|
2016-06-07 11:48:48 +02:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def close_and_get_content(file_handle):
|
|
|
|
# type: (IO[str]) -> str
|
2016-06-07 11:48:48 +02:00
|
|
|
file_handle.seek(0)
|
|
|
|
content = file_handle.read()
|
|
|
|
file_handle.close()
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print("Testing development server start!")
|
|
|
|
|
|
|
|
logfile = open('/tmp/run-dev-output', 'w+')
|
|
|
|
nagios_logfile = open('/tmp/test-nagios-output', 'w+')
|
|
|
|
|
|
|
|
args = ["{}/run-dev.py".format(TOOLS_DIR)]
|
|
|
|
run_dev = subprocess.Popen(args, stdout=logfile, stderr=logfile)
|
|
|
|
|
|
|
|
try:
|
|
|
|
failure = start_server(logfile)
|
|
|
|
failure = failure or not test_nagios(nagios_logfile)
|
|
|
|
finally:
|
2016-07-24 18:03:40 +02:00
|
|
|
log = close_and_get_content(logfile)
|
|
|
|
nagios_log = close_and_get_content(nagios_logfile)
|
2016-06-07 11:48:48 +02:00
|
|
|
|
|
|
|
run_dev.send_signal(signal.SIGINT)
|
|
|
|
run_dev.wait()
|
|
|
|
|
2016-07-24 18:03:40 +02:00
|
|
|
if not failure and 'Traceback' in log + ' ' + nagios_log:
|
2016-06-07 11:48:48 +02:00
|
|
|
failure = True
|
|
|
|
|
|
|
|
if failure:
|
|
|
|
print("Development server is not working properly:")
|
2016-07-24 18:03:40 +02:00
|
|
|
print(log)
|
2016-06-07 11:48:48 +02:00
|
|
|
print("check_send_receive_time output:")
|
2016-07-24 18:03:40 +02:00
|
|
|
print(nagios_log)
|
2016-06-07 11:48:48 +02:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
|
|
|
print("Development server is working properly.")
|
|
|
|
sys.exit(0)
|