Compare commits
2 Commits
nilmrun-1.
...
nilmrun-1.
Author | SHA1 | Date | |
---|---|---|---|
18d3cff772 | |||
a7b9656916 |
@@ -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
|
||||||
|
@@ -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
|
||||||
|
|
||||||
|
@@ -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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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"), [])
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user