Skip to content

Commit de1f5d4

Browse files
authored
Add a new Jenkins job for the smoke test (#5225)
Signed-off-by: Zelin Hao <zelinhao@amazon.com>
1 parent 2556e29 commit de1f5d4

File tree

5 files changed

+3929
-0
lines changed

5 files changed

+3929
-0
lines changed
+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*/
9+
10+
lib = library(identifier: 'jenkins@8.1.0', retriever: modernSCM([
11+
$class: 'GitSCMSource',
12+
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
13+
]))
14+
15+
def docker_images = [
16+
'tar': 'opensearchstaging/ci-runner:ci-runner-al2-opensearch-build-v1',
17+
'rpm': 'opensearchstaging/ci-runner:ci-runner-almalinux8-systemd-base-integtest-v1',
18+
'deb': 'opensearchstaging/ci-runner:ci-runner-ubuntu2004-systemd-base-integtest-v3',
19+
'zip': 'opensearchstaging/ci-runner:ci-runner-windows2019-opensearch-build-v1',
20+
]
21+
22+
def docker_args = [
23+
'tar': '-u 1000 --cpus 4 -m 16g',
24+
'rpm': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host --cpus 4 -m 16g',
25+
'deb': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host --cpus 4 -m 16g',
26+
'zip': '-u ContainerAdministrator',
27+
]
28+
29+
def agent_nodes = [
30+
'linux_x64': 'Jenkins-Agent-AL2023-X64-M54xlarge-Docker-Host',
31+
'linux_arm64': 'Jenkins-Agent-AL2023-Arm64-M6g4xlarge-Docker-Host',
32+
'windows_x64': 'Jenkins-Agent-Windows2019-X64-M54xlarge-Docker-Host',
33+
]
34+
35+
pipeline {
36+
options {
37+
timeout(time: 2, unit: 'HOURS')
38+
}
39+
agent none
40+
environment {
41+
BUILD_MANIFEST = 'build-manifest.yml'
42+
BUILD_JOB_NAME = 'distribution-build-opensearch'
43+
ARTIFACT_BUCKET_NAME = credentials('jenkins-artifact-bucket-name')
44+
}
45+
parameters {
46+
string(
47+
name: 'TEST_MANIFEST',
48+
description: 'Test manifest under the manifests folder, e.g. 2.19.0/opensearch-2.19.0-test.yml.',
49+
trim: true
50+
)
51+
string(
52+
name: 'BUILD_MANIFEST_URL',
53+
description: 'The build manifest URL for OpenSearch, e.g. "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.19.0/10545/linux/x64/tar/builds/opensearch/manifest.yml".',
54+
trim: true
55+
)
56+
}
57+
stages {
58+
stage('verify-parameters') {
59+
agent { label agent_nodes['linux_x64'] }
60+
steps {
61+
script {
62+
if (TEST_MANIFEST == '' || !fileExists("manifests/${TEST_MANIFEST}")) {
63+
currentBuild.result = 'ABORTED'
64+
error("Smoke Tests failed to start. Test manifest was not provided or not found in manifests/${TEST_MANIFEST}.")
65+
}
66+
67+
if (BUILD_MANIFEST_URL == '') {
68+
currentBuild.result = 'ABORTED'
69+
error('Smoke Tests failed to start. Build manifest url was not provided.')
70+
}
71+
downloadBuildManifest(
72+
url: BUILD_MANIFEST_URL,
73+
path: BUILD_MANIFEST
74+
)
75+
76+
def buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST))
77+
env.architecture = buildManifestObj.getArtifactArchitecture()
78+
env.buildId = buildManifestObj.getArtifactBuildId()
79+
env.distribution = buildManifestObj.getDistribution()
80+
env.version = buildManifestObj.build.version
81+
env.platform = buildManifestObj.build.platform
82+
env.artifactPath = buildManifestObj.getArtifactRoot(BUILD_JOB_NAME, buildId)
83+
env.AGENT_LABEL = agent_nodes["${env.platform}_${architecture}"]
84+
}
85+
}
86+
post {
87+
always {
88+
postCleanup()
89+
}
90+
}
91+
}
92+
stage('smoke-test') {
93+
options {
94+
timeout(time: 1, unit: 'HOURS')
95+
}
96+
agent {
97+
docker {
98+
label AGENT_LABEL
99+
image docker_images[env.distribution]
100+
args docker_args[env.distribution]
101+
registryUrl 'https://public.ecr.aws/'
102+
alwaysPull true
103+
}
104+
}
105+
steps {
106+
script {
107+
currentBuild.description = "$TEST_MANIFEST, $version, $architecture, $platform, $buildId, $distribution"
108+
109+
try {
110+
stage("Smoke_tests") {
111+
checkout scm
112+
sleep 10
113+
downloadBuildManifest(
114+
url: BUILD_MANIFEST_URL,
115+
path: BUILD_MANIFEST
116+
)
117+
118+
def buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST))
119+
def testManifestObj = lib.jenkins.TestManifest.new(readYaml(file: "manifests/${TEST_MANIFEST}"))
120+
121+
sh('rm -rf test-results')
122+
runSmokeTestScript(
123+
jobName: "$BUILD_JOB_NAME",
124+
buildManifest: "$BUILD_MANIFEST",
125+
testManifest: "manifests/${TEST_MANIFEST}",
126+
buildId: "${buildId}"
127+
)
128+
}
129+
} catch (e) {
130+
throw new Exception("Error running Smoke test", e)
131+
} finally {
132+
echo "Completed running smoke tests."
133+
postCleanup()
134+
}
135+
}
136+
}
137+
post {
138+
always {
139+
postCleanup()
140+
}
141+
}
142+
}
143+
}
144+
post {
145+
always {
146+
node(AGENT_LABEL) {
147+
script {
148+
postCleanup()
149+
}
150+
}
151+
}
152+
}
153+
}

