3 Commits

Author SHA1 Message Date
18d3cff772 Update WSGI docs 2013-07-10 14:16:35 -04:00
a7b9656916 Remove parameters from status output 2013-07-10 11:35:17 -04:00
2e9ec63675 Don't catch SystemExit from a subprocess 2013-07-09 13:15:27 -04:00
4 changed files with 21 additions and 41 deletions

View File

@@ -21,13 +21,13 @@ arbitrary commands.
SSLEngine On SSLEngine On
WSGIScriptAlias /nilmrun /home/nilm/nilmrun.wsgi WSGIScriptAlias /nilmrun /home/nilm/nilmrun.wsgi
WSGIApplicationGroup nilmrun-appgroup
WSGIProcessGroup nilmrun-procgroup WSGIProcessGroup nilmrun-procgroup
WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilm group=nilm WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilm group=nilm
# Access control example:
<Location /nilmrun> <Location /nilmrun>
WSGIApplicationGroup nilmrun-appgroup
SSLRequireSSL SSLRequireSSL
# Access control example:
Order deny,allow Order deny,allow
Deny from all Deny from all
Allow from 1.2.3.4 Allow from 1.2.3.4

View File

@@ -40,7 +40,6 @@ class LogReceiver(object):
class Process(object): class Process(object):
"""Spawn and manage a process that calls a Python function""" """Spawn and manage a process that calls a Python function"""
def __init__(self, name, function, parameters): def __init__(self, name, function, parameters):
self.parameters = parameters
self.start_time = None self.start_time = None
self.name = name self.name = name
@@ -173,7 +172,7 @@ def _exec_user_code(codeargs): # pragma: no cover (runs in subprocess)
codeobj = compile(code, '<user-code>', 'exec', codeobj = compile(code, '<user-code>', 'exec',
flags = 0, dont_inherit = 1) flags = 0, dont_inherit = 1)
exec(codeobj, module.__dict__, {}) exec(codeobj, module.__dict__, {})
except: except Exception:
try: try:
# Pull out the exception # Pull out the exception
info = sys.exc_info() info = sys.exc_info()

View File

@@ -68,7 +68,6 @@ class AppProcess(object):
"exitcode": self.manager[pid].exitcode, "exitcode": self.manager[pid].exitcode,
"name": self.manager[pid].name, "name": self.manager[pid].name,
"start_time": self.manager[pid].start_time, "start_time": self.manager[pid].start_time,
"parameters": self.manager[pid].parameters,
"log": self.manager[pid].log, "log": self.manager[pid].log,
} }

View File

