Merge "Check that docker container exists/running before deleting/killing it"
diff --git a/src/com/mirantis/mk/SaltModelTesting.groovy b/src/com/mirantis/mk/SaltModelTesting.groovy
index 148cb6f..c7afbb0 100644
--- a/src/com/mirantis/mk/SaltModelTesting.groovy
+++ b/src/com/mirantis/mk/SaltModelTesting.groovy
@@ -171,16 +171,16 @@
     }
 
     try {
-        common.warningMsg("IgnoreMe:Force cleanup slave.Ignore docker-daemon errors")
-        timeout(time: 10, unit: 'SECONDS') {
-            sh(script: "set -x; docker kill ${dockerContainerName} || true", returnStdout: true)
-        }
-        timeout(time: 10, unit: 'SECONDS') {
-            sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true)
+        timeout(time: 30, unit: 'SECONDS') {
+          if (sh(script: "docker inspect ${dockerContainerName}", returnStatus: true) == 0) {
+              common.warningMsg("Verify that container is not running. Ignore further docker-daemon errors")
+              sh(script: "set -x; test \$(docker inspect -f '{{.State.Running}}' ${dockerContainerName} 2>/dev/null) = 'true' && docker kill ${dockerContainerName}", returnStdout: true)
+              sh(script: "set -x; docker rm --force ${dockerContainerName} || true", returnStdout: true)
+          }
         }
     }
     catch (Exception er) {
-        common.warningMsg("IgnoreMe:Timeout to delete test docker container with force!Message:\n" + er.toString())
+        common.warningMsg("IgnoreMe:Timeout to delete test docker container with force! Message:\n" + er.toString())
     }
 
     if (TestMarkerResult) {