forked from SUSE/susemanager-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuyuni-master-dev-acceptance-tests-code-coverage
More file actions
166 lines (146 loc) · 12.4 KB
/
uyuni-master-dev-acceptance-tests-code-coverage
File metadata and controls
166 lines (146 loc) · 12.4 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env groovy
node('sumaform-cucumber-slc1') {
properties([
buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '1')),
pipelineTriggers([cron('0 0 * * 7')]),
disableConcurrentBuilds(),
parameters([
string(name: 'cucumber_gitrepo', defaultValue: 'https://github.com/uyuni-project/uyuni.git', description: 'Testsuite Git Repository'),
string(name: 'cucumber_ref', defaultValue: 'master', description: 'Testsuite Git reference (branch, tag...)'),
string(name: 'tf_file', defaultValue: 'susemanager-ci/terracumber_config/tf_files/Uyuni-Master-tests-code-coverage-SLC.tf', description: 'Path to the tf file to be used'),
string(name: 'sumaform_gitrepo', defaultValue: 'https://github.com/uyuni-project/sumaform.git', description: 'Sumaform Git Repository'),
string(name: 'sumaform_ref', defaultValue: 'master', description: 'Sumaform Git reference (branch, tag...)'),
choice(name: 'sumaform_backend', choices: ['libvirt', 'aws'], description: 'Sumaform backend to be used (see https://github.com/uyuni-project/sumaform#backend-choice)'),
choice(name: 'bin_path', choices: ['/usr/bin/tofu', '/usr/bin/terraform'], description: 'Binary path'),
string(name: 'deploy_parallelism', defaultValue: '', description: 'Advanced: Define the number of parallel resource operations for the executable binary'),
choice(name: 'bin_plugins_path', choices: ['/usr/bin'], description: 'Plugins path'),
string(name: 'terracumber_gitrepo', defaultValue: 'https://github.com/uyuni-project/terracumber.git', description: 'Terracumber Git Repository'),
string(name: 'terracumber_ref', defaultValue: 'master', description: 'Terracumber Git ref (branch, tag...)'),
booleanParam(name: 'terraform_init', defaultValue: true, description: 'Call terraform init (needed if modules are added or changes)'),
booleanParam(name: 'terraform_taint', defaultValue: true, description: 'Call terraform taint (so the resources, except volumes, are recreated)'),
choice(name: 'rake_namespace', choices: ['cucumber', 'parallel'], description: 'Choose [parallel] (Clients and some features will run in parallel) or [cucumber] (all sequential)'),
booleanParam(name: 'use_previous_terraform_state', defaultValue: false, description: 'Use previous Terraform state'),
extendedChoice(name: 'functional_scopes', multiSelectDelimiter: ',', quoteValue: false, saveJSONParameterToFile: false, type: 'PT_CHECKBOX', visibleItemCount: 30, value: '@scope_smdba,@scope_spacecmd,@scope_spacewalk_utils,@scope_visualization,@scope_notification_message,@scope_virtual_host_manager,@scope_subscription_matching,@scope_formulas,@scope_sp_migration,@scope_cve_audit,@scope_onboarding,@scope_content_lifecycle_management,@scope_res,@scope_recurring_actions,@scope_maintenance_windows,@scope_building_container_images,@scope_kubernetes_integration,@scope_openscap,@scope_deblike,@scope_action_chains,@scope_salt_ssh,@scope_tomcat,@scope_changing_software_channels,@scope_monitoring,@scope_salt,@scope_cobbler,@scope_sumatoolbox,@scope_virtualization,@scope_hub,@scope_retail,@scope_configuration_channels,@scope_content_staging,@scope_proxy,@scope_traditional_client,@scope_api,@scope_power_management,@scope_retracted_patches,@scope_ansible,@scope_reportdb,@scope_containerized_proxy', description: 'Choose the functional scopes that you want to test')
])
])
timestamps {
// Init path env variables
env.resultdir = "${WORKSPACE}/results"
env.resultdirbuild = "${resultdir}/${BUILD_NUMBER}"
// The junit plugin doesn't affect full paths
junit_resultdir = "results/${BUILD_NUMBER}/results_junit"
env.common_params = "--outputdir ${resultdir} --tf ${params.tf_file} --gitfolder ${resultdir}/sumaform --terraform-bin ${params.bin_path}"
env.cucumber_cmd = "--logfile ${resultdirbuild}/testsuite.log --runstep cucumber --cucumber-cmd"
if (params.deploy_parallelism) {
env.common_params = "${env.common_params} --parallelism ${params.deploy_parallelism}"
}
// Start pipeline
deployed = false
try {
stage('Clone terracumber, susemanager-ci and sumaform') {
git url: params.terracumber_gitrepo, branch: params.terracumber_ref
dir("susemanager-ci") {
checkout scm
}
// Create a directory for to place the directory with the build results (if it does not exist)
sh "mkdir -p ${resultdir}"
// Clone sumaform
sh "set +x; source /home/jenkins/.credentials set -x; ./terracumber-cli ${common_params} --gitrepo ${params.sumaform_gitrepo} --gitref ${params.sumaform_ref} --runstep gitsync"
// Restore Terraform states from artifacts
if (params.use_previous_terraform_state) {
copyArtifacts projectName: currentBuild.projectName, selector: specific("${currentBuild.previousBuild.number}")
}
}
stage('Deploy') {
// Provision the environment
if (params.terraform_init) {
env.TERRAFORM_INIT = '--init'
} else {
env.TERRAFORM_INIT = ''
}
env.TERRAFORM_TAINT = ''
if (params.terraform_taint) {
switch(params.sumaform_backend) {
case "libvirt":
env.TERRAFORM_TAINT = " --taint '.*(domain|main_disk|data_disk|database_disk|standalone_provisioning).*'";
break;
case "aws":
env.TERRAFORM_TAINT = " --taint '.*(host).*'";
break;
default:
println("ERROR: Unknown backend ${params.sumaform_backend}");
sh "exit 1";
break;
}
}
sh "set +x; source /home/jenkins/.credentials set -x; export TF_VAR_CUCUMBER_GITREPO=${params.cucumber_gitrepo}; export TF_VAR_CUCUMBER_BRANCH=${params.cucumber_ref}; export TERRAFORM=${params.bin_path}; export TERRAFORM_PLUGINS=${params.bin_plugins_path}; ./terracumber-cli ${common_params} --logfile ${resultdirbuild}/sumaform.log ${env.TERRAFORM_INIT} ${env.TERRAFORM_TAINT} --sumaform-backend ${params.sumaform_backend} --runstep provision | sed -E 's/([^.]+)module\\.([^.]+)\\.module\\.([^.]+)(\\.module\\.[^.]+)?(\\[[0-9]+\\])?(\\.module\\.[^.]+)?(\\.[^.]+)?(.*)/\\1\\2.\\3\\8/'"
deployed = true
}
stage('Prepare JaCoCo tools') {
def jacocoAgentUrl = "https://search.maven.org/remotecontent?filepath=org/jacoco/org.jacoco.agent/0.8.12/org.jacoco.agent-0.8.12-runtime.jar"
def jacocoCliUrl = "https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.12/org.jacoco.cli-0.8.12-nodeps.jar"
def uyuniMasterUrl = "https://github.com/uyuni-project/uyuni/archive/refs/heads/master.tar.gz"
def serverDataVolume = "/var/lib/containers/storage/volumes/var-cache/_data"
// Download JaCoCo tools to be accessible from the server container
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'ssh -o StrictHostKeyChecking=no \$SERVER \"wget -O ${serverDataVolume}/jacocoagent.jar ${jacocoAgentUrl}; wget ${jacocoCliUrl} -O ${serverDataVolume}/jacococli.jar\"'"
// Create symbolic links to facilitate managing JaCoCo inside our server container
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'ssh -o StrictHostKeyChecking=no \$SERVER \"mgrctl exec \\\"ln -s /var/cache/jacocoagent.jar /tmp; ln -s /var/cache/jacococli.jar /tmp; ln -s /usr/share/susemanager/www/tomcat/webapps/rhn /srv/tomcat/webapps/rhn \\\"\"'"
// Download and extract Uyuni master source code to be accessible from the server container
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'ssh -o StrictHostKeyChecking=no \$SERVER \"wget --directory-prefix ${serverDataVolume} ${uyuniMasterUrl}; tar --extract --file ${serverDataVolume}/master.tar.gz --directory ${serverDataVolume}\"'"
// Restart Tomcat service from the server container
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'ssh -o StrictHostKeyChecking=no \$SERVER \"mgrctl exec \\\"systemctl restart tomcat.service\\\"\"'"
}
stage('Sanity Check') {
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'cd /root/spacewalk/testsuite; rake cucumber:sanity_check'"
}
stage('Core - Setup') {
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'cd /root/spacewalk/testsuite; rake cucumber:core'"
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'cd /root/spacewalk/testsuite; rake cucumber:reposync'"
}
stage('Core - Proxy') {
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'cd /root/spacewalk/testsuite; rake cucumber:proxy'"
}
stage('Core - Initialize clients') {
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'cd /root/spacewalk/testsuite; rake ${params.rake_namespace}:init_clients'"
}
stage('Secondary features') {
def tags_list = ""
if (params.functional_scopes) {
def transformed_scopes = params.functional_scopes.replaceAll(',', ' or ')
tags_list += "export TAGS=${transformed_scopes}; "
}
def statusCode1 = sh script:"./terracumber-cli ${common_params} ${cucumber_cmd} '${tags_list} cd /root/spacewalk/testsuite; rake cucumber:secondary'", returnStatus:true
def statusCode2 = sh script:"./terracumber-cli ${common_params} ${cucumber_cmd} '${tags_list} cd /root/spacewalk/testsuite; rake ${params.rake_namespace}:secondary_parallelizable'", returnStatus:true
sh "exit \$(( ${statusCode1}|${statusCode2} ))"
}
}
finally {
stage('Save TF state') {
archiveArtifacts artifacts: "results/sumaform/terraform.tfstate, results/sumaform/.terraform/**/*"
}
stage('Dump Code Coverage results') {
def jacocoCliPath = "/var/cache/jacococli.jar"
def jacocoExecFiles = "/var/cache/*.exec"
def jacocoAllExecPath = "/var/cache/jacoco-all.exec"
def jacocoHtmlReportPath = "/srv/www/htdocs/pub/jacoco-cucumber-report"
def jacocoXmlReportPath = "/srv/www/htdocs/pub/jacoco-cucumber-report.xml"
def sourceFilesPath = "/var/cache/uyuni-master/java/code/src"
def classFilesPath = "/srv/tomcat/webapps/rhn/WEB-INF/lib/rhn.jar"
// Dump JaCoCo code coverage binary report and reset the JaCoCo recorded data
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'ssh -o StrictHostKeyChecking=no \$SERVER \"mgrctl exec \\\"java -jar ${jacocoCliPath} dump --address localhost --destfile /var/cache/jacoco-last.exec --port 6300 --reset\\\"\"'"
// Merge code coverage binary reports
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'ssh -o StrictHostKeyChecking=no \$SERVER \"mgrctl exec \\\"java -jar ${jacocoCliPath} merge \\\\\\\$(ls ${jacocoExecFiles}) --destfile ${jacocoAllExecPath}\\\"\"'"
// Generate JaCoCo HTML and XML complete reports
sh "./terracumber-cli ${common_params} ${cucumber_cmd} 'ssh -o StrictHostKeyChecking=no \$SERVER \"mgrctl exec \\\"java -jar ${jacocoCliPath} report ${jacocoAllExecPath} --html ${jacocoHtmlReportPath} --xml ${jacocoXmlReportPath} --sourcefiles ${sourceFilesPath} --classfiles ${classFilesPath}\\\"\"'"
}
stage('Get results') {
def error = 0
// Send email
sh "./terracumber-cli ${common_params} --logfile ${resultdirbuild}/mail.log --runstep mail"
// Clean up old results
sh "./clean-old-results -r ${resultdir}"
sh "exit ${error}"
}
}
}
}