Drop Travis CI support
	- Until all formulas are switched to new config
	  keep backwards compatibility
	- Once all formulas are switched to new config
	  old approach will be deprecated

Fixes: PROD-25037 (PROD:25037)

Change-Id: I262fa36b41ac6ad77512d58dcc45f04640e61f33
diff --git a/test-salt-formulas-env.groovy b/test-salt-formulas-env.groovy
index 486bd3a..257c0ab 100644
--- a/test-salt-formulas-env.groovy
+++ b/test-salt-formulas-env.groovy
@@ -24,7 +24,9 @@
 
 def checkouted = false
 def openstackTest = false
-def cleanEnv = ''
+def travisLess = false      /** TODO: Remove once formulas are witched to new config */
+def cleanEnv = ''           /** TODO: Remove once formulas are witched to new config */
+def testSuite = ''
 
 throttle(['test-formula']) {
   timeout(time: 1, unit: 'HOURS') {
@@ -43,69 +45,116 @@
           }
         }
         stage("kitchen") {
-          if (checkouted) {
-            if (fileExists(".kitchen.yml") || fileExists(".kitchen.openstack.yml")) {
-              if (fileExists(".kitchen.openstack.yml")) {
-                common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.")
-                if (fileExists(".kitchen.yml")) {
-                  common.infoMsg("Ignoring the docker Kitchen test configuration file.")
+          if (fileExists(".travis.yml")) {/** TODO: Remove this legacy block once formulas are witched to new config */
+            if (checkouted) {
+              if (fileExists(".kitchen.yml") || fileExists(".kitchen.openstack.yml")) {
+                if (fileExists(".kitchen.openstack.yml")) {
+                  common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.")
+                  if (fileExists(".kitchen.yml")) {
+                    common.infoMsg("Ignoring the docker Kitchen test configuration file.")
+                  }
+                  openstackTest = true
+                } else {
+                  common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.")
                 }
-                openstackTest = true
-              } else {
-                common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.")
-              }
-              ruby.ensureRubyEnv()
-              if (fileExists(".travis.yml")) {
-                common.infoMsg(".travis.yml found, running custom kitchen init")
-                def kitchenConfigYML = readYaml(file: ".travis.yml")
-                def kitchenInit = kitchenConfigYML["install"]
-                def kitchenInstalled = false
-                if (kitchenInit && !kitchenInit.isEmpty()) {
-                  for (int i = 0; i < kitchenInit.size(); i++) {
-                    if (kitchenInit[i].trim().startsWith("if [ ! -e Gemfile ]")) { //found Gemfile config
-                      common.infoMsg("Custom Gemfile configuration found, using them")
-                      if (openstackTest) {
-                        withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: openstack_credentials_id,
-                        usernameVariable: 'OS_USERNAME', passwordVariable: 'OS_PASSWORD'], ]) {
-                          env.OS_USERNAME = OS_USERNAME
-                          env.OS_PASSWORD = OS_PASSWORD
-                          env.OS_AUTH_URL = OS_AUTH_URL
-                          env.OS_PROJECT_NAME = OS_PROJECT_NAME
-                          env.OS_DOMAIN_NAME = OS_DOMAIN_NAME
-                          env.OS_AZ = OS_AZ
+                ruby.ensureRubyEnv()
+                if (fileExists(".travis.yml")) {
+                  common.infoMsg(".travis.yml found, running custom kitchen init")
+                  def kitchenConfigYML = readYaml(file: ".travis.yml")
+                  def kitchenInit = kitchenConfigYML["install"]
+                  def kitchenInstalled = false
+                  if (kitchenInit && !kitchenInit.isEmpty()) {
+                    for (int i = 0; i < kitchenInit.size(); i++) {
+                      if (kitchenInit[i].trim().startsWith("if [ ! -e Gemfile ]")) { //found Gemfile config
+                        common.infoMsg("Custom Gemfile configuration found, using them")
+                        if (openstackTest) {
+                          withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: openstack_credentials_id,
+                          usernameVariable: 'OS_USERNAME', passwordVariable: 'OS_PASSWORD'], ]) {
+                            env.OS_USERNAME = OS_USERNAME
+                            env.OS_PASSWORD = OS_PASSWORD
+                            env.OS_AUTH_URL = OS_AUTH_URL
+                            env.OS_PROJECT_NAME = OS_PROJECT_NAME
+                            env.OS_DOMAIN_NAME = OS_DOMAIN_NAME
+                            env.OS_AZ = OS_AZ
+                          }
                         }
+                        ruby.installKitchen(kitchenInit[i].trim())
+                        kitchenInstalled = true
                       }
-                      ruby.installKitchen(kitchenInit[i].trim())
-                      kitchenInstalled = true
                     }
                   }
-                }
-                if (!kitchenInstalled) {
+                  if (!kitchenInstalled) {
+                    ruby.installKitchen()
+                  }
+                } else {
+                  common.infoMsg(".travis.yml not found, running default kitchen init")
                   ruby.installKitchen()
                 }
-              } else {
-                common.infoMsg(".travis.yml not found, running default kitchen init")
-                ruby.installKitchen()
-              }
-              common.infoMsg("Running part of kitchen test")
-              if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
-                cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
-                if (openstackTest) { cleanEnv = "KITCHEN_YAML=.kitchen.openstack.yml " + cleanEnv }
-                sh("grep apt.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
-                sh("grep apt-mk.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
-                def suite = ruby.getSuiteName(KITCHEN_ENV)
-                if (suite && suite != "") {
-                  common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
-                  ruby.runKitchenTests(cleanEnv, suite)
+                common.infoMsg("Running part of kitchen test")
+                if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
+                  cleanEnv = KITCHEN_ENV.replaceAll("\\s?SUITE=[^\\s]*", "")
+                  if (openstackTest) { cleanEnv = "KITCHEN_YAML=.kitchen.openstack.yml " + cleanEnv }
+                  sh("grep apt.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
+                  sh("grep apt-mk.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
+                  def suite = ruby.getSuiteName(KITCHEN_ENV)
+                  if (suite && suite != "") {
+                    common.infoMsg("Running kitchen test with environment:" + KITCHEN_ENV.trim())
+                    ruby.runKitchenTests(cleanEnv, suite)
+                  } else {
+                    common.warningMsg("No SUITE was found. Running with all suites.")
+                    ruby.runKitchenTests(cleanEnv, "")
+                  }
                 } else {
-                  common.warningMsg("No SUITE was found. Running with all suites.")
-                  ruby.runKitchenTests(cleanEnv, "")
+                  throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
                 }
               } else {
-                throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
+                throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
               }
-            } else {
-              throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
+            }/** TODO: End of block for removal */
+          } else {
+            if (checkouted) {
+              travisLess = true
+              if (fileExists(".kitchen.yml") || fileExists(".kitchen.openstack.yml")) {
+                if (fileExists(".kitchen.openstack.yml")) {
+                  common.infoMsg("Openstack Kitchen test configuration found, running Openstack kitchen tests.")
+                  if (fileExists(".kitchen.yml")) {
+                    common.infoMsg("Ignoring the docker Kitchen test configuration file.")
+                  }
+                  openstackTest = true
+                  withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: openstack_credentials_id,
+                  usernameVariable: 'OS_USERNAME', passwordVariable: 'OS_PASSWORD'], ]) {
+                    env.OS_USERNAME = OS_USERNAME
+                    env.OS_PASSWORD = OS_PASSWORD
+                    env.OS_AUTH_URL = OS_AUTH_URL
+                    env.OS_PROJECT_NAME = OS_PROJECT_NAME
+                    env.OS_DOMAIN_NAME = OS_DOMAIN_NAME
+                    env.OS_AZ = OS_AZ
+                  }
+                } else {
+                  common.infoMsg("Docker Kitchen test configuration found, running Docker kitchen tests.")
+                }
+                ruby.ensureRubyEnv()
+                if (!fileExists("Gemfile")) {
+                  sh("curl -s -o ./Gemfile 'https://gerrit.mcp.mirantis.com/gitweb?p=salt-formulas/salt-formulas-scripts.git;a=blob_plain;f=Gemfile;hb=refs/heads/master'")
+                  ruby.installKitchen()
+                } else {
+                  common.infoMsg("Override Gemfile found in the kitchen directory, using it.")
+                  ruby.installKitchen()
+                }
+                common.infoMsg("Running part of kitchen test")
+                if (KITCHEN_ENV != null && !KITCHEN_ENV.isEmpty() && KITCHEN_ENV != "") {
+                  testSuite = KITCHEN_ENV.replaceAll("_", "-").trim()
+                  if (openstackTest) { testSuite = "KITCHEN_YAML=.kitchen.openstack.yml " + testSuite }
+                  sh("grep apt.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
+                  sh("grep apt-mk.mirantis.com -Ril | xargs -I{} bash -c \"echo {}; sed -i 's/apt-mk.mirantis.com/apt.mcp.mirantis.net/g' {}\"")
+                  common.infoMsg("Running kitchen test with environment:" + testSuite)
+                  ruby.runKitchenTests("", testSuite)
+                } else {
+                  throw new Exception("KITCHEN_ENV parameter is empty or invalid. This may indicate wrong env settings of initial test job or .travis.yml file.")
+                }
+              } else {
+                throw new Exception(".kitchen.yml file not found, no kitchen tests triggered.")
+              }
             }
           }
         }
@@ -113,7 +162,11 @@
         // If there was an error or exception thrown, the build failed
         currentBuild.result = "FAILURE"
         sh(script: 'find .kitchen/logs/ -type f -iname "*.log" | xargs -I{} bash -c "echo {}; cat {}"')
-        ruby.runKitchenCommand("destroy", cleanEnv)
+        if (travisLess) {
+          ruby.runKitchenCommand("destroy", testSuite)
+        } else {
+          ruby.runKitchenCommand("destroy", cleanEnv)  /** TODO: Remove once formulas are witched to new config */
+        }
         throw e
       } finally {
         if (currentBuild.result == "FAILURE" && fileExists(".kitchen/logs/kitchen.log")) {