This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
203 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
[run] | ||
omit = ptero_petri/api/wsgi.py | ||
branch = True | ||
parallel = True | ||
source = ptero_petri | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,5 @@ | |
/.tox | ||
/AUTHORS | ||
/ChangeLog | ||
/logs | ||
/build | ||
/var |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
web: gunicorn ptero_petri.api.wsgi:app | ||
orchestrator: ptero orchestrator | ||
orchestrator: petri-orchestrator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,11 @@ | ||
import logging | ||
import os | ||
import psutil | ||
import signal | ||
import time | ||
|
||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
_SIGNAL_TIMEOUT = 10 | ||
def exit_process(exit_code): | ||
LOG.info('Exitting process.') | ||
|
||
|
||
def exit_process(exit_code, child_signals=[signal.SIGINT, signal.SIGTERM]): | ||
LOG.info('Exitting process: signalling children.') | ||
|
||
for signum in child_signals: | ||
_signal_child_processes(signum, timeout=_SIGNAL_TIMEOUT) | ||
|
||
_signal_child_processes(signal.SIGKILL, recursive=True, | ||
timeout=_SIGNAL_TIMEOUT) | ||
|
||
LOG.info('Children killed, exiting with code %d', exit_code) | ||
os._exit(exit_code) | ||
|
||
|
||
def _signal_child_processes(signum, recursive=False, timeout=_SIGNAL_TIMEOUT): | ||
for child in psutil.Process(os.getpid()).get_children(recursive=recursive): | ||
child.send_signal(signum) | ||
|
||
_wait_children(timeout, recursive=recursive) | ||
|
||
|
||
def _wait_children(timeout, recursive=False): | ||
final_time = time.time() + timeout | ||
for child in psutil.Process(os.getpid()).get_children(recursive=recursive): | ||
try: | ||
child.wait(max(0, final_time - time.time())) | ||
except psutil.TimeoutExpired: | ||
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
fakeredis | ||
honcho | ||
mock | ||
nose >= 1.3.0 | ||
nose-cov | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import errno | ||
import os | ||
import psutil | ||
import signal | ||
import sys | ||
import time | ||
|
||
|
||
NUM_ORCHESTRATORS = 2 | ||
|
||
|
||
instance = None | ||
|
||
|
||
def mkdir_p(path): | ||
try: | ||
os.makedirs(path) | ||
except OSError as exc: | ||
if exc.errno == errno.EEXIST and os.path.isdir(path): | ||
pass | ||
else: | ||
raise | ||
|
||
|
||
def wait_time(): | ||
if os.environ.get('TRAVIS'): | ||
return 15 | ||
else: | ||
return 3 | ||
|
||
def this_dir(): | ||
return os.path.dirname(__file__) | ||
|
||
def procfile_path(): | ||
return os.path.join(this_dir(), 'scripts', 'Procfile') | ||
|
||
def service_command_line(): | ||
return ['honcho', '-f', procfile_path(), 'start', | ||
'-c', 'orchestrator=%d' % NUM_ORCHESTRATORS] | ||
|
||
|
||
def setUp(): | ||
global instance | ||
|
||
logdir = 'var/log' | ||
mkdir_p(logdir) | ||
outlog = open(os.path.join(logdir, 'honcho.out'), 'w') | ||
errlog = open(os.path.join(logdir, 'honcho.err'), 'w') | ||
|
||
if not os.environ.get('SKIP_PROCFILE'): | ||
instance = psutil.Popen(service_command_line(), | ||
shell=False, stdout=outlog, stderr=errlog) | ||
time.sleep(wait_time()) | ||
if instance.poll() is not None: | ||
raise RuntimeError("honcho instance terminated prematurely") | ||
|
||
def signal_processes(processes, sig): | ||
signaled_someone = False | ||
for p in processes: | ||
try: | ||
p.send_signal(sig) | ||
signaled_someone = True | ||
except psutil.NoSuchProcess: | ||
pass | ||
|
||
return signaled_someone | ||
|
||
def get_descendents(): | ||
return psutil.Process(instance.pid).get_children(recursive=True) | ||
|
||
def cleanup(): | ||
descendents = get_descendents() | ||
|
||
instance.send_signal(signal.SIGINT) | ||
try: | ||
instance.wait(timeout=10) | ||
except psutil.TimeoutExpired: | ||
pass | ||
|
||
if not signal_processes(descendents, signal.SIGINT): | ||
return | ||
|
||
time.sleep(3) | ||
signal_processes(descendents, signal.SIGKILL) | ||
|
||
|
||
# NOTE If this doesn't run then honcho will be orphaned... | ||
def tearDown(): | ||
if not os.environ.get('SKIP_PROCFILE'): | ||
cleanup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.