Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lay groundwork for RFS jenkins job #18

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8d61d53
Lay groundwork for RFS jenkins job
lewijacn Sep 5, 2024
16ded78
Further updates from testing
lewijacn Sep 6, 2024
df35533
Test for getting branch
lewijacn Sep 6, 2024
5f25a1d
Test getting branch name
lewijacn Sep 6, 2024
b2e740f
Test passing branch details
lewijacn Sep 6, 2024
1dd3c76
Modify integ tests for quick test
lewijacn Sep 6, 2024
e5e221b
Edit string population
lewijacn Sep 6, 2024
581ad9f
Update errored pipeline file
lewijacn Sep 6, 2024
6f7ecfb
Cleaner interface and test lockable option
lewijacn Sep 6, 2024
46dc199
Add lock print statement
lewijacn Sep 6, 2024
c984dd1
Pipeline updates for generic trigger
lewijacn Sep 6, 2024
d6f4a4d
Groovy error fix
lewijacn Sep 6, 2024
3667e52
Updates from testing
lewijacn Sep 7, 2024
ffdb190
Update branch name for push
lewijacn Sep 7, 2024
1a2572c
Test checkout jenkinsfile
lewijacn Sep 7, 2024
c77a372
Revert checkout jenkins file
lewijacn Sep 7, 2024
269e6da
Add cover layer and rename backfill integ
lewijacn Sep 7, 2024
a6735f8
Swap to call command
lewijacn Sep 7, 2024
98a9419
Use cover format for to enable loading changes from feature branches …
lewijacn Sep 7, 2024
8a4665f
Minor fixes from PR
lewijacn Sep 9, 2024
8f4f30a
Update github action
lewijacn Sep 9, 2024
3620dcc
Adjust for fork using secrets
lewijacn Sep 9, 2024
42b84af
Update workflow permissions
lewijacn Sep 9, 2024
760ac14
Update action targets
lewijacn Sep 9, 2024
05e5acb
Updates from testing on fork
lewijacn Sep 9, 2024
129979d
Merge remote-tracking branch 'origin/main' into add-rfs-jenkins-job
lewijacn Sep 9, 2024
49bddde
Update to use marketplace github action for jenkins triggering
lewijacn Sep 18, 2024
0af816a
Update marketplace action name
lewijacn Sep 18, 2024
b38ee70
Update version
lewijacn Sep 18, 2024
d4914f8
Update action version for webhook
lewijacn Sep 18, 2024
bdf9def
Update action version for webhook
lewijacn Sep 18, 2024
b8e6896
Update action version for webhook
lewijacn Sep 18, 2024
c33ceed
Update action version for webhook
lewijacn Sep 18, 2024
7570523
Update workflow to parse git repo and branch and pass to action
lewijacn Sep 19, 2024
fb713a1
Update action version
lewijacn Sep 19, 2024
05461c5
Update .github/workflows/rfs_pr_e2e_test.yml
lewijacn Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/rfs_pr_e2e_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Jenkins

on:
push:
branches-ignore:
- 'backport/**'
- 'dependabot/**'
pull_request_target:
types: [opened, synchronize, reopened]

env:
python-version: '3.11'

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
rfs-e2e-aws-test:
runs-on: ubuntu-latest
steps:
- name: Determine Github repository and branch
id: determine-repo-vars
run: |
if [[ "${GITHUB_EVENT_NAME}" == "pull_request_target" ]]; then
branch_name="${{ github.event.pull_request.head.ref }}"
pr_repo_url="https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git"
else
branch_name="${{ github.ref_name }}"
pr_repo_url="https://github.com/${{ github.repository }}.git"
fi
echo "Running jenkins test on repo: $pr_repo_url and branch: $branch_name"
echo "branch_name=$branch_name" >> $GITHUB_OUTPUT
echo "pr_repo_url=$pr_repo_url" >> $GITHUB_OUTPUT
- name: Jenkins Job Trigger and Monitor
uses: lewijacn/[email protected]
with:
jenkins_url: "https://migrations.ci.opensearch.org"
job_name: "rfs-default-e2e-test"
api_token: "${{ secrets.JENKINS_MIGRATIONS_GENERIC_WEBHOOK_TOKEN }}"
job_params: "GIT_REPO_URL=${{ steps.determine-repo-vars.outputs.pr_repo_url }},GIT_BRANCH=${{ steps.determine-repo-vars.outputs.branch_name }}"
78 changes: 0 additions & 78 deletions jenkins/migrationIntegPipelines/rfsBackfillE2EPipeline.groovy

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def gitBranch = params.GIT_BRANCH ?: 'main'
def gitUrl = params.GIT_REPO_URL ?: 'https://github.com/opensearch-project/opensearch-migrations.git'

