Skip to content

Commit

Permalink
Add library to create test report manifest (#270)
Browse files Browse the repository at this point in the history
Signed-off-by: Zelin Hao <[email protected]>
(cherry picked from commit b5c7537)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Aug 18, 2023
1 parent e96b5de commit a4fc816
Show file tree
Hide file tree
Showing 6 changed files with 334 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/data/opensearch-dashboards-1.3.0-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
schema-version: '1.0'
name: OpenSearch Dashboards
components:
- name: functionalTestDashboards
integ-test:
test-configs:
- with-security
- without-security
- name: queryWorkbenchDashboards
bwc-test:
test-configs:
- with-security
- without-security
47 changes: 47 additions & 0 deletions tests/jenkins/TestCreateUploadTestReportManifest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.
*/

package jenkins.tests

import org.junit.Test
import static com.lesfurets.jenkins.unit.MethodCall.callArgsToString
import static org.hamcrest.CoreMatchers.hasItems
import static org.hamcrest.MatcherAssert.assertThat


class TestCreateUploadTestReportManifest extends BuildPipelineTest {

@Test
public void TestCreateUploadTestReportManifest() {
this.registerLibTester(new CreateUploadTestReportManifestLibTester(
'tests/data/opensearch-1.3.0-test.yml',
'tests/data/opensearch-1.3.0-build.yml',
'tests/data/opensearch-dashboards-build-1.3.0.yml',
'1234',
'integ-test',
'',
)
)
super.setUp()
super.testPipeline("tests/jenkins/jobs/CreateUploadTestReportManifest_Jenkinsfile")
assertThat(getShellCommands('sh', 'report.sh'), hasItems('./report.sh tests/data/opensearch-1.3.0-test.yml --artifact-paths opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar --test-run-id 1234 --test-type integ-test --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar '))
assertThat(getShellCommands('sh', 'report.sh'), hasItems('./report.sh tests/data/opensearch-dashboards-1.3.0-test.yml --artifact-paths opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar opensearch-dashboards=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1.3.0/25b38c278cdd45efa583765d8ba76346/linux/x64/tar --test-run-id 1234 --test-type integ-test --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar '))
}

def getShellCommands(methodName, searchString) {
def shCommands = helper.callStack.findAll { call ->
call.methodName == methodName
}.collect { call ->
callArgsToString(call)
}.findAll { command ->
command.contains(searchString)
}
return shCommands
}
}
33 changes: 33 additions & 0 deletions tests/jenkins/jobs/CreateUploadTestReportManifest_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.
*/

pipeline {
agent none
stages {
stage('create-test-run-manifest') {
steps {
script {
createUploadTestReportManifest(
testManifest: "tests/data/opensearch-1.3.0-test.yml",
buildManifest: "tests/data/opensearch-1.3.0-build.yml",
testRunID: "1234",
testType: "integ-test",
)
createUploadTestReportManifest(
testManifest: "tests/data/opensearch-dashboards-1.3.0-test.yml",
buildManifest: "tests/data/opensearch-1.3.0-build.yml",
dashboardsBuildManifest: "tests/data/opensearch-dashboards-build-1.3.0.yml",
testRunID: "1234",
testType: "integ-test",
)
}
}
}
}
}
56 changes: 56 additions & 0 deletions tests/jenkins/jobs/CreateUploadTestReportManifest_Jenkinsfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CreateUploadTestReportManifest_Jenkinsfile.run()
CreateUploadTestReportManifest_Jenkinsfile.pipeline(groovy.lang.Closure)
CreateUploadTestReportManifest_Jenkinsfile.echo(Executing on agent [label:none])
CreateUploadTestReportManifest_Jenkinsfile.stage(create-test-run-manifest, groovy.lang.Closure)
CreateUploadTestReportManifest_Jenkinsfile.script(groovy.lang.Closure)
CreateUploadTestReportManifest_Jenkinsfile.createUploadTestReportManifest({testManifest=tests/data/opensearch-1.3.0-test.yml, buildManifest=tests/data/opensearch-1.3.0-build.yml, testRunID=1234, testType=integ-test})
createUploadTestReportManifest.legacySCM(groovy.lang.Closure)
createUploadTestReportManifest.library({identifier=jenkins@main, retriever=null})
createUploadTestReportManifest.readYaml({file=tests/data/opensearch-1.3.0-test.yml})
TestManifest.asBoolean()
createUploadTestReportManifest.readYaml({file=tests/data/opensearch-1.3.0-build.yml})
BuildManifest.asBoolean()
BuildManifest.getDistribution()
createUploadTestReportManifest.echo(Start Reporting workflow for test type: tar)
BuildManifest.getArtifactRootUrl(distribution-build-opensearch, c3ff7a232d25403fa8cc14c97799c323)
createUploadTestReportManifest.echo(Artifact root URL: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar)
createUploadTestReportManifest.echo(Paths: opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar)
createUploadTestReportManifest.echo(Base Path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar)
createUploadTestReportManifest.echo(Component: null)
createUploadTestReportManifest.echo(Run command: ./report.sh tests/data/opensearch-1.3.0-test.yml --artifact-paths opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar --test-run-id 1234 --test-type integ-test --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar )
createUploadTestReportManifest.sh(./report.sh tests/data/opensearch-1.3.0-test.yml --artifact-paths opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar --test-run-id 1234 --test-type integ-test --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar )
createUploadTestReportManifest.echo(Build Id: c3ff7a232d25403fa8cc14c97799c323)
BuildManifest.getArtifactRoot(dummy_integ_test, c3ff7a232d25403fa8cc14c97799c323)
createUploadTestReportManifest.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
createUploadTestReportManifest.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
createUploadTestReportManifest.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
createUploadTestReportManifest.echo(Uploading to s3://dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar/test-results/1234/integ-test/test-report.yml)
createUploadTestReportManifest.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
createUploadTestReportManifest.s3Upload({file=/tmp/workspace/test-report.yml, bucket=ARTIFACT_BUCKET_NAME, path=dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar/test-results/1234/integ-test/test-report.yml})
CreateUploadTestReportManifest_Jenkinsfile.createUploadTestReportManifest({testManifest=tests/data/opensearch-dashboards-1.3.0-test.yml, buildManifest=tests/data/opensearch-1.3.0-build.yml, dashboardsBuildManifest=tests/data/opensearch-dashboards-build-1.3.0.yml, testRunID=1234, testType=integ-test})
createUploadTestReportManifest.legacySCM(groovy.lang.Closure)
createUploadTestReportManifest.library({identifier=jenkins@main, retriever=null})
createUploadTestReportManifest.readYaml({file=tests/data/opensearch-dashboards-1.3.0-test.yml})
TestManifest.asBoolean()
createUploadTestReportManifest.readYaml({file=tests/data/opensearch-1.3.0-build.yml})
BuildManifest.asBoolean()
createUploadTestReportManifest.readYaml({file=tests/data/opensearch-dashboards-build-1.3.0.yml})
BuildManifest.asBoolean()
BuildManifest.getDistribution()
createUploadTestReportManifest.echo(Start Reporting workflow for test type: tar)
BuildManifest.getArtifactRootUrl(distribution-build-opensearch, c3ff7a232d25403fa8cc14c97799c323)
BuildManifest.getArtifactRootUrl(distribution-build-opensearch-dashboards, 25b38c278cdd45efa583765d8ba76346)
createUploadTestReportManifest.echo(Artifact root URL: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar)
createUploadTestReportManifest.echo(Paths: opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar opensearch-dashboards=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1.3.0/25b38c278cdd45efa583765d8ba76346/linux/x64/tar)
createUploadTestReportManifest.echo(Base Path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar)
createUploadTestReportManifest.echo(Component: null)
createUploadTestReportManifest.echo(Run command: ./report.sh tests/data/opensearch-dashboards-1.3.0-test.yml --artifact-paths opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar opensearch-dashboards=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1.3.0/25b38c278cdd45efa583765d8ba76346/linux/x64/tar --test-run-id 1234 --test-type integ-test --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar )
createUploadTestReportManifest.sh(./report.sh tests/data/opensearch-dashboards-1.3.0-test.yml --artifact-paths opensearch=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar opensearch-dashboards=https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/1.3.0/25b38c278cdd45efa583765d8ba76346/linux/x64/tar --test-run-id 1234 --test-type integ-test --base-path DUMMY_PUBLIC_ARTIFACT_URL/dummy_integ_test/1.3.0/c3ff7a232d25403fa8cc14c97799c323/linux/x64/tar )
createUploadTestReportManifest.echo(Build Id: 25b38c278cdd45efa583765d8ba76346)
BuildManifest.getArtifactRoot(dummy_integ_test, 25b38c278cdd45efa583765d8ba76346)
createUploadTestReportManifest.string({credentialsId=jenkins-artifact-bucket-name, variable=ARTIFACT_BUCKET_NAME})
createUploadTestReportManifest.string({credentialsId=jenkins-aws-account-public, variable=AWS_ACCOUNT_PUBLIC})
createUploadTestReportManifest.withCredentials([ARTIFACT_BUCKET_NAME, AWS_ACCOUNT_PUBLIC], groovy.lang.Closure)
createUploadTestReportManifest.echo(Uploading to s3://dummy_integ_test/1.3.0/25b38c278cdd45efa583765d8ba76346/linux/x64/tar/test-results/1234/integ-test/test-report.yml)
createUploadTestReportManifest.withAWS({role=opensearch-test, roleAccount=AWS_ACCOUNT_PUBLIC, duration=900, roleSessionName=jenkins-session}, groovy.lang.Closure)
createUploadTestReportManifest.s3Upload({file=/tmp/workspace/test-report.yml, bucket=ARTIFACT_BUCKET_NAME, path=dummy_integ_test/1.3.0/25b38c278cdd45efa583765d8ba76346/linux/x64/tar/test-results/1234/integ-test/test-report.yml})
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.
*/

import static org.hamcrest.CoreMatchers.notNullValue
import static org.hamcrest.MatcherAssert.assertThat


class CreateUploadTestReportManifestLibTester extends LibFunctionTester {

private String testType
private String componentName
private String buildManifest
private String testManifest
private String buildManifestDashboards
private String testRunID

public CreateUploadTestReportManifestLibTester(testManifest, buildManifest, buildManifestDashboards, testRunID, testType, componentName){
this.testManifest = testManifest
this.buildManifest = buildManifest
this.buildManifestDashboards = buildManifestDashboards
this.testRunID = testRunID
this.testType = testType
this.componentName = componentName
}

void configure(helper, binding) {
binding.setVariable('env', ['JOB_NAME': 'dummy_integ_test', 'BUILD_NUMBER': '487', 'PUBLIC_ARTIFACT_URL': 'DUMMY_PUBLIC_ARTIFACT_URL' ])
helper.registerAllowedMethod("withCredentials", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})
helper.registerAllowedMethod("withAWS", [Map, Closure], { args, closure ->
closure.delegate = delegate
return helper.callClosure(closure)
})
helper.registerAllowedMethod("s3Upload", [Map])
}

void parameterInvariantsAssertions(call) {
assertThat(call.args.testManifest.first(), notNullValue())
assertThat(call.args.buildManifest.first(), notNullValue())
assertThat(call.args.testRunID.first(), notNullValue())
assertThat(call.args.testType.first(), notNullValue())
}

boolean expectedParametersMatcher(call) {
return call.args.testManifest.first().toString().equals(this.testManifest)
&& call.args.buildManifest.first().toString().equals(this.buildManifest)
&& call.args.testRunID.first().toString().equals(this.testRunID)
&& call.args.testType.first().toString().equals(this.testType)
}

String libFunctionName() {
return 'createUploadTestReportManifest'
}
}
Loading

0 comments on commit a4fc816

Please sign in to comment.