-
Notifications
You must be signed in to change notification settings - Fork 277
/
integ-test.jenkinsfile
337 lines (321 loc) · 19.1 KB
/
integ-test.jenkinsfile
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
lib = library(identifier: '[email protected]', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
]))
def docker_images = [
'tar': 'opensearchstaging/ci-runner:ci-runner-al2-opensearch-build-v1',
'rpm': 'opensearchstaging/ci-runner:ci-runner-almalinux8-systemd-base-integtest-v1',
'deb': 'opensearchstaging/ci-runner:ci-runner-ubuntu2004-systemd-base-integtest-v3',
'zip': 'opensearchstaging/ci-runner:ci-runner-windows2019-opensearch-build-v1',
]
def docker_args = [
'tar': '-u 1000 --cpus 4 -m 16g',
'rpm': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host --cpus 4 -m 16g',
'deb': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host --cpus 4 -m 16g',
'zip': '-u ContainerAdministrator',
]
def agent_nodes = [
'linux_x64': 'Jenkins-Agent-AL2023-X64-M54xlarge-Docker-Host',
'linux_arm64': 'Jenkins-Agent-AL2023-Arm64-M6g4xlarge-Docker-Host',
'windows_x64': 'Jenkins-Agent-Windows2019-X64-M54xlarge-Docker-Host',
]
pipeline {
options {
timeout(time: 4, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '60'))
}
agent none
environment {
BUILD_MANIFEST = 'build-manifest.yml'
BUILD_JOB_NAME = 'distribution-build-opensearch'
ARTIFACT_BUCKET_NAME = credentials('jenkins-artifact-bucket-name')
}
// Add as follows to enable parameterizedCron trigger for a specific test manifest.
/*triggers {
parameterizedCron '''
H 1 * * * %TEST_MANIFEST=2.12.0/opensearch-2.12.0-concurrent-search-test.yml;BUILD_MANIFEST_URL=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.12.0/latest/linux/arm64/tar/builds/opensearch/manifest.yml
H 1 * * * %TEST_MANIFEST=2.12.0/opensearch-2.12.0-concurrent-search-test.yml;BUILD_MANIFEST_URL=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.12.0/latest/linux/x64/tar/builds/opensearch/manifest.yml
'''
}*/
parameters {
string(
name: 'COMPONENT_NAME',
description: 'If this field contains one or more component names (e.g. index-management geospatial ...) separated by space, will test with "--component ...", else test everything in the TEST_MANIFEST..',
trim: true
)
string(
name: 'TEST_MANIFEST',
description: 'Test manifest under the manifests folder, e.g. 2.0.0/opensearch-2.0.0-test.yml.',
trim: true
)
string(
name: 'BUILD_MANIFEST_URL',
description: 'The build manifest URL for OpenSearch, e.g. "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.9.0/8172/linux/x64/tar/builds/opensearch/manifest.yml".',
trim: true
)
string(
name: 'RC_NUMBER',
description: 'The RC build count. Default is 0 which means its not an RC build.',
defaultValue: '0'
)
booleanParam(
name: 'VALIDATE_ARTIFACTS',
description: 'If true the provided artifacts are validated before triggering integ-tests else skip the validation stage',
defaultValue: true
)
}
stages {
stage('verify-parameters') {
agent { label agent_nodes['linux_x64'] }
steps {
script {
if (TEST_MANIFEST == '' || !fileExists("manifests/${TEST_MANIFEST}")) {
currentBuild.result = 'ABORTED'
error("Integration Tests failed to start. Test manifest was not provided or not found in manifests/${TEST_MANIFEST}.")
}
if (BUILD_MANIFEST_URL == '') {
currentBuild.result = 'ABORTED'
error('Integration Tests failed to start. Build manifest url was not provided.')
}
downloadBuildManifest(
url: BUILD_MANIFEST_URL,
path: BUILD_MANIFEST
)
def buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST))
env.architecture = buildManifestObj.getArtifactArchitecture()
env.buildId = buildManifestObj.getArtifactBuildId()
env.distribution = buildManifestObj.getDistribution()
env.version = buildManifestObj.build.version
env.platform = buildManifestObj.build.platform
env.artifactPath = buildManifestObj.getArtifactRoot(BUILD_JOB_NAME, buildId)
env.AGENT_LABEL = agent_nodes["${env.platform}_${architecture}"]
}
}
post {
always {
postCleanup()
}
}
}
stage('validate-artifacts') {
when {
expression {
params.VALIDATE_ARTIFACTS == true
}
}
agent { label agent_nodes['linux_x64'] }
steps {
script {
build job: 'distribution-validation',
propagate: true,
wait: true,
parameters: [
string(name: 'VERSION', value: "${env.version}"),
string(name: 'DISTRIBUTION', value: "${env.distribution}"),
string(name: 'ARCHITECTURE', value: "${env.architecture}"),
string(name: 'OS_BUILD_NUMBER', value: "${env.buildId}"),
string(name: 'PROJECTS', value: "opensearch"),
string(name: 'ARTIFACT_TYPE', value: "staging")
]
}
}
post {
always {
postCleanup()
}
}
}
stage('integ-test') {
// Need to run this directly on agent node here in order to trigger stages with docker container and avoid docker within docker situation
// Can only be run in runner that is at least 50GB per container
agent { label AGENT_LABEL }
steps {
script {
downloadBuildManifest(
url: BUILD_MANIFEST_URL,
path: BUILD_MANIFEST
)
def buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST))
def testManifestObj = lib.jenkins.TestManifest.new(readYaml(file: "manifests/${TEST_MANIFEST}"))
def componentDefaultList = testManifestObj.getComponentNames()
def componentsInBuildManifest = buildManifestObj.getNames()
def componentList = COMPONENT_NAME ? COMPONENT_NAME.trim().split(' ') as List : componentDefaultList
String switch_user_non_root = (distribution.equals('rpm') || distribution.equals('deb')) ? 'true' : 'false'
echo "switch_user_non_root: ${switch_user_non_root}"
for (component_check in componentList) {
if (!componentDefaultList.contains(component_check)) {
error("${component_check} is not present in the test manifest: ${TEST_MANIFEST}")
}
if (!componentsInBuildManifest.contains(component_check)) {
echo "Skipping tests for ${component_check} as is not present in the provided build manifest."
componentList -= component_check
}
// Due to inability to install multiple versions of deb/rpm packages on the same EC2 host.
// CCR plugin remoteIntegTest are failing in deb and rpm distribution due to multiple clusters are not forming.(Issue-https://github.com/opensearch-project/opensearch-build/issues/4610)
// A multi-cluster setup is needed. TODO: Explore multi-cluster setup solutions.
// Temporarily Skipping integTest for cross-cluster-replication component when running on deb and rpm distribution.
if ((distribution.equals('rpm') || distribution.equals('deb')) && component_check.equals('cross-cluster-replication')) {
echo "Skipping integTest for ${distribution} distribution for cross-cluster-replication"
componentList -= component_check
}
}
echo "Testing components: ${componentList}"
currentBuild.description = "$TEST_MANIFEST, $version, $architecture, $platform, $buildId, $distribution, $componentList"
if (env.platform != 'windows') {
echo "Downloading from ${artifactPath} and stashing both artifacts and repository"
downloadFromS3(
assumedRoleName: 'opensearch-bundle',
roleAccountNumberCred: 'jenkins-aws-account-public',
downloadPath: "${artifactPath}/",
bucketName: "${ARTIFACT_BUCKET_NAME}",
localPath: "${WORKSPACE}/artifacts",
force: true
)
sh("rm -rf $WORKSPACE/$distribution && mv -v $WORKSPACE/artifacts/${artifactPath} $WORKSPACE")
}
else {
echo 'Skipping artifacts downloads since platform is Windows and only stashing the repository'
}
// Stash the current working directory files, aka opensearch-build repo
// Unstash later in each triggered stage to run integTest
stash includes: '**', name: "integtest-opensearch-$BUILD_NUMBER"
componentTests = [:]
for (component in componentList) {
// Must use local variable due to groovy for loop and closure scope
// Or the stage will be fixed to the last item in return when new stages are triggered here
// https://web.archive.org/web/20181121065904/http://blog.freeside.co/2013/03/29/groovy-gotcha-for-loops-and-closure-scope/
def local_component = component.trim()
def local_component_index = componentList.indexOf(local_component)
def wait_seconds = local_component_index * 20
echo "Add Component: ${local_component}"
componentTests["Testing ${local_component}"] = {
// Using scripted pipelines to trigger dynamic parallel stages
timeout(time: 2, unit: 'HOURS') {
node(AGENT_LABEL) {
docker.withRegistry('https://public.ecr.aws/') {
docker.image(docker_images["$distribution"]).inside(docker_args["$distribution"]) {
try {
stage("${local_component}") {
// Jenkins tend to not clean up workspace at times even though ws clean is called
// Docker is mounting the agent directory so it can communicate with the agent
// this sometimes causes the workspace to retain last run test-results and ends with build failures
// https://github.com/opensearch-project/opensearch-build/blob/6ed1ce3c583233eae4fe1027969d778cfc7660f7/src/test_workflow/test_recorder/test_recorder.py#L99
sh("echo ${local_component} with index ${local_component_index} will sleep ${wait_seconds} seconds to reduce load && sleep ${wait_seconds}")
unstash "integtest-opensearch-$BUILD_NUMBER"
if (env.platform == 'windows') {
echo "Unstashing the repository and downloading the artifacts from S3: ${artifactPath}"
downloadFromS3(
assumedRoleName: 'opensearch-bundle',
roleAccountNumberCred: 'jenkins-aws-account-public',
downloadPath: "${artifactPath}/",
bucketName: "${ARTIFACT_BUCKET_NAME}",
localPath: "${WORKSPACE}/artifacts",
force: true
)
sh("rm -rf $WORKSPACE/$distribution && mv -v $WORKSPACE/artifacts/${artifactPath} $WORKSPACE")
}
else {
echo 'Unstashing both artifacts and repository'
}
sh('rm -rf test-results')
runIntegTestScript(
jobName: "$BUILD_JOB_NAME",
componentName: "${local_component}",
buildManifest: "$BUILD_MANIFEST",
testManifest: "manifests/${TEST_MANIFEST}",
localPath: "${WORKSPACE}/${distribution}",
switchUserNonRoot: "${switch_user_non_root}"
)
}
} catch (e) {
throw new Exception("Error running integtest for component ${local_component}", e)
} finally {
echo "Completed running integtest for component ${local_component}"
uploadTestResults(
buildManifestFileName: BUILD_MANIFEST,
jobName: JOB_NAME
)
postCleanup()
}
}
}
}
}
}
}
parallel componentTests
}
}
post {
always {
script {
retry(5) {
node(AGENT_LABEL) {
docker.withRegistry('https://public.ecr.aws/') {
docker.image(docker_images["$distribution"]).inside(docker_args["$distribution"]) {
checkout scm
sleep 10
downloadBuildManifest(
url: BUILD_MANIFEST_URL,
path: BUILD_MANIFEST
)
createUploadTestReportManifest(
testManifest: "manifests/${TEST_MANIFEST}",
buildManifest: BUILD_MANIFEST,
testRunID: "${env.BUILD_NUMBER}",
testType: 'integ-test',
rcNumber: params.RC_NUMBER,
componentName: "${COMPONENT_NAME}",
)
echo("Download report manifest from https://ci.opensearch.org/ci/dbc/integ-test/${env.version}/${env.buildId}/${env.platform}/${env.architecture}/${env.distribution}/test-results/${env.BUILD_NUMBER}/integ-test/test-report.yml")
archiveArtifacts artifacts: 'test-report.yml'
}
}
}
}
retry(5) {
node(agent_nodes['linux_x64']) {
sleep 10
def rc = (params.RC_NUMBER.toInteger() > 0)
sh "mkdir -p test-results-os-${env.BUILD_NUMBER}"
sh "curl -sSL https://ci.opensearch.org/ci/dbc/integ-test/${env.version}/${env.buildId}/${env.platform}/${env.architecture}/${env.distribution}/test-results/${env.BUILD_NUMBER}/integ-test/test-report.yml --output test-results-os-${env.BUILD_NUMBER}/test-report.yml"
publishIntegTestResults(
distributionBuildUrl: "https://build.ci.opensearch.org/blue/organizations/jenkins/${env.BUILD_JOB_NAME}/detail/${env.BUILD_JOB_NAME}/${env.buildId}/pipeline",
jobName: env.JOB_NAME,
testReportManifestYml: "test-results-os-${env.BUILD_NUMBER}/test-report.yml"
)
postCleanup()
}
}
}
postCleanup()
}
}
}
}
post {
always {
node(AGENT_LABEL) {
script {
def triggerIntegTestNotification =
build job: 'integ-test-notification',
propagate: false,
wait: false,
parameters: [
string(name: 'INPUT_MANIFEST', value: "${env.version}/opensearch-${env.version}.yml"),
string(name: 'DISTRIBUTION_NUMBER', value: "${env.buildId}")
]
postCleanup()
}
}
}
}
}