Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sayali Gaikawad <[email protected]>
  • Loading branch information
gaiksaya committed Jan 17, 2024
1 parent 8b3345a commit 6e73f0c
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 497 deletions.
51 changes: 22 additions & 29 deletions jenkins/opensearch/integ-test.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ lib = library(identifier: 'jenkins@add-getNames', retriever: modernSCM([
]))

def docker_images = [
"tar": "opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v3",
"rpm": "opensearchstaging/ci-runner:ci-runner-rockylinux8-systemd-base-integtest-v3",
"deb": "opensearchstaging/ci-runner:ci-runner-ubuntu2004-systemd-base-integtest-v3",
"zip": "opensearchstaging/ci-runner:ci-runner-windows2019-servercore-opensearch-build-v1",
'tar': 'opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v3',
'rpm': 'opensearchstaging/ci-runner:ci-runner-rockylinux8-systemd-base-integtest-v3',
'deb': 'opensearchstaging/ci-runner:ci-runner-ubuntu2004-systemd-base-integtest-v3',
'zip': 'opensearchstaging/ci-runner:ci-runner-windows2019-servercore-opensearch-build-v1',
]

def docker_args = [
"tar": "-u 1000",
"rpm": "--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host",
"deb": "--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host",
"zip": "-u ContainerAdministrator",
'tar': '-u 1000',
'rpm': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host',
'deb': '--entrypoint=/usr/lib/systemd/systemd -u root --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:rw --cgroupns=host',
'zip': '-u ContainerAdministrator',
]

def agent_nodes = [
"linux_x64": "Jenkins-Agent-AL2023-X64-C54xlarge-Docker-Host",
"linux_arm64": "Jenkins-Agent-AL2023-Arm64-C6g4xlarge-Docker-Host",
"windows_x64": "Jenkins-Agent-Windows2019-X64-C54xlarge-Docker-Host",
'linux_x64': 'Jenkins-Agent-AL2023-X64-C54xlarge-Docker-Host',
'linux_arm64': 'Jenkins-Agent-AL2023-Arm64-C6g4xlarge-Docker-Host',
'windows_x64': 'Jenkins-Agent-Windows2019-X64-C54xlarge-Docker-Host',
]

