Merge "Star p4runtime shell in verbose mode, exit if shell fails to connect"
diff --git a/TestON/docker/Dockerfile b/TestON/docker/Dockerfile
index 5ad5d52..2c43893 100644
--- a/TestON/docker/Dockerfile
+++ b/TestON/docker/Dockerfile
@@ -51,9 +51,14 @@
     mkdir -p /var/run/sshd && \
     mkdir -p /var/log/supervisor && \
     useradd -m jenkins && \
+    chmod 777 /tmp && \
     chsh -s /bin/bash jenkins && \
     echo jenkins:jenkins | chpasswd
 
+RUN curl -sS --fail "https://repo1.maven.org/maven2/org/onosproject/onos-releases/2.5.4/onos-admin-2.5.4.tar.gz" | tar zx && \
+    mv onos-admin-2.5.4/* /usr/local/bin/ && \
+    rm -r onos-admin-2.5.4
+
 ENV PYTHONPATH=${TREX_EXT_LIBS}:${TREX_LIBS}
 # TODO: should we parametrize those?
 ENV OC1=localhost
diff --git a/TestON/tests/USECASE/SegmentRouting/QOS/QOS.py b/TestON/tests/USECASE/SegmentRouting/QOS/QOS.py
index 1b20ce8..6f05db0 100644
--- a/TestON/tests/USECASE/SegmentRouting/QOS/QOS.py
+++ b/TestON/tests/USECASE/SegmentRouting/QOS/QOS.py
@@ -83,4 +83,5 @@
         main.step("Teardown")
         trex.teardown()
         up4.teardown()
+        run.saveOnosDiagsIfFailure(main)
         run.cleanup(main)
diff --git a/TestON/tests/USECASE/SegmentRouting/QOSNonMobile/dependencies/QOSNonMobileTest.py b/TestON/tests/USECASE/SegmentRouting/QOSNonMobile/dependencies/QOSNonMobileTest.py
index 9a52313..45e9d8c 100644
--- a/TestON/tests/USECASE/SegmentRouting/QOSNonMobile/dependencies/QOSNonMobileTest.py
+++ b/TestON/tests/USECASE/SegmentRouting/QOSNonMobile/dependencies/QOSNonMobileTest.py
@@ -175,6 +175,7 @@
 
         main.step("Teardown")
         trex.teardown()
+        run.saveOnosDiagsIfFailure(main)
         run.cleanup(main)
 
     def __cleanupTrafficSelector(self, traffic_selector):
diff --git a/TestON/tests/USECASE/SegmentRouting/UP4/UP4.py b/TestON/tests/USECASE/SegmentRouting/UP4/UP4.py
index 1395671..456a6b5 100644
--- a/TestON/tests/USECASE/SegmentRouting/UP4/UP4.py
+++ b/TestON/tests/USECASE/SegmentRouting/UP4/UP4.py
@@ -62,6 +62,8 @@
 
         main.step("Stop scapy and p4rt client")
         up4.teardown()
+
+        run.saveOnosDiagsIfFailure(main)
         run.cleanup(main)
 
     def CASE2(self, main):
@@ -256,6 +258,8 @@
         main.step("Stop scapy and p4rt client")
         up4.teardown()
         bess_host.stopScapy()
+
+        run.saveOnosDiagsIfFailure(main)
         run.cleanup(main)
 
     def CASE3(self, main):
@@ -380,6 +384,8 @@
             onfail="ONOS instances have different number of flows: (%d, %d, %d)" % (
                 onos_0_flow_count, onos_1_flow_count, onos_2_flow_count)
         )
+
+        run.saveOnosDiagsIfFailure(main)
         run.cleanup(main)
 
     def CASE4(self, main):
@@ -432,6 +438,14 @@
         )
 
         onosPod = main.params["UP4_delete_pod"]
+
+        # Save ONOS diags of the POD we are killing otherwise we lose ONOS logs
+        main.ONOSbench.onosDiagnosticsK8s(
+            [onosPod],
+            main.logdir,
+            "-CASE%d-%s_BeforeKill" % (main.CurrentTestCaseNumber, onosPod)
+        )
+
         # Exit from previous port forwarding, because we need to restore
         # port-forwarding after ONOS reboot.
         kubectl_0.clearBuffer()
@@ -575,4 +589,5 @@
 
         run.checkFlows(main, minFlowCount=initial_flow_count)
 
+        run.saveOnosDiagsIfFailure(main)
         run.cleanup(main)
diff --git a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
index 3aba8fc..59466be 100644
--- a/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
+++ b/TestON/tests/USECASE/SegmentRouting/dependencies/Testcaselib.py
@@ -2005,3 +2005,9 @@
         utilities.assert_equals( expect=True, actual=logging,
                                  onpass="Reset log levels",
                                  onfail="Failed to reset log levels" )
+
+    @staticmethod
+    def saveOnosDiagsIfFailure( main ):
+        if main.FALSE in main.stepResultsList:
+            # Some step has failed
+            Testcaselib.saveOnosDiagnostics( main )