tests/jenkins/TestSmokeTest.groovy

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
7+
import jenkins.tests.BuildPipelineTest
8+
import org.junit.Before
9+
import org.junit.Test
10+
import org.yaml.snakeyaml.Yaml
11+
12+
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
13+
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource
14+
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library
15+
import static org.hamcrest.CoreMatchers.hasItem
16+
import static org.hamcrest.MatcherAssert.assertThat
17+
18+
class TestSmokeTest extends BuildPipelineTest {
19+
20+
@Override
21+
@Before
22+
void setUp() {
23+
24+
helper.registerSharedLibrary(
25+
library().name('jenkins')
26+
.defaultVersion('8.1.0')
27+
.allowOverride(true)
28+
.implicit(true)
29+
.targetPath('vars')
30+
.retriever(gitSource('https://github.com/opensearch-project/opensearch-build-libraries.git'))
31+
.build()
32+
)
33+
34+
super.setUp()
35+
36+
def jobName = "dummy_job"
37+
def testManifest = "tests/jenkins/data/opensearch-2.19.0-test.yml"
38+
def buildManifest = "tests/jenkins/data/opensearch-2.19.0-build.yml"
39+
def buildManifestUrl = "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.19.0/10545/linux/x64/tar/builds/opensearch/manifest.yml"
40+
def agentLabel = "Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host"
41+
42+
binding.setVariable('env', ['BUILD_NUMBER': '234', 'PUBLIC_ARTIFACT_URL': 'DUMMY_PUBLIC_ARTIFACT_URL', 'JOB_NAME': 'dummy_job', 'DOCKER_AGENT':[image:'opensearchstaging/ci-runner:ci-runner-centos7-v1', args:'-e JAVA_HOME=/opt/java/openjdk-11']])
43+
binding.setVariable('BUILD_JOB_NAME', 'dummy_job')
44+
binding.setVariable('TEST_MANIFEST', testManifest)
45+
binding.setVariable('BUILD_MANIFEST_URL', buildManifestUrl)
46+
binding.setVariable('AGENT_LABEL', agentLabel)
47+
binding.setVariable('BUILD_NUMBER', '234')
48+
binding.setVariable('BUILD_MANIFEST', buildManifest)
49+
helper.registerAllowedMethod("readYaml", [Map.class], { args ->
50+
if (args.file == 'manifests/tests/jenkins/data/opensearch-2.19.0-test.yml') {
51+
return new Yaml().load((testManifest as File).text)
52+
} else if (args.file == 'tests/jenkins/data/opensearch-2.19.0-build.yml') {
53+
return new Yaml().load((buildManifest as File).text)
54+
} else {
55+
println("Manifest not found ${args.file}")
56+
}
57+
})
58+
helper.addFileExistsMock("manifests/${testManifest}", true)
59+
helper.registerAllowedMethod('unstash', [String.class], null)
60+
}
61+
62+
@Test
63+
void smokeTests_runs() {
64+
addParam('UPDATE_GITHUB_ISSUES', true)
65+
super.testPipeline('jenkins/opensearch/smoke-test.jenkinsfile',
66+
'tests/jenkins/jenkinsjob-regression-files/opensearch/smoke-test.jenkinsfile')
67+
assertThat(getCommandExecutions('sh', 'test.sh'), hasItem('./test.sh smoke-test manifests/tests/jenkins/data/opensearch-2.19.0-test.yml --test-run-id 234 --paths opensearch=https://ci.opensearch.org/ci/dbc/dummy_job/2.19.0/10545/linux/x64/tar'))
68+
}
69+
70+
@Test
71+
void checkError() {
72+
helper.addFileExistsMock('manifests/tests/jenkins/data/opensearch-2.19.0-test.yml', false)
73+
runScript('jenkins/opensearch/smoke-test.jenkinsfile')
74+
assertThat(getCommandExecutions('error', ''), hasItem('Smoke Tests failed to start. Test manifest was not provided or not found in manifests/tests/jenkins/data/opensearch-2.19.0-test.yml.'))
75+
assertJobStatusFailure()
76+
}
77+
78+
def getCommandExecutions(methodName, command) {
79+
def shCommands = helper.callStack.findAll {
80+
call ->
81+
call.methodName == methodName
82+
}.
83+
collect {
84+
call ->
85+
callArgsToString(call)
86+
}.findAll {
87+
shCommand ->
88+
shCommand.contains(command)
89+
}
90+
91+
return shCommands
92+
}
93+
}

0 commit comments

Comments
 (0)