forked from Mirantis/mk-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvp-runner.groovy
145 lines (133 loc) · 5.79 KB
/
cvp-runner.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
*
* Launch pytest frameworks in Jenkins
*
* Expected parameters:
* SALT_MASTER_URL URL of Salt master
* SALT_MASTER_CREDENTIALS Credentials to the Salt API
* IMAGE Docker image link to use for running container with test framework.
* EXTRA_PARAMS Yaml context which contains additional setting for job
*
*/
common = new com.mirantis.mk.Common()
validate = new com.mirantis.mcp.Validate()
salt_testing = new com.mirantis.mk.SaltModelTesting()
def EXTRA_PARAMS = readYaml(text: env.getProperty('EXTRA_PARAMS')) ?: [:]
def env_vars = EXTRA_PARAMS.get("envs") ?: []
def override_config = env.getProperty('EXTRA_PARAMS') ?: ""
def IMAGE = (env.getProperty('IMAGE')) ?: 'docker-prod-local.docker.mirantis.net/mirantis/cvp/cvp-sanity-checks:stable'
def SLAVE_NODE = (env.getProperty('SLAVE_NODE')) ?: 'docker'
/*
YAML example
=====
# commands is a map of commands which looks like step_name: shell_command
commands:
001_prepare: rm /var/lib/g.txt
002_prepare: git clone http://repo_with_tests.git
003_test: cd repo_with_tests && pytest /var/lib/ --collect-only
004_collect: cp cvp-spt /var/lib/validation_artifacts/
# envs is a list of new environment variables
envs:
- SALT_USERNAME=admin
- SALT_PASSWORD=password
- drivetrain_version=testing
*/
node (SLAVE_NODE) {
def artifacts_dir = 'validation_artifacts'
def test_suite_name = "${env.JOB_NAME}"
def xml_file = "${test_suite_name}_report.xml"
def configRun = [:]
try {
withEnv(env_vars) {
stage('Initialization') {
def container_workdir = '/var/lib'
def tests_set = (env.getProperty('tests_set')) ?: ''
def script = "pytest --junitxml ${container_workdir}/${artifacts_dir}/${xml_file} -vv ${tests_set}"
sh "mkdir -p ${artifacts_dir}"
// Enrichment for docker commands
def commands = EXTRA_PARAMS.get("commands") ?: ['010_start_tests': "tox -e ${test_suite_name} -- ${script}"]
def commands_list = commands.collectEntries{ [ (it.key) : { sh("${it.value}") } ] }
// Enrichment for env variables
def creds = common.getCredentials(SALT_MASTER_CREDENTIALS)
def env_vars_list = [
"SALT_USERNAME=${creds.username}",
"SALT_PASSWORD=${creds.password}",
"SALT_URL=${SALT_MASTER_URL}",
"REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt",
"OVERRIDE_CONFIG=${override_config}"
] + env_vars
// Generating final config
def force_pull = (env.getProperty('force_pull')) ?: false
configRun = [
'image': IMAGE,
'dockerPull': force_pull.toBoolean(),
'baseRepoPreConfig': false,
'dockerMaxCpus': 2,
'dockerExtraOpts' : [
"--network=host",
"-v /root/qa_results/:/root/qa_results/",
"-v /etc/ssl/certs/:/etc/ssl/certs/:ro",
"-v ${env.WORKSPACE}/${artifacts_dir}/:${container_workdir}/${artifacts_dir}/",
],
'envOpts' : env_vars_list,
'runCommands' : commands_list
]
}
stage('Run Tests') {
salt_testing.setupDockerAndTest(configRun)
}
stage ('Publish results') {
archiveArtifacts artifacts: "${artifacts_dir}/*"
junit "${artifacts_dir}/*.xml"
if (env.JOB_NAME.contains("cvp-spt")) {
plot csvFileName: 'plot-glance.csv',
group: 'SPT',
style: 'line',
title: 'SPT Glance results',
xmlSeries: [[
file: "${artifacts_dir}/${xml_file}",
nodeType: 'NODESET',
url: '',
xpath: '/testsuites/testsuite/testcase[@classname="tests.test_glance"]/properties/property']]
plot csvFileName: 'plot-hw2hw.csv',
group: 'SPT',
style: 'line',
title: 'SPT HW2HW results',
xmlSeries: [[
file: "${artifacts_dir}/${xml_file}",
nodeType: 'NODESET',
url: '',
xpath: '/testsuites/testsuite/testcase[@classname="tests.test_hw2hw"]/properties/property']]
plot csvFileName: 'plot-vm2vm.csv',
group: 'SPT',
style: 'line',
title: 'SPT VM2VM results',
xmlSeries: [[
file: "${artifacts_dir}/${xml_file}",
nodeType: 'NODESET',
url: '',
xpath: '/testsuites/testsuite/testcase[@classname="tests.test_vm2vm"]/properties/property']]
}
try {
sh """
for i in ${artifacts_dir}/*.xml; do
grep 'failures="0"' \$i
grep 'errors="0"' \$i
done
"""
} catch(err) {
currentBuild.result = "FAILURE"
common.errorMsg("[ERROR] Failures or errors is not zero in ${artifacts_dir}/*.xml")
throw err
}
}
}
}
catch (Throwable e) {
currentBuild.result = "FAILURE"
throw e
}
finally {
sh "rm -rf ${artifacts_dir}"
}
}