]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
liveboot: report build status to testlink testcase
authorFabian Holler <fabian.holler@profitbricks.com>
Tue, 30 Apr 2013 10:05:50 +0000 (12:05 +0200)
committerFabian Holler <fabian.holler@profitbricks.com>
Tue, 30 Apr 2013 10:08:31 +0000 (12:08 +0200)
The liveboot webinterface creates now the testlink project for every new
liveboot image. The jenkins build script reports if a liveboot image
build was successful or failed to a testlink testcase.

liveboot_build.sh
liveboot_gw_autotest.sh
liveboot_testlink_create_build.sh [deleted file]
liveboot_testlink_update_testcase.py [new file with mode: 0755]

index 4cfbdd598a853b9a0337768b9c5011462905ee7a..68cacab6baa9747659e1932f4fe7b62f46a42240 100755 (executable)
@@ -6,6 +6,8 @@
 set_failure() {
        BUILD_END=$(date +%s)
        $SCRIPTSDIR/liveboot2db.py $JOB_NAME $BUILD_NUMBER $REQUEST_ID $BUILD_START $BUILD_END "failed"
+    build_name=$(basename $(readlink -f/srv/build/liveboot/builds/last))
+    $SCRIPTSDIR/liveboot_testlink_update_testcase.py "$build_name" "failed"
        # cleanup mount points
        cd /var/cache/pbuilder/build
        echo "My PID: $$"
@@ -62,6 +64,12 @@ echo "sudo pbuilder --execute --bindmounts /srv/build/ -- $BUILD_SCRIPT" > ${BUI
 bash -x ${BUILD_SCRIPT}_sudo
 rm $BUILD_SCRIPT ${BUILD_SCRIPT}_sudo
 
+#
+# report build status to testlink testcase
+#
+build_name=$(basename $(readlink -f/srv/build/liveboot/builds/last))
+$SCRIPTSDIR/liveboot_testlink_update_testcase.py "$build_name" "successful"
+
 #
 # add liveboot build result to cidb
 #
index 516f4d8ea20da956550f82521e1bbe3bd7f00613..1142b520730551e829a43a68a3889012a3543c9f 100755 (executable)
@@ -60,12 +60,6 @@ ssh -t $CORE_ROUTER "sudo rm /opt/autotest -rf ; sudo mkdir -p /opt/autotest ; s
 ssh -t $CORE_ROUTER "cd /opt ; git clone git://git/ri/autotest.git"
 ssh -t $CORE_ROUTER "cd /opt/autotest ; git checkout master"
 
-#
-# Generate TestLink Build
-#
-$(dirname $0)/liveboot_testlink_create_build.sh \
-        "liveboot-${LIVEBOOT_BUILD_NUMBER}"     \
-        "Auto-generated by Jenkins on $(date --rfc-3339=seconds)"
 
 #
 # run autotests
diff --git a/liveboot_testlink_create_build.sh b/liveboot_testlink_create_build.sh
deleted file mode 100755 (executable)
index 72f5fcf..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-# ask Thilo Fromm about this script
-#
-# Create a TestLink build by means of xmlrpc.
-# 
-#  This helper script creates a new TestLink build in the "Profitbricks"
-#  project, test plan "R&I Liveboot Approval Autotest".
-#
-#  Example Usage: 
-#
-#    liveboot_testlink_create_build.sh                  \
-#                                       "liveboot-923"  \
-#                                       "auto-generated build at $(date)."
-#
-
-testlink_url='http://testlink/lib/api/xmlrpc.php'
-     dev_key='6805a288081cf7480d391533b354cb7c'
-
-test_project="Profitbricks"
-   test_plan="R&amp;I Liveboot Approval Autotest"
-
-
-# ---------------------
-
-
-xmlrpc() {
-    local method="tl.$1" ; shift
-    local params="
-     <member> <name>devKey</name> <value>$dev_key</value> </member>$@
-                 "
-
-    curl -s                                 \
-         --header 'content-type: text/xml'  \
-         --header 'Cache-Control: no-cache' \
-         --header 'Pragma: no-cache'        \
-         --data-binary                      \
-"
-<?xml version=\"1.0\" encoding=\"UTF-8\"?>
-<methodCall>
-    <methodName>$method</methodName>
-    <params> 
-        <param> 
-            <value> 
-                <struct> $params </struct> 
-            </value> 
-        </param> 
-    </params>
-</methodCall>" \
-        $testlink_url
-
-    echo ""
-}
-# ----
-
-get_testplan_by_name() {
-    local project="$1" ; shift
-    local plan="$@"
-    xmlrpc "getTestPlanByName" "
-        <member> <name>testprojectname</name> <value>$project</value> </member>
-        <member> <name>testplanname</name> <value>$plan</value> </member>"  \
-        | grep '<member><name>id</name>'                                    \
-        | sed 's:.*<value><string>\([0-9]*\)</string></value>.*:\1:'
-}
-# ----
-
-createBuild() {
-    local name="$1" ; shift
-    local notes="$@"
-
-    local id=`get_testplan_by_name "$test_project"  "$test_plan"`
-
-    xmlrpc "createBuild" "
-        <member> <name>testplanid</name> <value>$id</value> </member>  \
-        <member> <name>buildname</name> <value>$name</value> </member>  \
-        <member> <name>buildnotes</name> <value>$notes</value> </member>"
-}
-# ----
-
-
-if [ "liveboot_testlink_create_build.sh" = `basename $0` ]; then
-
-    [ $# -lt 2 ] && {
-        echo
-        echo "USAGE: $0 '<TestLink build name>' '<comment>'"
-        echo
-        exit
-    }
-
-    name="$1" ; shift
-    createBuild "$name" $@
-    exit
-fi
diff --git a/liveboot_testlink_update_testcase.py b/liveboot_testlink_update_testcase.py
new file mode 100755 (executable)
index 0000000..24d38a9
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+
+""" The build.sh liveboot script creates a new Testlink Project for every
+Liveboot image that is build. This script reports if a liveboot build was
+successful or failed to the testlink testcase 'Liveboot Image Build' """
+
+import logging
+import sys
+import xmlrpclib
+
+
+TESTLINK_API_URL = "http://testlink/lib/api/xmlrpc.php"
+TESTLINK_DEV_KEY = "6805a288081cf7480d391533b354cb7c"
+TESTLINK_IMAGE_BUILD_TESTCASE_ID = "PB-601"
+TESTLINK_PLATFORM = "R&I HW Test Bed"
+logger = logging.getLogger(__name__)
+
+
+class TestlinkAPIClient:
+    def __init__(self):
+        self.server = xmlrpclib.Server(TESTLINK_API_URL)
+        self.devKey = TESTLINK_DEV_KEY
+
+    def getTestPlanId(self, name):
+        data = {"devKey": self.devKey, "testprojectname": "Profitbricks",
+                "testplanname": name}
+        return self.server.tl.getTestPlanByName(data)
+
+    def reportTestCaseResult(self, testcaseexternalid, testplanid, buildname,
+                             status, notes):
+        # valid status values:
+        # 'p' = passed
+        # 'b' = blocked
+        # 'f' = failed
+        data = {"devKey": self.devKey, "testcaseexternalid":
+                testcaseexternalid, "testplanid": testplanid, "buildname":
+                buildname, "platformname": TESTLINK_PLATFORM, "status": status}
+        return self.server.tl.reportTCResult(data)
+
+
+def update_testlink_testcase(buildname, status, notes=""):
+    logger.info("Updating testlink testcase for build %s, testcase result: %s"
+            % (buildname, status))
+# set testcaseexternalid, ignore testcaseid
+    t = TestlinkAPIClient()
+    testplan_id = t.getTestPlanId("R&I Liveboot Approval Autotest")[0]["id"]
+    res = t.reportTestCaseResult(TESTLINK_IMAGE_BUILD_TESTCASE_ID, testplan_id,
+            buildname, status, notes)
+    logger.info("Testlink server returned: %s" % res)
+
+
+if __name__ == "__main__":
+    logging.basicConfig(level=logging.DEBUG)
+
+    if len(sys.argv) < 3:
+        print("usage: %s BUILDNAME (failed|successful)" % sys.argv[0])
+        sys.exit(1)
+    if sys.argv[2] == "successful":
+        update_testlink_testcase(sys.argv[1], "p")
+    elif sys.argv[2] == "failed":
+        update_testlink_testcase(sys.argv[1], "f")