diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 15:32:39 -0400 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-04-10 15:32:39 -0400 |
commit | 384e322f974534c1c734db144633e3c3e002b1f8 (patch) | |
tree | 1637267cea4cb5166677f272e97b19ce8331a36c /run | |
parent | 4162cc0c57de22566efa6e2dab224909279f2a47 (diff) |
Added option to send email when experiments complete.
Diffstat (limited to 'run')
-rw-r--r-- | run/emailer.py | 28 | ||||
-rw-r--r-- | run/experiment.py | 10 | ||||
-rw-r--r-- | run/litmus_util.py | 4 |
3 files changed, 37 insertions, 5 deletions
diff --git a/run/emailer.py b/run/emailer.py new file mode 100644 index 0000000..6d66da2 --- /dev/null +++ b/run/emailer.py | |||
@@ -0,0 +1,28 @@ | |||
1 | import os | ||
2 | import pwd | ||
3 | import smtplib | ||
4 | import socket | ||
5 | |||
6 | class Emailer(object): | ||
7 | def __init__(self, target): | ||
8 | user = pwd.getpwuid(os.getuid())[0] | ||
9 | host = socket.gethostname() | ||
10 | |||
11 | self.sender = "%s@%s" % (user, host) | ||
12 | self.target = target | ||
13 | |||
14 | self.body = "\r\n".join(["From: %s" % self.sender, | ||
15 | "To: %s" % target, | ||
16 | "Subject: Test Completed!", "", "{}"]) | ||
17 | |||
18 | self.mail = smtplib.SMTP("localhost") | ||
19 | |||
20 | # Hopefully crash if the server is not running | ||
21 | self.mail.ehlo() | ||
22 | |||
23 | def close(self): | ||
24 | self.mail.quit() | ||
25 | |||
26 | def send(self, text): | ||
27 | self.mail.sendmail(self.sender, [self.target], | ||
28 | self.body.format(text)) | ||
diff --git a/run/experiment.py b/run/experiment.py index 3dd4866..e5811f8 100644 --- a/run/experiment.py +++ b/run/experiment.py | |||
@@ -87,6 +87,10 @@ class Experiment(object): | |||
87 | def __run_tasks(self): | 87 | def __run_tasks(self): |
88 | already_waiting = lu.waiting_tasks() | 88 | already_waiting = lu.waiting_tasks() |
89 | 89 | ||
90 | if already_waiting: | ||
91 | self.log("Already %d tasks waiting for release!") | ||
92 | self.log("Experiment will fail if any of these tasks are released.") | ||
93 | |||
90 | self.log("Starting the programs") | 94 | self.log("Starting the programs") |
91 | for e in self.executables: | 95 | for e in self.executables: |
92 | try: | 96 | try: |
@@ -115,7 +119,6 @@ class Experiment(object): | |||
115 | # Need to re-release non-released tasks before we can kill them though | 119 | # Need to re-release non-released tasks before we can kill them though |
116 | self.log("Failed to release {} tasks! Re-releasing and killing".format( | 120 | self.log("Failed to release {} tasks! Re-releasing and killing".format( |
117 | len(self.executables) - released, len(self.executables))) | 121 | len(self.executables) - released, len(self.executables))) |
118 | |||
119 | time.sleep(5) | 122 | time.sleep(5) |
120 | 123 | ||
121 | released = lu.release_tasks() | 124 | released = lu.release_tasks() |
@@ -160,7 +163,10 @@ class Experiment(object): | |||
160 | self.teardown() | 163 | self.teardown() |
161 | finally: | 164 | finally: |
162 | self.log("Switching to Linux scheduler") | 165 | self.log("Switching to Linux scheduler") |
163 | lu.switch_scheduler("Linux") | 166 | try: |
167 | lu.switch_scheduler("Linux") | ||
168 | except: | ||
169 | self.log("Failed to switch back to Linux.") | ||
164 | 170 | ||
165 | if succ: | 171 | if succ: |
166 | self.__save_results() | 172 | self.__save_results() |
diff --git a/run/litmus_util.py b/run/litmus_util.py index b9080c1..4709b66 100644 --- a/run/litmus_util.py +++ b/run/litmus_util.py | |||
@@ -8,7 +8,6 @@ def switch_scheduler(switch_to_in): | |||
8 | 8 | ||
9 | This methods sleeps for two seconds to give Linux the chance to execute | 9 | This methods sleeps for two seconds to give Linux the chance to execute |
10 | schedule switching code. Raises an exception if the switch does not work. | 10 | schedule switching code. Raises an exception if the switch does not work. |
11 | |||
12 | ''' | 11 | ''' |
13 | 12 | ||
14 | switch_to = str(switch_to_in).strip() | 13 | switch_to = str(switch_to_in).strip() |
@@ -23,7 +22,7 @@ def switch_scheduler(switch_to_in): | |||
23 | cur_plugin = active_plugin.read().strip() | 22 | cur_plugin = active_plugin.read().strip() |
24 | 23 | ||
25 | if switch_to != cur_plugin: | 24 | if switch_to != cur_plugin: |
26 | raise Exception("Could not switch to plugin: %s" % switch_to) | 25 | raise Exception("Could not switch to '%s' (check dmesg)" % switch_to) |
27 | 26 | ||
28 | def waiting_tasks(): | 27 | def waiting_tasks(): |
29 | reg = re.compile(r'^ready.*?(?P<READY>\d+)$', re.M) | 28 | reg = re.compile(r'^ready.*?(?P<READY>\d+)$', re.M) |
@@ -37,7 +36,6 @@ def waiting_tasks(): | |||
37 | return 0 if not ready else int(ready) | 36 | return 0 if not ready else int(ready) |
38 | 37 | ||
39 | def release_tasks(): | 38 | def release_tasks(): |
40 | |||
41 | try: | 39 | try: |
42 | data = subprocess.check_output([conf.BINS['release']]) | 40 | data = subprocess.check_output([conf.BINS['release']]) |
43 | except subprocess.CalledProcessError: | 41 | except subprocess.CalledProcessError: |