pipeline {
Expand All @@ -40,8 +40,8 @@ pipeline {
}
agent none
environment {
BUILD_MANIFEST = "build-manifest.yml"
BUILD_JOB_NAME = "distribution-build-opensearch"
BUILD_MANIFEST = 'build-manifest.yml'
BUILD_JOB_NAME = 'distribution-build-opensearch'
ARTIFACT_BUCKET_NAME = credentials('jenkins-artifact-bucket-name')
}
triggers {
Expand Down Expand Up @@ -74,7 +74,7 @@ pipeline {
}
stages {
stage('verify-parameters') {
agent { label agent_nodes["linux_x64"]}
agent { label agent_nodes['linux_x64'] }
steps {
script {
if (TEST_MANIFEST == '' || !fileExists("manifests/${TEST_MANIFEST}")) {
Expand All @@ -84,30 +84,22 @@ pipeline {

if (BUILD_MANIFEST_URL == '') {
currentBuild.result = 'ABORTED'
error("Integration Tests failed to start. Build manifest url was not provided.")
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))
def testManifestObj = lib.jenkins.TestManifest.new(readYaml(file: "manifests/${TEST_MANIFEST}"))
def componentDefaultList = testManifestObj.getComponentNames()
def componentList = COMPONENT_NAME ? COMPONENT_NAME.trim().split(" ") as List : componentDefaultList
env.architecture = buildManifestObj.getArtifactArchitecture()
env.platform = buildManifestObj.getArtifactPlatform()
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}"]
env.updateGithubIssues = UPDATE_GITHUB_ISSUES && env.distribution == 'tar'


echo "Version: ${version}, Agent: ${AGENT_LABEL}, BuildId: ${buildId}, Distribution: ${distribution}, Components: ${componentList}"
currentBuild.description = "$TEST_MANIFEST, $version, $architecture, $platform, $buildId, $distribution, $componentList"
}
}
post {
Expand All @@ -122,7 +114,6 @@ pipeline {
agent { label AGENT_LABEL }
steps {
script {

downloadBuildManifest(
url: BUILD_MANIFEST_URL,
path: BUILD_MANIFEST
Expand All @@ -132,19 +123,21 @@ pipeline {
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
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}"
echo "componentList: ${componentList}"

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"${component_check} is not present in the provided build manifest. Tests will be skipped for ${component_check}"
echo "Skipping tests for ${component_check} as is not present in the provided build manifest."
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"
Expand All @@ -164,7 +157,7 @@ pipeline {

// 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"
stash includes: '**', name: "integtest-opensearch-$BUILD_NUMBER"

componentTests = [:]

Expand Down Expand Up @@ -272,7 +265,7 @@ pipeline {
testManifest: "manifests/${TEST_MANIFEST}",
buildManifest: BUILD_MANIFEST,
testRunID: "${env.BUILD_NUMBER}",
testType: "integ-test",
testType: 'integ-test',
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")
Expand Down
18 changes: 16 additions & 2 deletions tests/jenkins/TestOpenSearchIntegTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class TestOpenSearchIntegTest extends BuildPipelineTest {
return new Yaml().load((testManifest as File).text)
} else if (args.file == 'tests/jenkins/data/opensearch-3.0.0-build.yml') {
return new Yaml().load((buildManifest as File).text)
} else {
println("Manifest not found ${args.file}")
}
})
helper.addFileExistsMock("manifests/${testManifest}", true)
Expand All @@ -88,6 +90,7 @@ class TestOpenSearchIntegTest extends BuildPipelineTest {
'tests/jenkins/jenkinsjob-regression-files/opensearch/integ-test.jenkinsfile')
assertThat(getCommandExecutions('sh', 'test.sh'), hasItem('env PATH=$PATH JAVA_HOME=/opt/java/openjdk-17 ./test.sh integ-test manifests/tests/jenkins/data/opensearch-3.0.0-test.yml --component k-NN --test-run-id 234 --paths opensearch=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/9010/linux/x64/tar '))
assertThat(getCommandExecutions('sh', 'report.sh'), hasItem('./report.sh manifests/tests/jenkins/data/opensearch-3.0.0-test.yml --artifact-paths opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/3.0.0/9010/linux/x64/tar --test-run-id 234 --test-type integ-test --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/9010/linux/x64/tar '))
assertThat(getCommandExecutions('echo', 'Testing'), hasItem('Testing components: [ml-commons, anomaly-detection, neural-search, security-analytics, security, k-NN, notifications]'))
}

@Test
Expand All @@ -104,12 +107,20 @@ class TestOpenSearchIntegTest extends BuildPipelineTest {
assertJobStatusFailure()
}

@Test
void checkErrorForMissingComponentFromTestManifest() {
addParam('COMPONENT_NAME', 'sql')
runScript('jenkins/opensearch/integ-test.jenkinsfile')
assertThat(getCommandExecutions('echo', 'sql'), hasItem('Skipping tests for sql as is not present in the provided build manifest.'))
}

@Test
void checkGHissueCreation() {
helper.addShMock("date -d \"3 days ago\" +'%Y-%m-%d'") { script ->
return [stdout: "2023-10-24", exitValue: 0]
}
helper.addShMock('env PATH=$PATH JAVA_HOME=/opt/java/openjdk-17 ./test.sh integ-test manifests/tests/jenkins/data/opensearch-3.0.0-test.yml --component k-NN --test-run-id 234 --paths opensearch=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/9010/linux/x64/tar', '', 1)
helper.addShMock("""env PATH=\$PATH JAVA_HOME=/opt/java/openjdk-17 ./test.sh integ-test manifests/tests/jenkins/data/opensearch-3.0.0-test.yml --component k-NN --test-run-id 234 --paths opensearch=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/9010/linux/x64/tar """) { script ->
return [stdout: "Error running integtest for component k-NN, creating Github issue", exitValue: 1]}
helper.addShMock("""gh issue list --repo https://github.com/opensearch-project/k-NN.git -S "[AUTOCUT] Integration Test failed for k-NN: 3.0.0 tar distribution in:title" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number'""") { script ->
return [stdout: "", exitValue: 0]
}
Expand All @@ -128,7 +139,10 @@ class TestOpenSearchIntegTest extends BuildPipelineTest {
helper.addShMock("date -d \"5 days ago\" +'%Y-%m-%d'") { script ->
return [stdout: "2023-10-24", exitValue: 0]
}
helper.addShMock('env PATH=$PATH JAVA_HOME=/opt/java/openjdk-17 ./test.sh integ-test manifests/tests/jenkins/data/opensearch-3.0.0-test.yml --component k-NN --test-run-id 234 --paths opensearch=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/9010/linux/x64/tar ', '', 0)
helper.addShMock("""env PATH=\$PATH JAVA_HOME=/opt/java/openjdk-17 ./test.sh integ-test manifests/tests/jenkins/data/opensearch-3.0.0-test.yml --component k-NN --test-run-id 234 --paths opensearch=/tmp/workspace/tar --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_job/3.0.0/8184/linux/x64/tar""") { script ->
return [stdout: "Completed running integtest for component k-NN", exitValue: 0]
}
runScript('jenkins/opensearch/integ-test.jenkinsfile')
assertThat(getCommandExecutions('sh', 'script'), hasItem("{script=gh issue list --repo https://github.com/opensearch-project/k-NN.git -S \"[AUTOCUT] Integration Test failed for k-NN: 3.0.0 tar distribution in:title\" --label autocut,v3.0.0,integ-test-failure --json number --jq '.[0].number', returnStdout=true}"))
assertThat(getCommandExecutions('sh', 'script'), hasItem("{script=gh issue close bbb\nccc -R opensearch-project/k-NN --comment \"Closing the issue as the Integration Test passed for k-NN<br>Version: 3.0.0<br>Distribution: tar<br>Architecture: x64<br>Platform: linux<br><br>Please check the logs: https://some/url/redirect<br><br> *\", returnStdout=true}"))
}
Expand Down
Loading

0 comments on commit 6e73f0c

Please sign in to comment.