blob: 7cf8e2821f2350128f33e014603c799705913256 [file] [log] [blame]
Oleksii Zhurba71e97882018-02-16 20:09:43 -06001/**
2 *
3 * Launch pytest frameworks in Jenkins
4 *
5 * Expected parameters:
6 * SALT_MASTER_URL URL of Salt master
7 * SALT_MASTER_CREDENTIALS Credentials to the Salt API
8 *
9 * TESTS_SET Leave empty for full run or choose a file (test)
10 * TESTS_REPO Repo to clone
11 * TESTS_SETTINGS Additional environment varibales to apply
12 * PROXY Proxy to use for cloning repo or for pip
Oleksii Zhurbad9034952018-09-03 21:06:06 -050013 * TEST_IMAGE Docker image link or name to use for running container with test framework.
14 * DEBUG_MODE If you need to debug (keep container after test), please enabled this
Oleksii Zhurba71e97882018-02-16 20:09:43 -060015 *
16 */
17
Oleksii Zhurbad9034952018-09-03 21:06:06 -050018common = new com.mirantis.mk.Common()
Oleksii Zhurba71e97882018-02-16 20:09:43 -060019validate = new com.mirantis.mcp.Validate()
Oleksii Zhurbad9034952018-09-03 21:06:06 -050020salt = new com.mirantis.mk.Salt()
Oleksii Zhurba71e97882018-02-16 20:09:43 -060021def artifacts_dir = 'validation_artifacts/'
Oleksii Zhurbad9034952018-09-03 21:06:06 -050022def remote_dir = '/root/qa_results/'
23def container_workdir = '/var/lib'
24def TARGET_NODE = "I@gerrit:client"
25def reinstall_env = false
26def container_name = "${env.JOB_NAME}"
27def saltMaster
28def settings
Oleksii Zhurba71e97882018-02-16 20:09:43 -060029
30node() {
31 try{
32 stage('Initialization') {
Oleksii Zhurbad9034952018-09-03 21:06:06 -050033 sh "rm -rf ${artifacts_dir}"
34 if ( TESTS_SETTINGS != "" ) {
35 for (var in TESTS_SETTINGS.tokenize(";")) {
36 key = var.tokenize("=")[0].trim()
37 value = var.tokenize("=")[1].trim()
38 if (key == 'TARGET_NODE') {
39 TARGET_NODE = value
40 common.infoMsg("Node for container is set to ${TARGET_NODE}")
41 }
42 if (key == 'REINSTALL_ENV') {
43 reinstall_env = value.toBoolean()
44 }
45 }
46 }
47 if ( IMAGE == "" ) {
48 common.infoMsg("Env for tests will be built on Jenkins slave")
49 TARGET_NODE = ""
50 validate.prepareVenv(TESTS_REPO, PROXY)
51 } else {
52 saltMaster = salt.connection(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS)
53 salt.cmdRun(saltMaster, TARGET_NODE, "rm -rf ${remote_dir}")
54 salt.cmdRun(saltMaster, TARGET_NODE, "mkdir -p ${remote_dir}")
55 validate.runContainer(saltMaster, TARGET_NODE, IMAGE, container_name)
56 if ( TESTS_REPO != "") {
57 salt.cmdRun(saltMaster, TARGET_NODE, "docker exec ${container_name} rm -rf ${container_workdir}/cvp*")
58 salt.cmdRun(saltMaster, TARGET_NODE, "docker exec ${container_name} git clone ${TESTS_REPO} ${container_workdir}/${container_name}")
59 TESTS_SET = container_workdir + '/' + container_name + '/' + TESTS_SET
60 if ( reinstall_env ) {
61 common.infoMsg("Pip packages in container will be reinstalled based on requirements.txt from ${TESTS_REPO}")
62 salt.cmdRun(saltMaster, TARGET_NODE, "docker exec ${container_name} pip install --force-reinstall -r ${container_workdir}/${container_name}/requirements.txt")
63 }
64 }
65 }
Oleksii Zhurba71e97882018-02-16 20:09:43 -060066 }
67
68 stage('Run Tests') {
69 sh "mkdir -p ${artifacts_dir}"
Oleksii Zhurbad9034952018-09-03 21:06:06 -050070 validate.runPyTests(SALT_MASTER_URL, SALT_MASTER_CREDENTIALS, TESTS_SET, TESTS_SETTINGS.tokenize(";"), container_name, TARGET_NODE, remote_dir, artifacts_dir)
Oleksii Zhurba71e97882018-02-16 20:09:43 -060071 }
Oleksii Zhurbad9034952018-09-03 21:06:06 -050072
Oleksii Zhurba71e97882018-02-16 20:09:43 -060073 stage ('Publish results') {
74 archiveArtifacts artifacts: "${artifacts_dir}/*"
75 junit "${artifacts_dir}/*.xml"
Oleksii Zhurbad9034952018-09-03 21:06:06 -050076 if (env.JOB_NAME.contains("cvp-spt")) {
77 plot csvFileName: 'plot-8634d2fe-dc48-4713-99f9-b69a381483aa.csv',
78 group: 'SPT',
79 style: 'line',
80 title: 'SPT Glance results',
81 xmlSeries: [[
82 file: "${env.JOB_NAME}_report.xml",
83 nodeType: 'NODESET',
84 url: '',
85 xpath: '/testsuite/testcase[@name="test_speed_glance"]/properties/property']]
86 plot csvFileName: 'plot-8634d2fe-dc48-4713-99f9-b69a381483bb.csv',
87 group: 'SPT',
88 style: 'line',
89 title: 'SPT HW2HW results',
90 xmlSeries: [[
91 file: "${env.JOB_NAME}_report.xml",
92 nodeType: 'NODESET',
93 url: '',
94 xpath: '/testsuite/testcase[@classname="cvp_spt.tests.test_hw2hw"]/properties/property']]
95 plot csvFileName: 'plot-8634d2fe-dc48-4713-99f9-b69a381483bc.csv',
96 group: 'SPT',
97 style: 'line',
98 title: 'SPT VM2VM results',
99 xmlSeries: [[
100 file: "${env.JOB_NAME}_report.xml",
101 nodeType: 'NODESET',
102 url: '',
103 xpath: '/testsuite/testcase[@classname="cvp_spt.tests.test_vm2vm"]/properties/property']]
104 }
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600105 }
106 } catch (Throwable e) {
107 // If there was an error or exception thrown, the build failed
108 currentBuild.result = "FAILURE"
109 throw e
Oleksii Zhurbad9034952018-09-03 21:06:06 -0500110 } finally {
111 if (DEBUG_MODE == 'false') {
112 validate.runCleanup(saltMaster, TARGET_NODE, container_name)
113 salt.cmdRun(saltMaster, TARGET_NODE, "rm -rf ${remote_dir}")
114 }
Oleksii Zhurba71e97882018-02-16 20:09:43 -0600115 }
116}