diff options
-rw-r--r-- | run/emailer.py | 28 | ||||
-rw-r--r-- | run/experiment.py | 10 | ||||
-rw-r--r-- | run/litmus_util.py | 4 | ||||
-rwxr-xr-x | run_exps.py | 40 |
4 files changed, 66 insertions, 16 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: |
diff --git a/run_exps.py b/run_exps.py index 77c9631..b9cf88e 100755 --- a/run_exps.py +++ b/run_exps.py | |||
@@ -68,6 +68,9 @@ def parse_args(): | |||
68 | parser.add_option('-j', '--jabber', metavar='username@domain', | 68 | parser.add_option('-j', '--jabber', metavar='username@domain', |
69 | dest='jabber', default=None, | 69 | dest='jabber', default=None, |
70 | help='send a jabber message when an experiment completes') | 70 | help='send a jabber message when an experiment completes') |
71 | parser.add_option('-e', '--email', metavar='username@server', | ||
72 | dest='email', default=None, | ||
73 | help='send an email when all experiments complete') | ||
71 | 74 | ||
72 | return parser.parse_args() | 75 | return parser.parse_args() |
73 | 76 | ||
@@ -295,10 +298,22 @@ def setup_jabber(target): | |||
295 | 298 | ||
296 | return Jabber(target) | 299 | return Jabber(target) |
297 | except ImportError: | 300 | except ImportError: |
298 | sys.stderr.write("Failed to import jabber, disabling messages. " + | 301 | sys.stderr.write("Failed to import jabber. Is python-xmpp installed? " + |
299 | "Is python-xmpp installed?") | 302 | "Disabling instant messages.\n") |
300 | return None | 303 | return None |
301 | 304 | ||
305 | def setup_email(target): | ||
306 | try: | ||
307 | from run.emailer import Emailer | ||
308 | |||
309 | return Emailer(target) | ||
310 | except ImportError: | ||
311 | message = "Failed to import email. Is smtplib installed?" | ||
312 | except IOError: | ||
313 | message = "Failed to create email. Is an smtp server active?" | ||
314 | |||
315 | sys.stderr.write(message + " Disabling email message.\n") | ||
316 | return None | ||
302 | 317 | ||
303 | def main(): | 318 | def main(): |
304 | opts, args = parse_args() | 319 | opts, args = parse_args() |
@@ -320,10 +335,8 @@ def main(): | |||
320 | failed = 0 | 335 | failed = 0 |
321 | invalid = 0 | 336 | invalid = 0 |
322 | 337 | ||
323 | if opts.jabber: | 338 | jabber = setup_jabber(opts.jabber) if opts.jabber else None |
324 | jabber = setup_jabber(opts.jabber) | 339 | email = setup_email(opts.email) if opts.email else None |
325 | else: | ||
326 | jabber = None | ||
327 | 340 | ||
328 | for exp in args: | 341 | for exp in args: |
329 | path = "%s/%s" % (os.getcwd(), exp) | 342 | path = "%s/%s" % (os.getcwd(), exp) |
@@ -357,12 +370,17 @@ def main(): | |||
357 | if not os.listdir(out_base) and created and not succ: | 370 | if not os.listdir(out_base) and created and not succ: |
358 | os.rmdir(out_base) | 371 | os.rmdir(out_base) |
359 | 372 | ||
360 | print("Experiments run:\t%d" % len(args)) | 373 | message = "Experiments run:\t%d" % len(args) +\ |
361 | print(" Successful:\t\t%d" % succ) | 374 | "\n Successful:\t\t%d" % succ +\ |
362 | print(" Failed:\t\t%d" % failed) | 375 | "\n Failed:\t\t%d" % failed +\ |
363 | print(" Already Done:\t\t%d" % done) | 376 | "\n Already Done:\t\t%d" % done +\ |
364 | print(" Invalid Environment:\t%d" % invalid) | 377 | "\n Invalid Environment:\t%d" % invalid |
378 | |||
379 | print(message) | ||
365 | 380 | ||
381 | if email: | ||
382 | email.send(message) | ||
383 | email.close() | ||
366 | 384 | ||
367 | if __name__ == '__main__': | 385 | if __name__ == '__main__': |
368 | main() | 386 | main() |