blob: 6acadb992bfad8a018345d53f0bace6c140617a5 [file] [log] [blame]
Dmitry Tyzhnenko1f614e12017-07-20 17:34:36 +03001/*
2 *
3 * Launcher for TCP-QA tests
4 *
5 * Expected parameters:
6 * ENV_NAME Environment name
7 * REPOSITORY_SUITE Packagfe repository (stable, testing, nightly)
8 * TEST_GROUP TCQ-QA test group or a test name
9 * LAB_CONFIG_NAME Environment confguration for deploy
10 * ADDITIONAL_PARAMETERS Additional shell environment variables
11 * TCP_QA_COMMIT TCQ-QA commit or branch
12 * TCP_QA_REFS TCP-QA refs for cherry-pick
13 * TCP_QA_GERRIT_HOST TCQ-QA repo Gerrit host
14 * SHUTDOWN_ENV_ON_TEARDOWN Destroy virtual environment after test run
15 * KEEP_BEFORE Keep virtual environment before run tests or erase it
16 * KEEP_AFTER Keep virtual environment after run tests or erase it
17 * VENV_PATH Path to python virtual environment
18 * SLAVE_LABELS Jenkins slave node labels
19 * TEST_TIMEOUT Timeout for test job in minutes
20 * UPLOAD_RESULTS Upload or not test results to Testrail
21 * TESTRAIL_MILESTONE Testrail milestone
22 * TESTRAIL_TEST_SUITE Testrail test suite
23 *
24 */
25
26git = new com.mirantis.mcp.Git()
27qaCommon = new com.mirantis.tcp_qa.Common()
28testRunner = new com.mirantis.tcp_qa.RunTest()
29environment = new com.mirantis.tcp_qa.EnvActions()
30
31def runTests() {
32 def additionalParameters = []
33
34 if (!env.ENV_NAME) {
35 error("Error! Test path (ENV_NAME) is not specified!")
36 }
37
38 if (!env.REPOSITORY_SUITE) {
39 error("Error! Test path (REPOSITORY_SUITE) is not specified!")
40 }
41 if (!env.TEST_GROUP){
42 error("Error! Test path (TEST_GROUP) is not specified!")
43 }
44 if (!env.LAB_CONFIG_NAME){
45 error("Error! Test path (LAB_CONFIG_NAME) is not specified!")
46 }
47
48 if (params.ADDITIONAL_PARAMETERS) {
49 for (p in params.ADDITIONAL_PARAMETERS.split('\n')) {
50 additionalParameters << p
51 }
52 echo("Additional parameters are: ${additionalParameters.join(' ')}")
53 }
54
55 withEnv(additionalParameters) {
56
57 stage('Clone tcp-qa') {
58 git.gitCheckout ([
59 protocol: 'https',
60 port: '443',
61 branch : env.TCP_QA_COMMIT,
62 host : 'github.com',
63 project : 'Mirantis/tcp-qa',
64 targetDir : '.'
65 ])
66 if ( env.TCP_QA_REFS && ! env.TCP_QA_REFS.equals('none') ) {
67 def refs = "${env.TCP_QA_REFS}".split("\n")
68 qaCommon.getCustomRefs(env.TCP_QA_GERRIT_HOST, 'Mirantis/tcp-qa', env.WORKSPACE, refs)
69 }
70 }
71
72 stage('Update python venv') {
73 environment.prepareEnv()
74 }
75
76 stage('Run tests') {
77 if (!((env.KEEP_BEFORE == "yes") || (env.KEEP_BEFORE == "true"))){
78 environment.eraseEnv()
79 }
80 sh """
81 . ${VENV_PATH}/bin/activate
82
83 cd tcp_tests
Dmitry Tyzhnenko85dbfcd2017-08-22 13:07:21 +030084 if ! py.test -vvv -s -p no:django -p no:ipdb --junit-xml=../nosetests.xml -k ${TEST_GROUP}; then
Dmitry Tyzhnenko1f614e12017-07-20 17:34:36 +030085 echo "Tests failed!"
86 exit 1
87 fi
88 """
89
90 // testRunner.runTest("-k ${env.TEST_GROUP}", jobSetParameters)
91 }
92
93 if (!((env.KEEP_AFTER == "yes") || (env.KEEP_AFTER == "true"))){
94 environment.eraseEnv()
95 }
96 }
97}
98
99def uploadResults(){
100 stage('Upload tests results'){
Dmitry Tyzhnenko85dbfcd2017-08-22 13:07:21 +0300101 def thisBuildUrl = "${JENKINS_URL}/job/${JOB_NAME}/${BUILD_NUMBER}/"
102 def testPlanName = "${TESTRAIL_MILESTONE} Integration-${new Date().format('yyyy-MM-dd')}"
Dmitry Tyzhnenko1f614e12017-07-20 17:34:36 +0300103
104 qaCommon.uploadResultsTestRail([
Dmitry Tyzhnenko85dbfcd2017-08-22 13:07:21 +0300105 junitXml: "${WORKSPACE}/nosetests.xml",
Dmitry Tyzhnenko1f614e12017-07-20 17:34:36 +0300106 testPlanName: testPlanName,
Dmitry Tyzhnenko85dbfcd2017-08-22 13:07:21 +0300107 testSuiteName: "${TESTRAIL_TEST_SUITE}",
108 testrailMilestone: "${TESTRAIL_MILESTONE}",
Dmitry Tyzhnenko1f614e12017-07-20 17:34:36 +0300109 jobURL: thisBuildUrl,
110 ])
111 }
112}
113
114def runSlavesLabels = params.SLAVE_LABELS ?: 'tcp-qa-slaves'
115def runTimeout = params.TEST_TIMEOUT ?: 240
Jakub Josefa63f9862018-01-11 17:58:38 +0100116timeout(time: 12, unit: 'HOURS') {
117 node (runSlavesLabels) {
118 try {
119 timeout(time: runTimeout.toInteger(), unit: 'MINUTES') {
120 runTests()
121 }
Dmitry Tyzhnenko1f614e12017-07-20 17:34:36 +0300122 }
Jakub Josefa63f9862018-01-11 17:58:38 +0100123 catch (err) {
124 echo "Failed: ${err}"
125 currentBuild.result = 'FAILURE'
126 }
127 finally {
128 if (env.UPLOAD_RESULTS == "true") {
129 testRunUrl = uploadResults()
130 currentBuild.description = """
131 <a href="${testRunUrl}">TestRail report</a>
132 """
133 }
134 environment.destroyEnv()
135 archiveArtifacts allowEmptyArchive: true, artifacts: 'nosetests.xml,tests.log,*.ini', excludes: null
136 junit keepLongStdio: false, testResults: 'nosetests.xml'
137 }
Dmitry Tyzhnenko1f614e12017-07-20 17:34:36 +0300138 }
139}