mirror of
https://github.com/frappe/bench.git
synced 2024-11-11 15:51:03 +00:00
[test] test_setup_production_v6
This commit is contained in:
parent
6155e6aaa0
commit
149dbae7a3
@ -17,5 +17,5 @@ script:
|
||||
- cd ~
|
||||
- sudo pip install --upgrade pip
|
||||
- sudo pip install -e bench-repo
|
||||
# - sudo python -m unittest bench.tests.test_setup_production.TestSetupProduction.test_new_site
|
||||
# - sudo python -m unittest bench.tests.test_setup_production.TestSetupProduction.test_setup_production_v6
|
||||
- sudo python -m unittest -v bench.tests.test_setup_production
|
||||
|
@ -46,6 +46,7 @@ def get_app(app, git_url, branch=None, bench='.', build_asset_files=True, verbos
|
||||
logger.info('getting app {}'.format(app))
|
||||
shallow_clone = '--depth 1' if check_git_for_shallow_clone() else ''
|
||||
branch = '--branch {branch}'.format(branch=branch) if branch else ''
|
||||
|
||||
exec_cmd("git clone {git_url} {branch} {shallow_clone} --origin upstream {app}".format(
|
||||
git_url=git_url,
|
||||
app=app,
|
||||
@ -110,7 +111,7 @@ def get_current_frappe_version(bench='.'):
|
||||
try:
|
||||
return get_major_version(get_current_version('frappe', bench=bench))
|
||||
except IOError:
|
||||
return ''
|
||||
return 0
|
||||
|
||||
def get_current_branch(app, bench='.'):
|
||||
repo_dir = get_repo_dir(app, bench=bench)
|
||||
|
@ -12,7 +12,7 @@ def setup_procfile(bench_path, force=False):
|
||||
|
||||
procfile = bench.env.get_template('Procfile').render(
|
||||
node=find_executable("node") or find_executable("nodejs"),
|
||||
frappe_version=get_current_frappe_version(),
|
||||
frappe_version=get_current_frappe_version(bench_path),
|
||||
frappe_branch=get_current_branch('frappe', bench_path),
|
||||
webserver_port=config.get('webserver_port'))
|
||||
|
||||
|
@ -18,7 +18,7 @@ def generate_supervisor_config(bench_path, user=None, force=False):
|
||||
"bench_dir": bench_dir,
|
||||
"sites_dir": os.path.join(bench_dir, 'sites'),
|
||||
"user": user,
|
||||
"frappe_version": get_current_frappe_version(),
|
||||
"frappe_version": get_current_frappe_version(bench_path),
|
||||
"frappe_branch": get_current_branch('frappe', bench_path),
|
||||
"http_timeout": config.get("http_timeout", 120),
|
||||
"redis_server": find_executable('redis-server'),
|
||||
|
@ -20,8 +20,8 @@ class TestBenchInit(unittest.TestCase):
|
||||
if os.path.exists(bench_path):
|
||||
shutil.rmtree(bench_path, ignore_errors=True)
|
||||
|
||||
def test_init(self, bench_name="test-bench"):
|
||||
self.init_bench(bench_name)
|
||||
def test_init(self, bench_name="test-bench", **kwargs):
|
||||
self.init_bench(bench_name, **kwargs)
|
||||
|
||||
self.assert_folders(bench_name)
|
||||
|
||||
@ -107,9 +107,9 @@ class TestBenchInit(unittest.TestCase):
|
||||
out = subprocess.check_output(["bench", "--site", site_name, "list-apps"], cwd=bench_path)
|
||||
self.assertTrue("erpnext" in out)
|
||||
|
||||
def init_bench(self, bench_name):
|
||||
def init_bench(self, bench_name, **kwargs):
|
||||
self.benches.append(bench_name)
|
||||
bench.utils.init(bench_name)
|
||||
bench.utils.init(bench_name, **kwargs)
|
||||
|
||||
def test_drop_site(self):
|
||||
self.init_bench('test-bench')
|
||||
|
@ -28,6 +28,21 @@ class TestSetupProduction(test_init.TestBenchInit):
|
||||
|
||||
self.assert_nginx_process()
|
||||
|
||||
def test_setup_production_v6(self):
|
||||
bench_name = 'test-bench-v6'
|
||||
self.test_init(bench_name, frappe_branch='master')
|
||||
|
||||
user = getpass.getuser()
|
||||
|
||||
bench_path = os.path.join(os.path.abspath(self.benches_path), bench_name)
|
||||
setup_production(user, bench_path)
|
||||
|
||||
self.assert_nginx_config(bench_name)
|
||||
self.assert_nginx_process()
|
||||
|
||||
self.assert_supervisor_config(bench_name, use_rq=False)
|
||||
self.assert_supervisor_process(bench_name, use_rq=False)
|
||||
|
||||
def assert_nginx_config(self, bench_name):
|
||||
conf_src = os.path.join(os.path.abspath(self.benches_path), bench_name, 'config', 'nginx.conf')
|
||||
conf_dest = "/etc/nginx/conf.d/{bench_name}.conf".format(bench_name=bench_name)
|
||||
@ -48,7 +63,11 @@ class TestSetupProduction(test_init.TestBenchInit):
|
||||
):
|
||||
self.assertTrue(key.format(bench_name=bench_name) in f)
|
||||
|
||||
def assert_supervisor_config(self, bench_name):
|
||||
def assert_nginx_process(self):
|
||||
out = bench.utils.get_cmd_output("sudo nginx -t 2>&1")
|
||||
self.assertTrue("nginx: configuration file /etc/nginx/nginx.conf test is successful" in out)
|
||||
|
||||
def assert_supervisor_config(self, bench_name, use_rq=True):
|
||||
conf_src = os.path.join(os.path.abspath(self.benches_path), bench_name, 'config', 'supervisor.conf')
|
||||
|
||||
supervisor_conf_dir = get_supervisor_confdir()
|
||||
@ -64,12 +83,8 @@ class TestSetupProduction(test_init.TestBenchInit):
|
||||
with open(conf_src, "r") as f:
|
||||
f = f.read().decode("utf-8")
|
||||
|
||||
for key in (
|
||||
tests = [
|
||||
"program:{bench_name}-frappe-web",
|
||||
"program:{bench_name}-frappe-default-worker",
|
||||
"program:{bench_name}-frappe-short-worker",
|
||||
"program:{bench_name}-frappe-long-worker",
|
||||
"program:{bench_name}-frappe-schedule",
|
||||
"program:{bench_name}-redis-cache",
|
||||
"program:{bench_name}-redis-queue",
|
||||
"program:{bench_name}-redis-socketio",
|
||||
@ -77,31 +92,60 @@ class TestSetupProduction(test_init.TestBenchInit):
|
||||
"group:{bench_name}-web",
|
||||
"group:{bench_name}-workers",
|
||||
"group:{bench_name}-redis"
|
||||
):
|
||||
]
|
||||
|
||||
if use_rq:
|
||||
tests.extend([
|
||||
"program:{bench_name}-frappe-schedule",
|
||||
"program:{bench_name}-frappe-default-worker",
|
||||
"program:{bench_name}-frappe-short-worker",
|
||||
"program:{bench_name}-frappe-long-worker"
|
||||
])
|
||||
|
||||
else:
|
||||
tests.extend([
|
||||
"program:{bench_name}-frappe-workerbeat",
|
||||
"program:{bench_name}-frappe-worker",
|
||||
"program:{bench_name}-frappe-longjob-worker",
|
||||
"program:{bench_name}-frappe-async-worker"
|
||||
])
|
||||
|
||||
for key in tests:
|
||||
self.assertTrue(key.format(bench_name=bench_name) in f)
|
||||
|
||||
def assert_supervisor_process(self, bench_name):
|
||||
def assert_supervisor_process(self, bench_name, use_rq=True):
|
||||
out = bench.utils.get_cmd_output("sudo supervisorctl status")
|
||||
|
||||
if "STARTING" in out:
|
||||
time.sleep(10)
|
||||
out = bench.utils.get_cmd_output("sudo supervisorctl status")
|
||||
|
||||
for key in (
|
||||
tests = [
|
||||
"{bench_name}-web:{bench_name}-frappe-web[\s]+RUNNING",
|
||||
"{bench_name}-web:{bench_name}-node-socketio[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-default-worker-0[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-short-worker-0[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-long-worker-0[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-schedule[\s]+RUNNING",
|
||||
"{bench_name}-redis:{bench_name}-redis-cache[\s]+RUNNING",
|
||||
"{bench_name}-redis:{bench_name}-redis-queue[\s]+RUNNING",
|
||||
"{bench_name}-redis:{bench_name}-redis-socketio[\s]+RUNNING",
|
||||
):
|
||||
"{bench_name}-redis:{bench_name}-redis-socketio[\s]+RUNNING"
|
||||
]
|
||||
|
||||
if use_rq:
|
||||
tests.extend([
|
||||
"{bench_name}-workers:{bench_name}-frappe-schedule[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-default-worker-0[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-short-worker-0[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-long-worker-0[\s]+RUNNING"
|
||||
])
|
||||
|
||||
else:
|
||||
tests.extend([
|
||||
"{bench_name}-workers:{bench_name}-frappe-workerbeat[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-worker[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-longjob-worker[\s]+RUNNING",
|
||||
"{bench_name}-workers:{bench_name}-frappe-async-worker[\s]+RUNNING"
|
||||
])
|
||||
|
||||
for key in tests:
|
||||
self.assertTrue(re.search(key.format(bench_name=bench_name), out))
|
||||
|
||||
def assert_nginx_process(self):
|
||||
out = bench.utils.get_cmd_output("sudo nginx -t 2>&1")
|
||||
self.assertTrue("nginx: configuration file /etc/nginx/nginx.conf test is successful" in out)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user