Skip to content

Commit

Permalink
Update smoke test jenkinsfile to accommodate rpm & deb
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh committed Jan 10, 2025
1 parent de1f5d4 commit 54d9026
Show file tree
Hide file tree
Showing 5 changed files with 3,699 additions and 34 deletions.
37 changes: 19 additions & 18 deletions jenkins/opensearch/smoke-test.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* compatible open source license.
*/

lib = library(identifier: '[email protected].0', retriever: modernSCM([
lib = library(identifier: '[email protected].1', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
]))
Expand Down Expand Up @@ -105,27 +105,28 @@ pipeline {
steps {
script {
currentBuild.description = "$TEST_MANIFEST, $version, $architecture, $platform, $buildId, $distribution"
String switch_user_non_root = (distribution.equals('rpm') || distribution.equals('deb')) ? 'true' : 'false'
echo "switch_user_non_root: ${switch_user_non_root}"

try {
stage("Smoke_tests") {
checkout scm
sleep 10
downloadBuildManifest(
url: BUILD_MANIFEST_URL,
path: BUILD_MANIFEST
)
checkout scm
sleep 10
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 buildManifestObj = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST))
def testManifestObj = lib.jenkins.TestManifest.new(readYaml(file: "manifests/${TEST_MANIFEST}"))

sh('rm -rf test-results')
runSmokeTestScript(
jobName: "$BUILD_JOB_NAME",
buildManifest: "$BUILD_MANIFEST",
testManifest: "manifests/${TEST_MANIFEST}",
buildId: "${buildId}"
)
}
sh('rm -rf test-results')
runSmokeTestScript(
jobName: "$BUILD_JOB_NAME",
buildManifest: "$BUILD_MANIFEST",
testManifest: "manifests/${TEST_MANIFEST}",
buildId: "${buildId}",
switchUserNonRoot: "${switch_user_non_root}"
)
} catch (e) {
throw new Exception("Error running Smoke test", e)
} finally {
Expand Down
72 changes: 60 additions & 12 deletions tests/jenkins/TestSmokeTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestSmokeTest extends BuildPipelineTest {

helper.registerSharedLibrary(
library().name('jenkins')
.defaultVersion('8.1.0')
.defaultVersion('8.1.1')
.allowOverride(true)
.implicit(true)
.targetPath('vars')
Expand All @@ -34,18 +34,27 @@ class TestSmokeTest extends BuildPipelineTest {
super.setUp()

def jobName = "dummy_job"
def testManifest = "tests/jenkins/data/opensearch-2.19.0-test.yml"
def buildManifest = "tests/jenkins/data/opensearch-2.19.0-build.yml"
def buildManifestUrl = "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.19.0/10545/linux/x64/tar/builds/opensearch/manifest.yml"
def agentLabel = "Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host"

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']])
binding.setVariable('BUILD_JOB_NAME', 'dummy_job')
binding.setVariable('TEST_MANIFEST', testManifest)
binding.setVariable('BUILD_MANIFEST_URL', buildManifestUrl)
binding.setVariable('AGENT_LABEL', agentLabel)
binding.setVariable('BUILD_NUMBER', '234')

helper.registerAllowedMethod('unstash', [String.class], null)
}

@Test
void smokeTests_runs() {
def buildManifest = "tests/jenkins/data/opensearch-2.19.0-build.yml"
def testManifest = "tests/jenkins/data/opensearch-2.19.0-test.yml"
def buildManifestUrl = "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.19.0/10545/linux/x64/tar/builds/opensearch/manifest.yml"

binding.setVariable('BUILD_MANIFEST_URL', buildManifestUrl)
binding.setVariable('BUILD_MANIFEST', buildManifest)
binding.setVariable('TEST_MANIFEST', testManifest)
helper.addFileExistsMock("manifests/${testManifest}", true)

helper.registerAllowedMethod("readYaml", [Map.class], { args ->
if (args.file == 'manifests/tests/jenkins/data/opensearch-2.19.0-test.yml') {
return new Yaml().load((testManifest as File).text)
Expand All @@ -55,20 +64,59 @@ class TestSmokeTest extends BuildPipelineTest {
println("Manifest not found ${args.file}")
}
})
helper.addFileExistsMock("manifests/${testManifest}", true)
helper.registerAllowedMethod('unstash', [String.class], null)

super.testPipeline('jenkins/opensearch/smoke-test.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/opensearch/smoke-test.jenkinsfile')
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 '))
}

@Test
void smokeTests_runs() {
addParam('UPDATE_GITHUB_ISSUES', true)
void smokeTests_runs_rpm() {
def buildManifest = "tests/jenkins/data/opensearch-2.19.0-build-rpm.yml"
def testManifest = "tests/jenkins/data/opensearch-2.19.0-test.yml"
def buildManifestUrl = "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.19.0/10691/linux/arm64/rpm/builds/opensearch/manifest.yml"

binding.setVariable('BUILD_MANIFEST', buildManifest)
binding.setVariable('BUILD_MANIFEST_URL', buildManifestUrl)
binding.setVariable('TEST_MANIFEST', testManifest)
helper.addFileExistsMock("manifests/${testManifest}", true)

helper.registerAllowedMethod("readYaml", [Map.class], { args ->
if (args.file == 'manifests/tests/jenkins/data/opensearch-2.19.0-test.yml') {
return new Yaml().load((testManifest as File).text)
} else if (args.file == 'tests/jenkins/data/opensearch-2.19.0-build-rpm.yml') {
return new Yaml().load((buildManifest as File).text)
} else {
println("Manifest not found ${args.file}")
}
})

super.testPipeline('jenkins/opensearch/smoke-test.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/opensearch/smoke-test.jenkinsfile')
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'))
'tests/jenkins/jenkinsjob-regression-files/opensearch/smoke-test-rpm.jenkinsfile')
assertThat(getCommandExecutions('sh', 'test.sh'), hasItem('su `id -un 1000` -c \" ./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/10691/linux/arm64/rpm \"'))
}

@Test
void checkError() {
def buildManifest = "tests/jenkins/data/opensearch-2.19.0-build.yml"
def testManifest = "tests/jenkins/data/opensearch-2.19.0-test.yml"
def buildManifestUrl = "https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/2.19.0/10545/linux/x64/tar/builds/opensearch/manifest.yml"

binding.setVariable('BUILD_MANIFEST_URL', buildManifestUrl)
binding.setVariable('BUILD_MANIFEST', buildManifest)
binding.setVariable('TEST_MANIFEST', testManifest)
helper.addFileExistsMock("manifests/${testManifest}", true)

helper.registerAllowedMethod("readYaml", [Map.class], { args ->
if (args.file == 'manifests/tests/jenkins/data/opensearch-2.19.0-test.yml') {
return new Yaml().load((testManifest as File).text)
} else if (args.file == 'tests/jenkins/data/opensearch-2.19.0-build.yml') {
return new Yaml().load((buildManifest as File).text)
} else {
println("Manifest not found ${args.file}")
}
})

helper.addFileExistsMock('manifests/tests/jenkins/data/opensearch-2.19.0-test.yml', false)
runScript('jenkins/opensearch/smoke-test.jenkinsfile')
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.'))
Expand Down
Loading

0 comments on commit 54d9026

Please sign in to comment.