Add test status for notify build status of SR 96/162896/1
authorYonghee Han <onstudy@samsung.com>
Wed, 6 Dec 2017 04:41:01 +0000 (13:41 +0900)
committerYonghee Han <onstudy@samsung.com>
Wed, 6 Dec 2017 04:41:13 +0000 (13:41 +0900)
Trigger Next : TRBS_test_result_receiver -> notify_buildstatus

Change-Id: I2b73ed1d4136ddd39356d88cc3a8a8f529b9d48e

job_notify_buildstatus.py
job_trbs_test_result_receiver.py

index 9d87919..805cd2e 100644 (file)
@@ -2,20 +2,22 @@ import os
 import sys
 import base64
 import xml.etree.cElementTree as ElementTree
+
+from common.buildservice import BuildService
 from common.buildtrigger import trigger_info
 from common.send_mail import prepare_mail
 
-def send_mail_buildstatus(info):
+def send_mail_buildstatus(info, test_status=None):
     """ send mail about buildstatus """
-    EMAIL_TITLE = "SR[%s] %s %s"
-    EMAIL_BODY = "The status of SR has been updated.\n" \
+    EMAIL_TITLE = "SR[%s] %s %s %s"
+    EMAIL_BODY = "The status of the SR has been updated.\n" \
                  "Please check the following details.\n\n" \
                  "SR tag: %s\n" \
                  "Packages : %s\n\n" \
                  "Result\n" \
                  "Build : %s\n" \
                  "Image : %s\n" \
+                 "Test : %s\n\n" \
                  "For more details, please refer to %s"
 
     EMAIL_FOOTER = '\n\n--------------------------------------------------------\n'\
@@ -63,10 +65,20 @@ def send_mail_buildstatus(info):
         imgstatus=None
    
     dashboard_url = os.path.join(os.getenv('DASHBOARD_URL'), "index.code?sr=" + info.get('git_tag'))
+    if test_status:
+        if test_status == 'S':
+            title_test = 'Test(Succeeded)'
+            teststatus = 'success'
+        else:
+            title_test = 'Test(Failed)'
+            teststatus = 'failed'
+    else:
+        title_test =""
+        teststatus =""
 
     #make a message
-    title = EMAIL_TITLE % (info.get('git_tag'), title_build, title_image)
-    email_body = EMAIL_BODY % ( info.get('git_tag'), info.get('packages'), buildstatus, imgstatus, dashboard_url)
+    title = EMAIL_TITLE % (info.get('git_tag'), title_build, title_image, title_test)
+    email_body = EMAIL_BODY % ( info.get('git_tag'), info.get('packages'), buildstatus, imgstatus, teststatus, dashboard_url)
     msg = 'Hello \n\n' + email_body + EMAIL_FOOTER
     print submitters
     print title
@@ -78,14 +90,26 @@ def send_mail_buildstatus(info):
 def main():
     """The main body"""
 
-    saved_info = trigger_info(os.getenv('TRIGGER_INFO'))
+    obs_api = os.getenv("OBS_API_URL")
+    obs_user = os.getenv("OBS_API_USERNAME")
+    obs_passwd = os.getenv("OBS_API_PASSWD")
+
+    content = trigger_info(os.getenv('TRIGGER_INFO'))
+
+    build = BuildService(obs_api, obs_user, obs_passwd)
+    if content.get('project'):
+        project = content.get('project')
+        test_status = content.get('status')
+    else:
+        project = content.get('obs_url').split('project=')[-1]
+        test_status = None
 
-    project = saved_info.get('obs_url').split('project=')[-1]
     if project is None:
         raise LocalError('Please check the project (%s)' \
                          % (project))
 
-    send_mail_buildstatus(saved_info)
+    saved_info = build.get_info(project)
+    send_mail_buildstatus(saved_info, test_status)
 
 if __name__ == '__main__':
     sys.exit(main())
index 50b58ba..0685d6b 100755 (executable)
@@ -10,6 +10,23 @@ import urllib2
 import re
 import datetime
 from codebase import *
+from common.buildtrigger import trigger_info, trigger_next
+
+def notify_test_result(MYSQL, build_project_id, status):
+    """
+    Notify the test results to submitters
+    """
+    sql_data = (build_project_id,)
+    sql = "SELECT ip.project_name FROM info_project ip, build_project bp WHERE ip.id = bp.info_project_id AND bp.id = %s"
+    MYSQL['cursor'].execute(sql, sql_data)
+    row = MYSQL['cursor'].fetchall()
+    if len(row) > 0:
+        project_name = row[0]['project_name']
+        print project_name
+        data = {"project" : project_name,
+                "status" : status
+               }
+        trigger_next("NOTIFY-BUILDSTATUS", data)
 
 def is_test_succeeded(data, is_ref_exist, is_perf_exist):
 
@@ -61,6 +78,8 @@ def insert_test_stage(data, MYSQL, sr_id, snapshot, is_ref_exist, is_perf_exist
     MYSQL['cursor'].execute(sql, sql_data)
     MYSQL['connection'].commit()
 
+    # Add notify status
+    notify_test_result(MYSQL, build_project_id, status)
 
 if __name__ == "__main__":