library identifier: "migrations-lib@${gitBranch}", retriever: modernSCM(
[$class: 'GitSCMSource',
remote: "${gitUrl}"])

// Shared library function (location from root: vars/rfsDefaultE2ETest.groovy)
rfsDefaultE2ETest()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def gitBranch = params.GIT_BRANCH ?: 'main'
def gitUrl = params.GIT_REPO_URL ?: 'https://github.com/opensearch-project/opensearch-migrations.git'

library identifier: "migrations-lib@${gitBranch}", retriever: modernSCM(
[$class: 'GitSCMSource',
remote: "${gitUrl}"])

// Shared library function (location from root: vars/trafficReplayDefaultE2ETest.groovy)
trafficReplayDefaultE2ETest()
39 changes: 33 additions & 6 deletions vars/defaultIntegPipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ def call(Map config = [:]) {
def sourceContext = config.sourceContext
def migrationContext = config.migrationContext
def defaultStageId = config.defaultStageId
def jobName = config.jobName
if(sourceContext == null || sourceContext.isEmpty()){
throw new RuntimeException("The sourceContext argument must be provided");
}
Expand All @@ -11,11 +12,16 @@ def call(Map config = [:]) {
if(defaultStageId == null || defaultStageId.isEmpty()){
throw new RuntimeException("The defaultStageId argument must be provided");
}
if(jobName == null || jobName.isEmpty()){
throw new RuntimeException("The jobName argument must be provided");
}
def source_context_id = config.sourceContextId ?: 'source-single-node-ec2'
def migration_context_id = config.migrationContextId ?: 'migration-default'
def source_context_file_name = 'sourceJenkinsContext.json'
def migration_context_file_name = 'migrationJenkinsContext.json'
def skipCaptureProxyOnNodeSetup = config.skipCaptureProxyOnNodeSetup ?: false
def testDir = "/root/lib/integ_test/integ_test"
def integTestCommand = config.integTestCommand ?: "${testDir}/replayer_tests.py"
pipeline {
agent { label config.workerAgent ?: 'Jenkins-Default-Agent-X64-C5xlarge-Single-Host' }

Expand All @@ -25,6 +31,27 @@ def call(Map config = [:]) {
string(name: 'STAGE', defaultValue: "${defaultStageId}", description: 'Stage name for deployment environment')
}

options {
// Acquire lock on a given deployment stage
lock(label: params.STAGE, quantity: 1, variable: 'stage')
timeout(time: 3, unit: 'HOURS')
buildDiscarder(logRotator(daysToKeepStr: '30'))
}

triggers {
GenericTrigger(
genericVariables: [
[key: 'GIT_REPO_URL', value: '$.GIT_REPO_URL'],
[key: 'GIT_BRANCH', value: '$.GIT_BRANCH'],
[key: 'job_name', value: '$.job_name']
],
tokenCredentialId: 'jenkins-migrations-generic-webhook-token',
causeString: 'Triggered by PR on opensearch-migrations repository',
regexpFilterExpression: "^$jobName\$",
regexpFilterText: "\$job_name",
)
}

stages {
stage('Checkout') {
steps {
Expand Down Expand Up @@ -92,13 +119,14 @@ def call(Map config = [:]) {
if (config.deployStep) {
config.deployStep()
} else {
echo "Acquired deployment stage: ${stage}"
sh 'sudo usermod -aG docker $USER'
sh 'sudo newgrp docker'
def baseCommand = "sudo --preserve-env ./awsE2ESolutionSetup.sh --source-context-file './$source_context_file_name' " +
"--migration-context-file './$migration_context_file_name' " +
"--source-context-id $source_context_id " +
"--migration-context-id $migration_context_id " +
"--stage ${params.STAGE} " +
"--stage ${stage} " +
"--migrations-git-url ${params.GIT_REPO_URL} " +
"--migrations-git-branch ${params.GIT_BRANCH}"
if (skipCaptureProxyOnNodeSetup) {
Expand Down Expand Up @@ -127,17 +155,16 @@ def call(Map config = [:]) {
} else {
def time = new Date().getTime()
def uniqueId = "integ_min_${time}_${currentBuild.number}"
def test_dir = "/root/lib/integ_test/integ_test"
def test_result_file = "${test_dir}/reports/${uniqueId}/report.xml"
def command = "pipenv run pytest --log-file=${test_dir}/reports/${uniqueId}/pytest.log " +
"--junitxml=${test_result_file} ${test_dir}/replayer_tests.py " +
def test_result_file = "${testDir}/reports/${uniqueId}/report.xml"
def command = "pipenv run pytest --log-file=${testDir}/reports/${uniqueId}/pytest.log " +
"--junitxml=${test_result_file} ${integTestCommand} " +
"--unique_id ${uniqueId} " +
"-s"
withCredentials([string(credentialsId: 'migrations-test-account-id', variable: 'MIGRATIONS_TEST_ACCOUNT_ID')]) {
withAWS(role: 'JenkinsDeploymentRole', roleAccount: "${MIGRATIONS_TEST_ACCOUNT_ID}", duration: 3600, roleSessionName: 'jenkins-session') {
sh "sudo --preserve-env ./awsRunIntegTests.sh --command '${command}' " +
"--test-result-file ${test_result_file} " +
"--stage ${params.STAGE}"
"--stage ${stage}"
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions vars/rfsDefaultE2ETest.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Note:
// 1. There is a still a manual step needed on the EC2 source load balancer to replace its security group rule which allows all traffic (0.0.0.0/0) to
// allow traffic for the relevant service security group. This needs a better story around accepting user security groups in our Migration CDK.

def call(Map config = [:]) {
def sourceContextId = 'source-single-node-ec2'
def migrationContextId = 'migration-rfs'
def source_cdk_context = """
{
"source-single-node-ec2": {
"suffix": "ec2-source-<STAGE>",
"networkStackSuffix": "ec2-source-<STAGE>",
"distVersion": "7.10.2",
"distributionUrl": "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-oss-7.10.2-linux-x86_64.tar.gz",
"captureProxyEnabled": false,
"securityDisabled": true,
"minDistribution": false,
"cpuArch": "x64",
"isInternal": true,
"singleNodeCluster": true,
"networkAvailabilityZones": 2,
"dataNodeCount": 1,
"managerNodeCount": 0,
"serverAccessType": "ipv4",
"restrictServerAccessTo": "0.0.0.0/0"
}
}
"""
def migration_cdk_context = """
{
"migration-rfs": {
"stage": "<STAGE>",
"vpcId": "<VPC_ID>",
"engineVersion": "OS_2.11",
"domainName": "os-cluster-<STAGE>",
"dataNodeCount": 2,
"openAccessPolicyEnabled": true,
"domainRemovalPolicy": "DESTROY",
"artifactBucketRemovalPolicy": "DESTROY",
"trafficReplayerServiceEnabled": false,
"reindexFromSnapshotServiceEnabled": true,
"sourceClusterEndpoint": "<SOURCE_CLUSTER_ENDPOINT>"
}
}
"""

defaultIntegPipeline(
sourceContext: source_cdk_context,
migrationContext: migration_cdk_context,
sourceContextId: sourceContextId,
migrationContextId: migrationContextId,
defaultStageId: 'rfs-integ',
skipCaptureProxyOnNodeSetup: true,
jobName: 'rfs-default-e2e-test',
integTestCommand: '/root/lib/integ_test/integ_test/backfill_tests.py'
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
// 1. There is a still a manual step needed on the EC2 source load balancer to replace its security group rule which allows all traffic (0.0.0.0/0) to
// allow traffic for the relevant service security group. This needs a better story around accepting user security groups in our Migration CDK.

def sourceContextId = 'source-single-node-ec2'
def migrationContextId = 'migration-default'
// These default values should only be used on the initial Jenkins run in order to load parameter options into the UI,
// all future runs should use the specified parameters
def gitBranch = params.GIT_BRANCH ?: 'main'
def gitUrl = params.GIT_REPO_URL ?: 'https://github.com/opensearch-project/opensearch-migrations.git'
def source_cdk_context = """
def call(Map config = [:]) {
def sourceContextId = 'source-single-node-ec2'
def migrationContextId = 'migration-default'
def source_cdk_context = """
{
"source-single-node-ec2": {
"suffix": "ec2-source-<STAGE>",
Expand All @@ -29,8 +26,8 @@ def source_cdk_context = """
"restrictServerAccessTo": "0.0.0.0/0"
}
}
"""
def migration_cdk_context = """
"""
def migration_cdk_context = """
{
"migration-default": {
"stage": "<STAGE>",
Expand All @@ -50,19 +47,17 @@ def migration_cdk_context = """
"migrationAPIEnabled": true
}
}
"""
"""

library identifier: "migrations-lib@${gitBranch}", retriever: modernSCM(
[$class: 'GitSCMSource',
remote: "${gitUrl}"])

defaultIntegPipeline(
sourceContext: source_cdk_context,
migrationContext: migration_cdk_context,
sourceContextId: sourceContextId,
migrationContextId: migrationContextId,
defaultStageId: 'aws-integ',
//deployStep: {
// echo 'Custom Test Step'
//}
)
defaultIntegPipeline(
sourceContext: source_cdk_context,
migrationContext: migration_cdk_context,
sourceContextId: sourceContextId,
migrationContextId: migrationContextId,
defaultStageId: 'aws-integ',
jobName: 'traffic-replay-default-e2e-test',
//deployStep: {
// echo 'Custom Test Step'
//}
)
}
Loading