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
WSGIScriptAlias /nilmrun /home/nilm/nilmrun.wsgi
WSGIApplicationGroup nilmrun-appgroup
WSGIProcessGroup nilmrun-procgroup
WSGIDaemonProcess nilmrun-procgroup threads=32 user=nilm group=nilm
<Location /nilmrun>
WSGIApplicationGroup nilmrun-appgroup
SSLRequireSSL
# Access control example:
<Location /nilmrun>
SSLRequireSSL
Order deny,allow
Deny from all
Allow from 1.2.3.4

View File

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

View File

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

View File

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