From e4628f6f82b04a63b6238b96ab52263ec35fe20c Mon Sep 17 00:00:00 2001 From: Fatih Degirmenci Date: Sun, 19 Apr 2020 17:58:00 +0000 Subject: [PATCH] engine: Generate SDF for change Change-Id: I70e2747eccc0202d9502e61e7a3039b5efbd7c91 --- jjb/engine/engine-macros.yaml | 6 ++ jjb/engine/scripts/generate-sdf-for-change.sh | 67 +++++++++++++++++++ .../engine-verify-deploy-test.yaml | 13 ++-- .../verify-jobs/engine-verify-package.yaml | 9 ++- jjb/engine/verify-jobs/engine-verify-tox.yaml | 9 +-- 5 files changed, 94 insertions(+), 10 deletions(-) create mode 100755 jjb/engine/scripts/generate-sdf-for-change.sh diff --git a/jjb/engine/engine-macros.yaml b/jjb/engine/engine-macros.yaml index aa893b5b3..6dbbb20d5 100644 --- a/jjb/engine/engine-macros.yaml +++ b/jjb/engine/engine-macros.yaml @@ -28,6 +28,12 @@ !include-raw: ./scripts/tox.sh +- builder: + name: 'generate-sdf-for-change-macro' + builders: + - shell: + !include-raw: ./scripts/generate-sdf-for-change.sh + - builder: name: 'generate-ssh-keypair-macro' builders: diff --git a/jjb/engine/scripts/generate-sdf-for-change.sh b/jjb/engine/scripts/generate-sdf-for-change.sh new file mode 100755 index 000000000..cf888080b --- /dev/null +++ b/jjb/engine/scripts/generate-sdf-for-change.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +# ============LICENSE_START======================================================= +# Copyright (C) 2019 The Nordix Foundation. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ============LICENSE_END========================================================= + +# NOTE (fdegir): we do not need to do anything for the changes coming to infra/engine repo +if [[ "$GERRIT_PROJECT" == "infra/engine" ]]; then + exit 0 +fi + +echo "Info : Cloning infra/engine repository" +cd "$HOME" && /bin/rm -rf "$WORKSPACE" +git clone -q "$ENGINE_REPO_URL" "$WORKSPACE" + +export SDF_ORIGINAL="$WORKSPACE/engine/inventory/group_vars/all/sdf.yaml" +export SDF_PATCHSET="/tmp/sdf.yaml.$GERRIT_CHANGE_NUMBER" + +/bin/rm -rf "$SDF_PATCHSET" + +export TOOL_TYPE="${GERRIT_PROJECT//*\//}" +export TOOL_MATCH="false" +echo "Info : Tool type is $TOOL_TYPE" +echo "Info : Updating SDF with change SHA and refspec" +while IFS= read -r line; do + if [[ "$TOOL_MATCH" == "true" && "$line" =~ "version" ]]; then + echo "$line" | sed "s#version:.*#version: $GERRIT_PATCHSET_REVISION\n refspec: $GERRIT_REFSPEC#g" >> "$SDF_PATCHSET" + export TOOL_MATCH="false" + continue + fi + if [[ "$line" =~ "$TOOL_TYPE:" && "$TOOL_MATCH" == "false" ]]; then + export TOOL_MATCH="true" + fi + echo "$line" >> "$SDF_PATCHSET" +done < "$SDF_ORIGINAL" +# NOTE (fdegir): log the diff for possible troubleshooting +echo +echo "Info : Diff between original SDF and SDF generated for the change" +echo "-------------------------------------------------------------------------" +diff "$SDF_ORIGINAL" "$SDF_PATCHSET" +echo "-------------------------------------------------------------------------" +echo + +# NOTE (fdegir): move SDF generated for the change into the original SDF +/bin/mv -f "$SDF_PATCHSET" "$SDF_ORIGINAL" + +# NOTE (fdegir): log the final SDF +echo +echo "Info : Generated SDF content" +echo "-------------------------------------------------------------------------" +cat "$SDF_ORIGINAL" +echo "-------------------------------------------------------------------------" +echo diff --git a/jjb/engine/verify-jobs/engine-verify-deploy-test.yaml b/jjb/engine/verify-jobs/engine-verify-deploy-test.yaml index e24377b59..54a7fa870 100644 --- a/jjb/engine/verify-jobs/engine-verify-deploy-test.yaml +++ b/jjb/engine/verify-jobs/engine-verify-deploy-test.yaml @@ -54,11 +54,11 @@ - virtual: provisioner-type: 'bifrost' slave-type: 'vpod' - gated-projects: 'infra\/engine|infra\/provisioner\/bifrost\/|infra\/installer\/kolla\/|infra\/installer\/kubespray\/' + gated-projects: 'infra/engine|infra/provisioner/bifrost|infra/installer/kolla|infra/installer/kubespray' - cloud: provisioner-type: 'heat' slave-type: 'jumphost' - gated-projects: 'infra\/engine|infra\/provisioner\/heat\/|infra\/installer\/kolla\/|infra\/installer\/kubespray\/' + gated-projects: 'infra/engine|infra/provisioner/heat|infra/installer/kubespray' distro: - ubuntu1804 @@ -88,6 +88,10 @@ name: SLAVE_LABEL default: 'engine-{slave-type}-{environment-type}-{distro}' description: 'Slave label to schedule this job on.' + - string: + name: ENGINE_REPO_URL + default: 'https://gerrit.nordix.org/infra/engine.git' + description: 'URL to Nordix Cloud Infra engine repository' - string: name: EXECUTION_MODE default: '{execution-mode}' @@ -198,7 +202,7 @@ scm: - git-scm-gerrit: ssh-credentials-id: nordixinfra-nordix-gerrit-ssh - branch: '{branch}' + branch: refs/heads/$GERRIT_BRANCH refspec: $GERRIT_REFSPEC wipe_workspace: true clean_before: false @@ -329,7 +333,7 @@ scm: - git-scm-gerrit: ssh-credentials-id: nordixinfra-nordix-gerrit-ssh - branch: '{branch}' + branch: refs/heads/$GERRIT_BRANCH refspec: $GERRIT_REFSPEC wipe_workspace: true clean_before: false @@ -355,6 +359,7 @@ echo "Info : Offline deployment and testing on cloud instances is not currently supported!" exit 0 fi + - 'generate-sdf-for-change-macro' - 'generate-ssh-keypair-macro' - 'wait-pkg-mgr-macro' - 'download-artifact-macro' diff --git a/jjb/engine/verify-jobs/engine-verify-package.yaml b/jjb/engine/verify-jobs/engine-verify-package.yaml index 27f4b2e9d..8a7f1cdc3 100644 --- a/jjb/engine/verify-jobs/engine-verify-package.yaml +++ b/jjb/engine/verify-jobs/engine-verify-package.yaml @@ -27,7 +27,7 @@ branch: '{stream}' openrc-credentials-file: 'est-jenkins-openrcfile-city-karlskrona-onap' execution-mode: 'packaging' - gated-projects: 'infra\/engine' + gated-projects: 'infra/engine|infra/provisioner/bifrost|infra/provisioner/heat|infra/installer/kolla|infra/installer/kubespray' successful: false failed: false unstable: false @@ -62,6 +62,10 @@ name: VERBOSITY default: 'true' description: 'Verbosity setting for the engine - true or false - default is false' + - string: + name: ENGINE_REPO_URL + default: 'https://gerrit.nordix.org/infra/engine.git' + description: 'URL to Nordix Cloud Infra engine repository' - string: name: ARTIFACTS_TO_UPLOAD default: "k8s-installer-ubuntu1804.bsx" @@ -114,7 +118,7 @@ scm: - git-scm-gerrit: ssh-credentials-id: nordixinfra-nordix-gerrit-ssh - branch: '{branch}' + branch: refs/heads/$GERRIT_BRANCH refspec: $GERRIT_REFSPEC wipe_workspace: true clean_before: false @@ -179,6 +183,7 @@ builders: + - 'generate-sdf-for-change-macro' - 'generate-ssh-keypair-macro' - 'wait-pkg-mgr-macro' - 'package-macro' diff --git a/jjb/engine/verify-jobs/engine-verify-tox.yaml b/jjb/engine/verify-jobs/engine-verify-tox.yaml index 4561c13ec..3d34add81 100644 --- a/jjb/engine/verify-jobs/engine-verify-tox.yaml +++ b/jjb/engine/verify-jobs/engine-verify-tox.yaml @@ -25,6 +25,7 @@ stream: - 'master': branch: '{stream}' + gated-projects: 'infra/engine|infra/hwconfig|infra/swconfig|infra/test|infra/provisioner/bifrost|infra/provisioner/heat|infra/installer/kolla|infra/installer/kubespray' lint-type: - ansible-lint: @@ -32,7 +33,7 @@ repos-to-ignore: 'infra/hwconfig' - docs: disabled: false - repos-to-ignore: 'infra/hwconfig|infra/swconfig|infra/test' + repos-to-ignore: 'infra/hwconfig|infra/swconfig|infra/test|infra/provisioner/bifrost|infra/provisioner/heat|infra/installer/kolla|infra/installer/kubespray' - shellcheck: disabled: false repos-to-ignore: 'infra/hwconfig' @@ -75,7 +76,7 @@ scm: - git-scm-gerrit: ssh-credentials-id: nordixinfra-nordix-gerrit-ssh - branch: '{branch}' + branch: refs/heads/$GERRIT_BRANCH refspec: $GERRIT_REFSPEC wipe_workspace: true clean_before: false @@ -95,7 +96,7 @@ comment-contains-value: 'reverify' projects: - project-compare-type: 'REG_EXP' - project-pattern: 'infra\/engine|infra\/test|infra\/swconfig|infra\/hwconfig' + project-pattern: '{gated-projects}' branches: - branch-compare-type: 'ANT' branch-pattern: '**/{branch}' @@ -158,7 +159,7 @@ scm: - git-scm-gerrit: ssh-credentials-id: nordixinfra-nordix-gerrit-ssh - branch: '{branch}' + branch: refs/heads/$GERRIT_BRANCH refspec: $GERRIT_REFSPEC wipe_workspace: true clean_before: false -- 2.25.1