Add email reporting to failing tests when parsing results
* added failtest for testing this (and anything else that needs a failing test
)
* Improved readability in parse script output
* Added getopt() for parse and added -m option for sending mail on failures
* pulled mail* functions in from mirror/mirror
* Get a realuser value in autoserv for run tests
* Fix jobkeyval value
From: David McMahon <djmm@google.com>
Signed-off-by: Martin Bligh <mbligh@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@910 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/parse.py b/tko/parse.py
index 75f44d4..3ec753d 100755
--- a/tko/parse.py
+++ b/tko/parse.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import os, re, md5, sys
+import os, re, md5, sys, email.Message, smtplib
valid_users = r'(apw|mbligh|andyw|korgtest)'
build_stock = re.compile('build generic stock (2\.\S+)')
@@ -10,6 +10,46 @@
debug = True
+# XXX: these mail bits came almost verbatim from mirror/mirror and this should
+# probably be refactored into another file and used by both.
+def mail(from_address, to_addresses, cc_addresses, subject, message_text):
+ # if passed a string for the to_addresses convert it to a tuple
+ if type(to_addresses) is str:
+ to_addresses = (to_addresses,)
+
+ message = email.Message.Message()
+ message["To"] = ", ".join(to_addresses)
+ message["Cc"] = ", ".join(cc_addresses)
+ message["From"] = from_address
+ message["Subject"] = subject
+ message.set_payload(message_text)
+
+ try:
+ sendmail(message.as_string())
+ except SendmailException, e:
+ server = smtplib.SMTP("localhost")
+ server.sendmail(from_address, to_addresses, cc_addresses, message.as_string())
+ server.quit()
+
+
+MAIL = "sendmail"
+
+class SendmailException(Exception):
+ pass
+
+def sendmail(message):
+ """Send an email using sendmail"""
+ # open a pipe to the mail program and
+ # write the data to the pipe
+ p = os.popen("%s -t" % MAIL, 'w')
+ p.write(message)
+ exitcode = p.close()
+ if exitcode:
+ raise SendmailException("Exit code: %s" % exitcode)
+
+# XXX: End of code from mirror/mirror
+
+
def shorten_patch(long):
short = os.path.basename(long)
short = re.sub(r'^patch-', '', short)
@@ -35,7 +75,7 @@
self.kernel = None
# Get the user + tag info from the keyval file.
- jobkeyval = os.path.join(dir, "keyval")
+ jobkeyval = os.path.join(os.path.dirname (dir), "keyval")
self.user = None
self.label = None
if os.path.exists(jobkeyval):