diff options
| -rw-r--r-- | config.py | 22 | ||||
| -rw-r--r-- | snekbox.py | 10 | ||||
| -rw-r--r-- | tests/test_snekbox.py | 4 | 
3 files changed, 24 insertions, 12 deletions
| @@ -1,18 +1,26 @@  import os - +import docker +from docker.errors import NotFound +import traceback  def autodiscover():      container_names = ["rmq", "pdrmq", "snekbox_pdrmq_1"] -    try: -        import docker -        client = docker.from_env() -        for name in container_names: + +    client = docker.from_env() +    for name in container_names: +        try:              container = client.containers.get(name)              if container.status == "running":                  host = list(container.attrs.get('NetworkSettings').get('Networks').values())[0]['IPAddress']                  return host -    except Exception: -        return '127.0.0.1' +        except NotFound: +            #print(traceback.format_exc()) +            print("retrying...") +            continue +        except Exception: +            print(traceback.format_exc()) +            return '127.0.0.1' +  USERNAME = os.environ.get('RMQ_USERNAME', 'guest') @@ -3,6 +3,8 @@ import multiprocessing  import subprocess  import threading  import time +import os +import sys  from logs import log  from rmq import Rmq @@ -11,7 +13,7 @@ from rmq import Rmq  class Snekbox(object):      def __init__(self,                   nsjail_binary='nsjail', -                 python_binary='/usr/local/bin/python3.6'): +                 python_binary=os.path.dirname(sys.executable)+os.sep+'python3.6'):          self.nsjail_binary = nsjail_binary          self.python_binary = python_binary @@ -56,7 +58,9 @@ class Snekbox(object):          elif proc.returncode == 109:              output = 'timed out or memory limit exceeded'          else: +            log.debug(stderr)              output = 'unknown error' +          return output      def execute(self, body): @@ -78,8 +82,8 @@ class Snekbox(object):          exit(0)      def stopwatch(self, process): -        log.debug(f'10 second timer started for process {process.pid}') -        for _ in range(10): +        log.debug(f'3 second timer started for process {process.pid}') +        for _ in range(3):              time.sleep(1)              if not process.is_alive():                  log.debug(f'Clean exit on process {process.pid}') diff --git a/tests/test_snekbox.py b/tests/test_snekbox.py index d2f81fe..d7fa91a 100644 --- a/tests/test_snekbox.py +++ b/tests/test_snekbox.py @@ -8,9 +8,9 @@ from rmq import Rmq  r = Rmq() -python_binary = os.environ.get('PYTHONEXECUTABLE', '/usr/bin/python3.6') +#python_binary = os.environ.get('PYTHONEXECUTABLE', '/usr/bin/python3.6')  nsjail = os.sep.join([os.getcwd(), f'binaries{os.sep}nsjail2.6-ubuntu-x86_64']) -snek = Snekbox(nsjail_binary=nsjail, python_binary=python_binary) +snek = Snekbox(nsjail_binary=nsjail)  class SnekTests(unittest.TestCase): | 
