Skip to content

Commit

Permalink
Use latest image for OSD integ test (opensearch-project#1748)
Browse files Browse the repository at this point in the history
* use the osd test image

Signed-off-by: Tianle Huang <[email protected]>

* use image

Signed-off-by: Tianle Huang <[email protected]>

* fix schema

Signed-off-by: Tianle Huang <[email protected]>

* fix flake8

Signed-off-by: Tianle Huang <[email protected]>

* add unit test

Signed-off-by: Tianle Huang <[email protected]>

* use test manifest

Signed-off-by: Tianle Huang <[email protected]>

* use build job name

Signed-off-by: Tianle Huang <[email protected]>

* test

Signed-off-by: Tianle Huang <[email protected]>

* remove

Signed-off-by: Tianle Huang <[email protected]>

* update syntax

Signed-off-by: Tianle Huang <[email protected]>

* simplify

Signed-off-by: Tianle Huang <[email protected]>

* add test for the ci image

Signed-off-by: Tianle Huang <[email protected]>

* fix style

Signed-off-by: Tianle Huang <[email protected]>
  • Loading branch information
tianleh committed Mar 15, 2022
1 parent ae11713 commit 947ab86
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 3 deletions.
4 changes: 2 additions & 2 deletions jenkins/opensearch-dashboards/distribution-build.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pipeline {
string(name: 'TEST_MANIFEST', value: TEST_MANIFEST),
string(name: 'BUILD_MANIFEST_URL', value: buildManifestUrl),
string(name: 'AGENT_LABEL', value: AGENT_X64),
string(name: 'CONTAINER_IMAGE', value: dockerAgent.image)
string(name: 'CONTAINER_IMAGE', value: getTestDocker(testManifest: "manifests/${TEST_MANIFEST}")?.image ?: dockerAgent.image)
]

String status = integTestResults.getResult()
Expand Down Expand Up @@ -148,7 +148,7 @@ pipeline {
string(name: 'TEST_MANIFEST', value: TEST_MANIFEST),
string(name: 'BUILD_MANIFEST_URL', value: buildManifestUrl),
string(name: 'AGENT_LABEL', value: AGENT_ARM64),
string(name: 'CONTAINER_IMAGE', value: dockerAgent.image)
string(name: 'CONTAINER_IMAGE', value: getTestDocker(testManifest: "manifests/${TEST_MANIFEST}")?.image ?: dockerAgent.image)
]

String status = integTestResults.getResult()
Expand Down
3 changes: 3 additions & 0 deletions manifests/1.3.0/opensearch-dashboards-1.3.0-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
schema-version: '1.0'
name: OpenSearch Dashboards
ci:
image:
name: opensearchstaging/ci-runner:ci-runner-rockylinux8-opensearch-dashboards-integtest-v1
components:
- name: functionalTestDashboards
integ-test:
Expand Down
3 changes: 3 additions & 0 deletions manifests/2.0.0/opensearch-dashboards-2.0.0-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
schema-version: '1.0'
name: OpenSearch Dashboards
ci:
image:
name: opensearchstaging/ci-runner:ci-runner-rockylinux8-opensearch-dashboards-integtest-v1
components:
- name: OpenSearch-Dashboards
bwc-test:
Expand Down
38 changes: 38 additions & 0 deletions src/jenkins/TestManifest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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

class TestManifest {
class Ci implements Serializable {
class Image implements Serializable {
String name
String args

Image(Map data) {
this.name = data.name
this.args = data.args
}
}

Image image

Ci(Map data) {
this.image = new TestManifest.Ci.Image(data.image)
}
}

String name

Ci ci

TestManifest(Map data) {
this.name = data.name
this.ci = data.ci ? new TestManifest.Ci(data.ci) : null
}
}
37 changes: 36 additions & 1 deletion src/manifests/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

from typing import Any
from typing import Any, Optional

from manifests.component_manifest import Component, ComponentManifest, Components

Expand All @@ -16,6 +16,10 @@ class TestManifest(ComponentManifest['TestManifest', 'TestComponents']):
The format for schema version 1.0 is:
schema-version: '1.0'
name: 'OpenSearch'
ci:
image:
name: docker image name to pull
args: args to execute builds with, e.g. -e JAVA_HOME=...
components:
- name: index-management
working-directory: optional relative directory to run commands in
Expand All @@ -35,6 +39,17 @@ class TestManifest(ComponentManifest['TestManifest', 'TestComponents']):
SCHEMA = {
"schema-version": {"required": True, "type": "string", "allowed": ["1.0"]},
"name": {"required": True, "type": "string", "allowed": ["OpenSearch", "OpenSearch Dashboards"]},
"ci": {
"required": False,
"type": "dict",
"schema": {
"image": {
"required": False,
"type": "dict",
"schema": {"name": {"required": True, "type": "string"}, "args": {"required": False, "type": "string"}},
}
},
},
"components": {
"type": "list",
"schema": {
Expand Down Expand Up @@ -65,15 +80,35 @@ class TestManifest(ComponentManifest['TestManifest', 'TestComponents']):
def __init__(self, data: Any) -> None:
super().__init__(data)
self.name = str(data["name"])
self.ci = self.Ci(data.get("ci", None))
self.components = TestComponents(data.get("components", [])) # type: ignore[assignment]

def __to_dict__(self) -> dict:
return {
"schema-version": "1.0",
"name": self.name,
"ci": None if self.ci is None else self.ci.__to_dict__(),
"components": self.components.__to_dict__()
}

class Ci:
def __init__(self, data: Any):
self.image = None if data is None else self.Image(data.get("image", None))

def __to_dict__(self) -> Optional[dict]:
return None if self.image is None else {"image": self.image.__to_dict__()}

class Image:
def __init__(self, data: Any):
self.name = data["name"]
self.args = data.get("args", None)

def __to_dict__(self) -> dict:
return {
"name": self.name,
"args": self.args
}


class TestComponents(Components['TestComponent']):
@classmethod
Expand Down
20 changes: 20 additions & 0 deletions tests/jenkins/TestGetTestDocker.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test


class TestGetTestDocker extends BuildPipelineTest {

@Test
public void test() {
super.testPipeline("tests/jenkins/jobs/GetTestDocker_Jenkinsfile")
}
}
22 changes: 22 additions & 0 deletions tests/jenkins/jobs/GetTestDocker_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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('get test docker') {
steps {
script {
getTestDocker(
testManifest: 'tests/jenkins/data/opensearch-1.3.0-test.yml',
)
}
}
}
}
}
11 changes: 11 additions & 0 deletions tests/jenkins/jobs/GetTestDocker_Jenkinsfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
GetTestDocker_Jenkinsfile.run()
GetTestDocker_Jenkinsfile.pipeline(groovy.lang.Closure)
GetTestDocker_Jenkinsfile.echo(Executing on agent [label:none])
GetTestDocker_Jenkinsfile.stage(get test docker, groovy.lang.Closure)
GetTestDocker_Jenkinsfile.script(groovy.lang.Closure)
GetTestDocker_Jenkinsfile.getTestDocker({testManifest=tests/jenkins/data/opensearch-1.3.0-test.yml})
getTestDocker.legacySCM(groovy.lang.Closure)
getTestDocker.library({identifier=jenkins@20211123, retriever=null})
getTestDocker.readYaml({file=tests/jenkins/data/opensearch-1.3.0-test.yml})
TestManifest.asBoolean()
getTestDocker.echo(Using Docker image null (null))
12 changes: 12 additions & 0 deletions tests/tests_manifests/data/opensearch-dashboards-test-1.3.0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
schema-version: '1.0'
name: OpenSearch Dashboards
ci:
image:
name: opensearchstaging/ci-runner:ci-runner-rockylinux8-opensearch-dashboards-integtest-v1
components:
- name: functionalTestDashboards
integ-test:
test-configs:
- with-security
- without-security
22 changes: 22 additions & 0 deletions tests/tests_manifests/test_test_manifest_with_ci_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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 os
import unittest

from manifests.test_manifest import TestManifest


class TestTestManifest(unittest.TestCase):
def setUp(self) -> None:
self.maxDiff = None
self.data_path = os.path.realpath(os.path.join(os.path.dirname(__file__), "data"))
self.manifest_filename = os.path.join(self.data_path, "opensearch-dashboards-test-1.3.0.yml")
self.manifest = TestManifest.from_path(self.manifest_filename)

def test_component(self) -> None:
self.assertEqual(self.manifest.name, "OpenSearch Dashboards")
self.assertEqual(self.manifest.ci.image.name, "opensearchstaging/ci-runner:ci-runner-rockylinux8-opensearch-dashboards-integtest-v1")
12 changes: 12 additions & 0 deletions vars/getTestDocker.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Map call(Map args = [:]) {
def lib = library(identifier: "jenkins@20211123", retriever: legacySCM(scm))
def testManifest = lib.jenkins.TestManifest.new(readYaml(file: args.testManifest))

dockerImage = testManifest.ci?.image?.name
dockerArgs = testManifest.ci?.image?.args
echo "Using Docker image ${dockerImage} (${dockerArgs})"
return [
image: dockerImage,
args: dockerArgs
]
}

0 comments on commit 947ab86

Please sign in to comment.