Save per-test container logs on failure

Change-Id: I289b60e535a9c0c849785d08343c77601dca9948
diff --git a/libraries/utils.robot b/libraries/utils.robot
index 017b308..6aab95a 100644
--- a/libraries/utils.robot
+++ b/libraries/utils.robot
@@ -313,6 +313,22 @@
     Run Process    kubectl    run    announcer    -ti    --rm    --restart    Never    --image    ubuntu
     ...     bash    --    -c    echo; sleep 1; echo ${message}; sleep 1; date --rfc-3339\=n ; sleep 1; echo; sleep 1
 
+Start Logging
+    [Arguments]    ${label}
+    [Documentation]    Start logging for test ${label}
+    ${kail_process}=     Run Keyword If    "${container_log_dir}" != "${None}"   Start Process    kail    -n    default
+    ...    -n    voltha    cwd=${container_log_dir}   stdout=${label}-combined.log
+    Set Test Variable    ${kail_process}
+
+Stop Logging
+    [Arguments]    ${label}
+    [Documentation]    End logging for test; remove logfile if test passed
+    Run    sync
+    Run Keyword If    ${kail_process}    Terminate Process    ${kail_process}
+    ${test_logfile}=    Run Keyword If    "${container_log_dir}" != "${None}"
+    ...    Join Path    ${container_log_dir}    ${label}-combined.log
+    Run Keyword If Test Passed    Run Keyword If    "${test_logfile}" != "${None}"    Remove File    ${test_logfile}
+
 Clean Up Linux
     [Documentation]    Kill processes and clean up interfaces on src+dst servers
     FOR    ${I}    IN RANGE    0    ${num_onus}