Merge "Move SALT_OVERRIDES right after stack created"
diff --git a/cloud-deploy-pipeline.groovy b/cloud-deploy-pipeline.groovy
index 86036ca..e38e555 100644
--- a/cloud-deploy-pipeline.groovy
+++ b/cloud-deploy-pipeline.groovy
@@ -49,6 +49,7 @@
  *   SALT_OVERRIDES              YAML with overrides for Salt deployment
  *
  */
+
 common = new com.mirantis.mk.Common()
 git = new com.mirantis.mk.Git()
 openstack = new com.mirantis.mk.Openstack()
@@ -82,7 +83,6 @@
                 if (STACK_TYPE == 'heat') {
                     // value defaults
                     def openstackCloud
-                    def openstackVersion = OPENSTACK_API_CLIENT ? OPENSTACK_API_CLIENT : 'liberty'
 
                     if (STACK_REUSE.toBoolean() == true && STACK_NAME == '') {
                         error("If you want to reuse existing stack you need to provide it's name")
@@ -107,7 +107,7 @@
                     git.checkoutGitRepository('template', STACK_TEMPLATE_URL, STACK_TEMPLATE_BRANCH, STACK_TEMPLATE_CREDENTIALS)
 
                     // create openstack env
-                    openstack.setupOpenstackVirtualenv(venv, openstackVersion)
+                    openstack.setupOpenstackVirtualenv(venv, OPENSTACK_API_CLIENT)
                     openstackCloud = openstack.createOpenstackEnv(
                         OPENSTACK_API_URL, OPENSTACK_API_CREDENTIALS,
                         OPENSTACK_API_PROJECT, OPENSTACK_API_PROJECT_DOMAIN,
diff --git a/tcp-qa-pipeline.groovy b/tcp-qa-pipeline.groovy
new file mode 100644
index 0000000..1b178b4
--- /dev/null
+++ b/tcp-qa-pipeline.groovy
@@ -0,0 +1,138 @@
+/*
+ *
+ * Launcher for TCP-QA tests
+ *
+ * Expected parameters:
+ *   ENV_NAME                 Environment name
+ *   REPOSITORY_SUITE         Packagfe repository (stable, testing, nightly)
+ *   TEST_GROUP               TCQ-QA test group or a test name
+ *   LAB_CONFIG_NAME          Environment confguration for deploy
+ *   ADDITIONAL_PARAMETERS    Additional shell environment variables
+ *   TCP_QA_COMMIT            TCQ-QA commit or branch
+ *   TCP_QA_REFS              TCP-QA refs for cherry-pick
+ *   TCP_QA_GERRIT_HOST       TCQ-QA repo Gerrit host
+ *   SHUTDOWN_ENV_ON_TEARDOWN Destroy virtual environment after test run
+ *   KEEP_BEFORE              Keep virtual environment before run tests or erase it
+ *   KEEP_AFTER               Keep virtual environment after run tests or erase it
+ *   VENV_PATH                Path to python virtual environment
+ *   SLAVE_LABELS             Jenkins slave node labels
+ *   TEST_TIMEOUT             Timeout for test job in minutes
+ *   UPLOAD_RESULTS           Upload or not test results to Testrail
+ *   TESTRAIL_MILESTONE       Testrail milestone
+ *   TESTRAIL_TEST_SUITE      Testrail test suite
+ *
+ */
+
+git = new com.mirantis.mcp.Git()
+qaCommon = new com.mirantis.tcp_qa.Common()
+testRunner = new com.mirantis.tcp_qa.RunTest()
+environment = new com.mirantis.tcp_qa.EnvActions()
+
+def runTests() {
+    def additionalParameters = []
+
+    if (!env.ENV_NAME) {
+        error("Error! Test path (ENV_NAME) is not specified!")
+    }
+
+    if (!env.REPOSITORY_SUITE) {
+        error("Error! Test path (REPOSITORY_SUITE) is not specified!")
+    }
+    if (!env.TEST_GROUP){
+        error("Error! Test path (TEST_GROUP) is not specified!")
+    }
+    if (!env.LAB_CONFIG_NAME){
+        error("Error! Test path (LAB_CONFIG_NAME) is not specified!")
+    }
+
+    if (params.ADDITIONAL_PARAMETERS) {
+        for (p in params.ADDITIONAL_PARAMETERS.split('\n')) {
+            additionalParameters << p
+        }
+        echo("Additional parameters are: ${additionalParameters.join(' ')}")
+    }
+
+    withEnv(additionalParameters) {
+
+        stage('Clone tcp-qa') {
+            git.gitCheckout ([
+                protocol: 'https',
+                port: '443',
+                branch : env.TCP_QA_COMMIT,
+                host : 'github.com',
+                project : 'Mirantis/tcp-qa',
+                targetDir : '.'
+            ])
+            if ( env.TCP_QA_REFS && ! env.TCP_QA_REFS.equals('none') ) {
+                def refs = "${env.TCP_QA_REFS}".split("\n")
+                qaCommon.getCustomRefs(env.TCP_QA_GERRIT_HOST, 'Mirantis/tcp-qa', env.WORKSPACE, refs)
+            }
+        }
+
+        stage('Update python venv') {
+            environment.prepareEnv()
+        }
+
+        stage('Run tests') {
+            if (!((env.KEEP_BEFORE == "yes") || (env.KEEP_BEFORE == "true"))){
+                environment.eraseEnv()
+            }
+            sh """
+            . ${VENV_PATH}/bin/activate
+
+            cd tcp_tests
+            if ! py.test -vvv -s -p no:django -p no:ipdb --junit-xml=nosetests.xml -k ${TEST_GROUP}; then
+              echo "Tests failed!"
+              exit 1
+            fi
+            """
+
+            // testRunner.runTest("-k ${env.TEST_GROUP}", jobSetParameters)
+        }
+
+        if (!((env.KEEP_AFTER == "yes") || (env.KEEP_AFTER == "true"))){
+            environment.eraseEnv()
+        }
+    }
+}
+
+def uploadResults(){
+    stage('Upload tests results'){
+        def thisBuildUrl = "${env.JENKINS_URL}/job/${JOB_NAME}/${BUILD_NUMBER}/"
+        def testPlanName = "${env.TESTRAIL_MILESTONE} Integration-${new Date().format('yyyy-MM-dd')}"
+
+        qaCommon.uploadResultsTestRail([
+            junitXml: "${env.WORKSPACE}/nosetests.xml",
+            testPlanName: testPlanName,
+            testSuiteName: "${env.TESTRAIL_TEST_SUITE}",
+            testrailMilestone: "${env.TESTRAIL_MILESTONE}",
+            jobURL: thisBuildUrl,
+        ])
+    }
+}
+
+def runSlavesLabels = params.SLAVE_LABELS ?: 'tcp-qa-slaves'
+def runTimeout = params.TEST_TIMEOUT ?: 240
+
+node (runSlavesLabels) {
+    try {
+      timeout(time: runTimeout.toInteger(), unit: 'MINUTES') {
+        runTests()
+      }
+    }
+    catch (err) {
+        echo "Failed: ${err}"
+        currentBuild.result = 'FAILURE'
+    }
+    finally {
+        if (env.UPLOAD_RESULTS == "true") {
+            testRunUrl = uploadResults()
+            currentBuild.description = """
+            <a href="${testRunUrl}">TestRail report</a>
+            """
+        }
+        environment.destroyEnv()
+        archiveArtifacts allowEmptyArchive: true, artifacts: 'nosetests.xml,tests.log,*.ini', excludes: null
+        junit keepLongStdio: false, testResults: 'nosetests.xml'
+    }
+}
diff --git a/test-openstack-component-pipeline.groovy b/test-openstack-component-pipeline.groovy
new file mode 100644
index 0000000..d3504d3
--- /dev/null
+++ b/test-openstack-component-pipeline.groovy
@@ -0,0 +1,31 @@
+/**
+
+ * Launch system tests against new package.
+
+ * Flow parameters:
+ *   CREDENTIALS_ID
+ *   EXTRA_FORMULAS
+ *   FORMULAS_REVISION
+ *   FORMULAS_SOURCE
+ *   SALT_OPTS
+ *   STACK_DEPLOY_JOB
+
+**/
+def common = new com.mirantis.mk.Common()
+def gerrit = new com.mirantis.mk.Gerrit()
+
+
+timestamps {
+    node {
+        def cred = common.getCredentials(CREDENTIALS_ID, 'key')
+        def gerritChange = gerrit.getGerritChange(cred.username, GERRIT_HOST, GERRIT_CHANGE_NUMBER, CREDENTIALS_ID, true)
+
+        stage('Trigger deploy job') {
+            build(job: STACK_DEPLOY_JOB, parameters: [
+                [$class: 'StringParameterValue', name: 'OPENSTACK_API_PROJECT', value: 'mcp-oscore'],
+                [$class: 'StringParameterValue', name: 'STACK_TEST', value: ''],
+                [$class: 'BooleanParameterValue', name: 'TEST_DOCKER_INSTALL', value: false]
+            ])
+        }
+    }
+}