adapt mail sender to mail_sender jobs
authorHasan Wan <hasan.wan@intel.com>
Thu, 9 Aug 2012 10:17:42 +0000 (18:17 +0800)
committerLin Yang <lin.a.yang@intel.com>
Tue, 28 Aug 2012 03:23:07 +0000 (11:23 +0800)
Change-Id: Id7d7a977b66c866fa31dcf22222386d49c3487da
Signed-off-by: Hasan Wan <hasan.wan@intel.com>
buildcheck.py
common/send_mail.py
mail_sender.py
submitobs.py
submitobs_orig.py

index eee5582..676fd95 100755 (executable)
@@ -19,7 +19,6 @@ from common import git
 from common import runner
 from common.envparas import *
 from common import buildservice
-from common.send_mail import sendmail
 
 import gbp.rpm
 import gbp
@@ -35,6 +34,7 @@ envparas = ['JENKINS_HOME',
             'GERRIT_PATCHSET_NUMBER',
             'GERRIT_BRANCH',
             'BUILD_NUMBER',
+            'BUILD_TAG',
             'OBS_USERNAME',
             'OBS_API_URL',
             'OBS_OSCRC_PATH']
@@ -42,6 +42,18 @@ export(envparas, locals())
 GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
 GIT_URL = 'ssh://%s@%s:%s' % (GERRIT_USERNAME, GERRIT_HOSTNAME, GERRIT_SSHPORT)
 
+def sendmail(subject, body, mail_from, mail_to):
+    """ Prepare the envorinment parameter for trigger mail_sender job"""
+    mail_env = {}
+    mail_env['subject'] = subject
+    mail_env['body'] = body.replace('\n', '\\n')
+    mail_env['From'] = mail_from
+    mail_env['To'] = mail_to
+
+    with open('%s.env' %(BUILD_TAG),'w') as f:
+        for key in mail_env.keys():
+            f.write('%s=%s\n' %(key, mail_env[key]))
+
 def end(rc = 0):
     shutil.rmtree(tmpdir)
     exit(rc)
index 537c9a0..c2e013b 100644 (file)
@@ -11,13 +11,17 @@ from email.Header import Header
 from email.Utils import parseaddr, formataddr
 
 def sendmail(from_email, to, msg, smtp_server):
+
+    if type(to) != list:
+        to = [to]
+
     try:
         s = smtplib.SMTP(smtp_server)
-        s.sendmail(from_email, to, msg.as_string())
+        s.sendmail(from_email, ','.join(to), msg.as_string())
         s.quit()
         print "Email to %s sent succeeded" %(to)
     except smtplib.SMTPException, e:
-        print "Error: unable to send email: %s" % ( e )
+        raise Exception, "Error: unable to send email: %s" % ( e )
 
 def makemail(subject = '', body = '', from_email = None, to = [],
              cc = [], attachment = None, extra_headers = None):
index 3e30382..406d833 100644 (file)
@@ -10,10 +10,6 @@ envparas = ['From',
             'Cc',
             'subject',
             'body',
-            'targetpackage',
-            'template',
-            'reqinfo',
-            'comment',
             'attachment',
             'extra_headers',
             'SMTP_SERVER']
@@ -21,6 +17,12 @@ envparas = ['From',
 
 export(envparas, locals())
 
+if To.startswith('[') and To.endswith(']'):
+    To = eval(To)
+
+if Cc.startswith('[') and Cc.endswith(']'):
+    Cc = eval(Cc)
+    
 message = makemail(subject = subject, body = body, from_email = From, to = To,
          cc = Cc, attachment = attachment, extra_headers = extra_headers)
 
index 7ef7eb1..0af8d64 100755 (executable)
@@ -19,7 +19,6 @@ from common import obspkg
 from common.envparas import *
 from common import errors
 from common import mysql
-from common.send_mail import sendmail
 
 import gbp.rpm
 
@@ -42,6 +41,7 @@ envparas = ['GERRIT_EVENT_TYPE',
             'MYSQL_HOSTNAME',
             'MYSQL_USERNAME',
             'MYSQL_PASSWORD',
+            'BUILD_TAG',
             'MYSQL_DB_NAME']
 export(envparas, locals())
 GERRIT_CMD = 'ssh -p %s %s@%s gerrit' % (GERRIT_SSHPORT, GERRIT_USERNAME, GERRIT_HOSTNAME)
@@ -59,6 +59,20 @@ ret = { 'rc' : {'success' : 0, 'failure' : 0, 'retry' : 1},
                                    'newRev' : GERRIT_NEWREV}},
       }
 
+
+
+def sendmail(subject, body, mail_from, mail_to):
+    """ Prepare the envorinment parameter for trigger mail_sender job"""
+    mail_env = {}
+    mail_env['subject'] = subject
+    mail_env['body'] = body.replace('\n', '\\n')
+    mail_env['From'] = mail_from
+    mail_env['To'] = mail_to
+
+    with open('%s.env' %(BUILD_TAG),'w') as f:
+        for key in mail_env.keys():
+            f.write('%s=%s\n' %(key, mail_env[key]))
+
 def end(result = 'success'):
     print 'execute result: %s' % result
     db = mysql.Database(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQL_DB_NAME)
index 272e677..56f1b76 100755 (executable)
@@ -19,7 +19,6 @@ from common import obspkg
 from common.envparas import *
 from common import errors
 from common import mysql
-from common.send_mail import sendmail
 
 import gbp.rpm
 
@@ -39,6 +38,7 @@ envparas = ['GERRIT_EVENT_TYPE',
             'JENKINS_HOME',
             'OBS_API_URL',
             'OBS_OSCRC_PATH',
+            'BUILD_TAG',
             'MYSQL_HOSTNAME',
             'MYSQL_USERNAME',
             'MYSQL_PASSWORD',
@@ -58,6 +58,19 @@ ret = { 'rc' : {'success' : 0, 'failure' : 0, 'retry' : 1},
                                     'newRev' : GERRIT_NEWREV}},
       }
 
+
+def sendmail(subject, body, mail_from, mail_to):
+    """ Prepare the envorinment parameter for trigger mail_sender job"""
+    mail_env = {}
+    mail_env['subject'] = subject
+    mail_env['body'] = body.replace('\n', '\\n')
+    mail_env['From'] = mail_from
+    mail_env['To'] = mail_to
+
+    with open('%s.env' %(BUILD_TAG),'w') as f:
+        for key in mail_env.keys():
+            f.write('%s=%s\n' %(key, mail_env[key]))
+
 def end(result = 'success'):
     print 'execute result: %s' % result
     # cleanup workspace