diff mbox

[Branch,~linaro-validation/lava-dispatcher/trunk] Rev 492: add a way for lava-test-shell tests to add attachments to the test run

Message ID 20121211002413.15097.55579.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Michael-Doyle Hudson Dec. 11, 2012, 12:24 a.m. UTC
Merge authors:
  Michael Hudson-Doyle (mwhudson)
Related merge proposals:
  https://code.launchpad.net/~mwhudson/lava-dispatcher/easy-test-run-attachments/+merge/139085
  proposed by: Michael Hudson-Doyle (mwhudson)
  review: Approve - Andy Doan (doanac)
------------------------------------------------------------
revno: 492 [merge]
committer: Michael Hudson-Doyle <michael.hudson@linaro.org>
branch nick: trunk
timestamp: Tue 2012-12-11 13:23:15 +1300
message:
  add a way for lava-test-shell tests to add attachments to the test run
added:
  lava_test_shell/lava-test-run-attach
modified:
  doc/lava_test_shell.rst
  lava_dispatcher/actions/lava_test_shell.py


--
lp:lava-dispatcher
https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk

You are subscribed to branch lp:lava-dispatcher.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dispatcher/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'doc/lava_test_shell.rst'
--- doc/lava_test_shell.rst	2012-11-22 19:52:03 +0000
+++ doc/lava_test_shell.rst	2012-12-10 20:34:15 +0000
@@ -54,6 +54,7 @@ 
 
  * ``lava-test-case``
  * ``lava-test-case-attach``
+ * ``lava-test-run-attach``
 
 You need to use ``lava-test-case`` (specifically, ``lava-test-case
 --shell``) when you are working with `hooks, signals and external
@@ -113,6 +114,22 @@ 
  1. test case id
  2. the file to attach
  3. (optional) the MIME type of the file (if no MIME type is passed, a
+    guess is made based on the filename
+
+lava-test-run-attach
+--------------------
+
+This attaches a file to the overall test run that lava-test-shell is
+currently executing, for example::
+
+  steps:
+    - "echo content > file.txt"
+    - "lava-test-run-attach file.txt text/plain"
+
+The arguments are:
+
+ 1. the file to attach
+ 2. (optional) the MIME type of the file (if no MIME type is passed, a
     guess is made based on the filename)
 
 

=== modified file 'lava_dispatcher/actions/lava_test_shell.py'
--- lava_dispatcher/actions/lava_test_shell.py	2012-12-11 00:22:28 +0000
+++ lava_dispatcher/actions/lava_test_shell.py	2012-12-11 00:23:15 +0000
@@ -139,11 +139,13 @@ 
 LAVA_TEST_SHELL = '%s/lava-test-shell' % LAVA_TEST_DIR
 LAVA_TEST_CASE = '%s/lava-test-case' % LAVA_TEST_DIR
 LAVA_TEST_CASE_ATTACH = '%s/lava-test-case-attach' % LAVA_TEST_DIR
+LAVA_TEST_RUN_ATTACH = '%s/lava-test-run-attach' % LAVA_TEST_DIR
 
 Target.android_deployment_data['lava_test_runner'] = LAVA_TEST_ANDROID
 Target.android_deployment_data['lava_test_shell'] = LAVA_TEST_SHELL
 Target.android_deployment_data['lava_test_case'] = LAVA_TEST_CASE
 Target.android_deployment_data['lava_test_case_attach'] = LAVA_TEST_CASE_ATTACH
+Target.android_deployment_data['lava_test_run_attach'] = LAVA_TEST_RUN_ATTACH
 Target.android_deployment_data['lava_test_sh_cmd'] = '/system/bin/mksh'
 Target.android_deployment_data['lava_test_dir'] = '/data/lava'
 Target.android_deployment_data['lava_test_results_part_attr'] = 'data_part_android_org'
@@ -152,6 +154,7 @@ 
 Target.ubuntu_deployment_data['lava_test_shell'] = LAVA_TEST_SHELL
 Target.ubuntu_deployment_data['lava_test_case'] = LAVA_TEST_CASE
 Target.ubuntu_deployment_data['lava_test_case_attach'] = LAVA_TEST_CASE_ATTACH
+Target.ubuntu_deployment_data['lava_test_run_attach'] = LAVA_TEST_RUN_ATTACH
 Target.ubuntu_deployment_data['lava_test_sh_cmd'] = '/bin/bash'
 Target.ubuntu_deployment_data['lava_test_dir'] = '/lava'
 Target.ubuntu_deployment_data['lava_test_results_part_attr'] = 'root_part'
@@ -160,6 +163,7 @@ 
 Target.oe_deployment_data['lava_test_shell'] = LAVA_TEST_SHELL
 Target.oe_deployment_data['lava_test_case'] = LAVA_TEST_CASE
 Target.oe_deployment_data['lava_test_case_attach'] = LAVA_TEST_CASE_ATTACH
+Target.oe_deployment_data['lava_test_run_attach'] = LAVA_TEST_RUN_ATTACH
 Target.oe_deployment_data['lava_test_sh_cmd'] = '/bin/sh'
 Target.oe_deployment_data['lava_test_dir'] = '/lava'
 Target.oe_deployment_data['lava_test_results_part_attr'] = 'root_part'
@@ -527,7 +531,7 @@ 
 
         shcmd = target.deployment_data['lava_test_sh_cmd']
 
-        for key in ['lava_test_shell', 'lava_test_case_attach']:
+        for key in ['lava_test_shell', 'lava_test_case_attach', 'lava_test_run_attach']:
             fname = target.deployment_data[key]
             with open(fname, 'r') as fin:
                 with open('%s/bin/%s' % (mntdir, os.path.basename(fname)), 'w') as fout:

=== added file 'lava_test_shell/lava-test-run-attach'
--- lava_test_shell/lava-test-run-attach	1970-01-01 00:00:00 +0000
+++ lava_test_shell/lava-test-run-attach	2012-12-10 23:43:42 +0000
@@ -0,0 +1,34 @@ 
+#NOTE the lava_test_shell_action fills in the proper interpreter path
+# above during target deployment
+
+# basename is not present on AOSP builds, but the /*\// thing does not
+# work with dash (Ubuntu builds) or busybox (OpenEmbedded).  Both of
+# those have basename though.
+which basename > /dev/null || basename () { echo ${1/*\//}; }
+
+usage () {
+    echo "Usage: lava-test--attach FILE [MIME_TYPE]"
+    echo ""
+    echo "Attach FILE to the current test run."
+}
+
+FILE="$1"
+shift
+MIMETYPE="$1"
+shift
+if [ $# -gt 0 ]; then
+    usage
+    exit 1
+fi
+if [ ! -f "$FILE" ]; then
+    usage
+    exit 1
+fi
+
+# $LAVA_RESULT_DIR is set by lava-test-shell
+attachment_dir="$LAVA_RESULT_DIR/attachments"
+mkdir -p "$attachment_dir"
+cp "$FILE" "$attachment_dir"
+if [ ! -z "$MIMETYPE" ]; then
+    echo "$MIMETYPE" > "$attachment_dir/$(basename $FILE).mimetype"
+fi