From 149dbae7a35b84eb94550d427509d8a890eeb160 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 27 Apr 2016 19:21:46 +0530 Subject: [PATCH] [test] test_setup_production_v6 --- .travis.yml | 2 +- bench/app.py | 5 +- bench/config/procfile.py | 2 +- bench/config/supervisor.py | 2 +- bench/tests/test_init.py | 8 +-- bench/tests/test_setup_production.py | 96 ++++++++++++++++++++-------- 6 files changed, 80 insertions(+), 35 deletions(-) diff --git a/.travis.yml b/.travis.yml index 83434ef8..486021e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/bench/app.py b/bench/app.py index 550e8a3a..cc5177a1 100644 --- a/bench/app.py +++ b/bench/app.py @@ -1,5 +1,5 @@ import os -from .utils import (exec_cmd, get_frappe, check_git_for_shallow_clone, build_assets, +from .utils import (exec_cmd, get_frappe, check_git_for_shallow_clone, build_assets, restart_supervisor_processes, get_cmd_output, run_frappe_cmd) from .config.common_site_config import get_config @@ -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) diff --git a/bench/config/procfile.py b/bench/config/procfile.py index 726cc152..1f1553dc 100644 --- a/bench/config/procfile.py +++ b/bench/config/procfile.py @@ -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')) diff --git a/bench/config/supervisor.py b/bench/config/supervisor.py index 30eaadff..0fb12045 100644 --- a/bench/config/supervisor.py +++ b/bench/config/supervisor.py @@ -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'), diff --git a/bench/tests/test_init.py b/bench/tests/test_init.py index 0416b08c..867fd39a 100644 --- a/bench/tests/test_init.py +++ b/bench/tests/test_init.py @@ -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') diff --git a/bench/tests/test_setup_production.py b/bench/tests/test_setup_production.py index 3c38b6b3..836510f9 100644 --- a/bench/tests/test_setup_production.py +++ b/bench/tests/test_setup_production.py @@ -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,44 +83,69 @@ class TestSetupProduction(test_init.TestBenchInit): with open(conf_src, "r") as f: f = f.read().decode("utf-8") - for key in ( - "program:{bench_name}-frappe-web", + tests = [ + "program:{bench_name}-frappe-web", + "program:{bench_name}-redis-cache", + "program:{bench_name}-redis-queue", + "program:{bench_name}-redis-socketio", + "program:{bench_name}-node-socketio", + "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", - "program:{bench_name}-frappe-schedule", - "program:{bench_name}-redis-cache", - "program:{bench_name}-redis-queue", - "program:{bench_name}-redis-socketio", - "program:{bench_name}-node-socketio", - "group:{bench_name}-web", - "group:{bench_name}-workers", - "group:{bench_name}-redis" - ): + "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 ( - "{bench_name}-web:{bench_name}-frappe-web[\s]+RUNNING", - "{bench_name}-web:{bench_name}-node-socketio[\s]+RUNNING", + tests = [ + "{bench_name}-web:{bench_name}-frappe-web[\s]+RUNNING", + "{bench_name}-web:{bench_name}-node-socketio[\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" + ] + + 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", - "{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}-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)