@@ -104,8 +104,7 @@ class TestClient(object):
# Verify that status looks OK # Verify that status looks OK
status = client.get("/process/status", { "pid": pid, "clear": True }) status = client.get("/process/status", { "pid": pid, "clear": True })
for x in [ "pid", "alive", "exitcode", "name", for x in [ "pid", "alive", "exitcode", "name", "start_time", "log" ]:
"start_time", "parameters", "log" ]:
in_(x, status) in_(x, status)
in_("dummy 0\ndummy 1\ndummy 2\ndummy 3\n", status["log"]) in_("dummy 0\ndummy 1\ndummy 2\ndummy 3\n", status["log"])
eq_(status["alive"], True) eq_(status["alive"], True)
@@ -165,19 +164,11 @@ class TestClient(object):
eq_(status["alive"], False) eq_(status["alive"], False)
ne_(status["exitcode"], 0) ne_(status["exitcode"], 0)
@unittest.skip("trainola moving to nilmtools")
def test_client_05_trainola_simple(self):
client = HTTPClient(baseurl = testurl, post_json = True)
pid = client.post("/run/trainola", { "data": {} })
status = self.wait_end(client, pid, remove = False)
ne_(status["exitcode"], 0)
status = client.post("/process/remove", { "pid": pid })
@unittest.skip("needs a running nilmdb; trainola moved to nilmtools") @unittest.skip("needs a running nilmdb; trainola moved to nilmtools")
def test_client_06_trainola(self): def test_client_05_trainola(self):
client = HTTPClient(baseurl = testurl, post_json = True) client = HTTPClient(baseurl = testurl, post_json = True)
data = { "url": "http://bucket.mit.edu/nilmdb", data = { "url": "http://bucket.mit.edu/nilmdb",
"dest_stream": "/sharon/prep-a-matches",
"stream": "/sharon/prep-a", "stream": "/sharon/prep-a",
"start": 1366111383280463, "start": 1366111383280463,
"end": 1366126163457797, "end": 1366126163457797,
@@ -190,6 +181,7 @@ class TestClient(object):
"stream": "/sharon/prep-a", "stream": "/sharon/prep-a",
"start": 1366260494269078, "start": 1366260494269078,
"end": 1366260608185031, "end": 1366260608185031,
"dest_column": 0,
"columns": [ { "name": "P1", "index": 0 }, "columns": [ { "name": "P1", "index": 0 },
{ "name": "Q1", "index": 1 } { "name": "Q1", "index": 1 }
] ]
@@ -199,37 +191,26 @@ class TestClient(object):
"stream": "/sharon/prep-a", "stream": "/sharon/prep-a",
"start": 1366260864215764, "start": 1366260864215764,
"end": 1366260870882998, "end": 1366260870882998,
"dest_column": 1,
"columns": [ { "name": "P1", "index": 0 }, "columns": [ { "name": "P1", "index": 0 },
{ "name": "Q1", "index": 1 } { "name": "Q1", "index": 1 }
] ]
} }
] ]
} }
pid = client.post("/run/code", { "code": "import nilmtools.trainola\n" +
# start trainola "nilmtools.trainola.main()",
pid = client.post("/run/trainola", { "data": data }) "args": [ data ] })
while True:
# wait for it to finish status = client.get("/process/status", { "pid": pid, "clear": 1 })
for i in range(60): sys.stdout.write(status["log"])
time.sleep(1) sys.stdout.flush()
if i == 2:
status = client.get("/process/status", { "pid": pid,
"clear": True })
in_("Loading stream data", status['log'])
elif i == 3:
status = client.get("/process/status", { "pid": pid })
nin_("Loading stream data", status['log'])
else:
status = client.get("/process/status", { "pid": pid })
if status["alive"] == False: if status["alive"] == False:
break break
else: status = client.post("/process/remove", { "pid": pid })
client.post("/process/remove", {"pid": pid }) os._exit(int(status["exitcode"]))
raise AssertionError("took too long")
if i < 3:
raise AssertionError("too fast?")
def test_client_07_run_command(self): def test_client_06_run_command(self):
client = HTTPClient(baseurl = testurl, post_json = True) client = HTTPClient(baseurl = testurl, post_json = True)
eq_(client.get("/process/list"), []) eq_(client.get("/process/list"), [])
@@ -258,7 +239,7 @@ class TestClient(object):
status = do(["sleep", "60"], True) status = do(["sleep", "60"], True)
ne_(status["exitcode"], 0) ne_(status["exitcode"], 0)
def test_client_08_run_code(self): def test_client_07_run_code(self):
client = HTTPClient(baseurl = testurl, post_json = True) client = HTTPClient(baseurl = testurl, post_json = True)
eq_(client.get("/process/list"), []) eq_(client.get("/process/list"), [])
@@ -307,6 +288,7 @@ class TestClient(object):
code=textwrap.dedent(""" code=textwrap.dedent("""
import sys import sys
print sys.argv[1].encode('ascii'), sys.argv[2] print sys.argv[1].encode('ascii'), sys.argv[2]
sys.exit(0) # also test raising SystemExit
""") """)
status = do(code, ["hello", 123], False) status = do(code, ["hello", 123], False)
eq_(status["log"], "hello 123\n") eq_(status["log"], "hello 123\n")