cloud-infra: Create periodic job for k8-calico-spinnaker

Change-Id: I5a87a32775ee5aa7f5f13eb4432f2a9b3216960a
diff --git a/jjb/cloud-infra/cloud-infra-periodic-spinnaker.yaml b/jjb/cloud-infra/cloud-infra-periodic-spinnaker.yaml
new file mode 100644
index 0000000..2590c42
--- /dev/null
+++ b/jjb/cloud-infra/cloud-infra-periodic-spinnaker.yaml
@@ -0,0 +1,392 @@
+---
+#
+# ============LICENSE_START=======================================================
+#  Copyright (C) 2019 Nordix Foundation.
+# ================================================================================
+# 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=========================================================
+
+#--------------------------------------------------------------------------------------
+# The jobs declared in this JJB configuration file are used for deploying and testing
+# Spinnaker using k8-calico-spinnaker scenario.
+#--------------------------------------------------------------------------------------
+
+- project:
+    name: 'cloud-infra-periodic-spinnaker'
+
+    project: 'infra/engine'
+
+    cloud:
+      - city:
+          slave-label: 'city-jumphost-ubuntu1804'
+          openrc-credentials-file: 'est-jenkins-openrcfile-city-frankfurt-onap'
+          daily-trigger: '@midnight'
+
+    spinnaker-branch:
+      - '1.16':
+          nordix-branch: master
+          engine-version: master
+          engine-refspec: master
+          deploy-scenario: 'k8-calico-spinnaker'
+          deploy-scenario-version: master
+          deploy-scenario-refspec: master
+          disabled: false
+          delete-stack: 'yes'
+
+    distro:
+      - ubuntu1804
+
+    ci-loop:
+      - daily
+
+    type:
+      - cloud:
+          pod-name: est-cloud
+          provisioner-type: heat
+          installer-type: kubespray
+
+    phase:
+      - spinnaker-deploy:
+          build-timeout: 60
+      - spinnaker-test:
+          build-timeout: 60
+      - promote-spinnaker:
+          build-timeout: 60
+
+    jobs:
+      - 'k8-calico-spinnaker-{distro}-{installer-type}-{cloud}-{type}-{ci-loop}-{spinnaker-branch}'
+      - '{phase}-{distro}-{installer-type}-{type}-{ci-loop}-{spinnaker-branch}'
+
+- job-template:
+    name: 'k8-calico-spinnaker-{distro}-{installer-type}-{cloud}-{type}-{ci-loop}-{spinnaker-branch}'
+
+    project-type: multijob
+
+    disabled: '{obj:disabled}'
+
+    concurrent: false
+
+    parameters:
+      - project-parameters:
+          project: '{project}'
+          branch: '{nordix-branch}'
+      - nordix-gerrit-parameters
+      - label:
+          name: SLAVE_LABEL
+          default: '{slave-label}'
+          description: 'Slave label to schedule this job on. All slaves have Ubuntu1604 no matter what distro target nodes use'
+      - string:
+          name: PROVISIONER_TYPE
+          default: 'heat'
+          description: 'Provisioner to use for provisioning nodes'
+      - string:
+          name: INSTALLER_TYPE
+          default: 'kubespray'
+          description: 'Installer to use for deploying the scenario'
+      - string:
+          name: DEPLOY_SCENARIO
+          default: 'k8-calico-spinnaker'
+          description: 'Scenario to deploy and test'
+      - string:
+          name: DEPLOY_TYPE
+          default: 'cloud'
+          description: 'Type of the deployment'
+      - string:
+          name: DISTRO
+          default: '{distro}'
+          description: 'Distribution to use for configuring target nodes (networking etc.)'
+      - string:
+          name: OPENSTACK_CLOUD_PROVIDER
+          default: '{cloud}'
+          description: 'Name of the cloud where this job is run'
+      - string:
+          name: SPINNAKER_VERSION
+          default: '{spinnaker-branch}'
+          description: 'Spinnaker version to deploy'
+      - string:
+          name: STACK_NAME
+          default: 'nordix-cicd-{deploy-scenario}-{spinnaker-branch}'
+      - string:
+          name: HEAT_ENVIRONMENT_FILENAME
+          default: "heat-environment-full.yaml"
+          description: 'Heat environment file to use for creating the stack'
+      - string:
+          name: ENGINE_VERSION
+          default: '{engine-version}'
+          description: 'Development purposes only! Nordix Cloud Infra Engine version to use for deploying Spinnaker. Could be sha, branch'
+      - string:
+          name: ENGINE_REFSPEC
+          default: '{engine-refspec}'
+          description: 'Development purposes only! Nordix Cloud Infra Engine version to use for deploying Spinnaker. Must be refspec.'
+      - string:
+          name: DEPLOY_SCENARIO_VERSION
+          default: '{deploy-scenario-version}'
+          description: 'Development purposes only! Nordix Cloud Infra Scenario version to use for deploying Spinnaker. Depends on DEPLOY_SCENARIO_REFSPEC and could be sha, branch.'
+      - string:
+          name: DEPLOY_SCENARIO_REFSPEC
+          default: '{deploy-scenario-refspec}'
+          description: 'Development purposes only! Nordix Cloud Infra Scenario version to use for deploying Spinnaker. Depends on DEPLOY_SCENARIO_VERSION and must be refspec.'
+      - string:
+          name: POD_NAME
+          default: '{pod-name}'
+          description: 'Development purposes only! Set to none for disabling test results DB reporting.'
+      - string:
+          name: DELETE_STACK
+          default: '{delete-stack}'
+          description: 'Development purposes only! Whether delete the stack or not. It must either be yes or no. Setting this to no will increase the cost!'
+
+    properties:
+      - logrotate
+      - build-blocker:
+          use-build-blocker: true
+          blocking-jobs:
+            - 'cloud-infra-periodic-engine-.*'
+            - 'onap-.*'
+            - 'k8-.*'
+          block-level: 'NODE'
+      - throttle:
+          max-per-node: 1
+          max-total: 1
+          option: project
+
+    wrappers:
+      - credentials-binding:
+          - file:
+              credential-id: '{openrc-credentials-file}'
+              variable: OPENRC_FILE
+      - mask-passwords
+      - build-timeout:
+          timeout: 630
+      - fix-workspace-permissions
+      - openstack:
+          single-use: True
+
+    triggers:
+      - timed: '{daily-trigger}'
+
+    scm:
+      - git-scm:
+          ssh-credentials-id: nordixinfra-nordix-gerrit-ssh
+          branch: '{nordix-branch}'
+          refspec: ''
+          wipe_workspace: true
+          clean_before: false
+
+    builders:
+      - description-setter:
+          description: $DEPLOY_SCENARIO | Spinnaker $SPINNAKER_VERSION
+      - shell: |
+          #!/bin/bash
+          /bin/rm -rf /tmp/openrc && /bin/cp -f $OPENRC_FILE /tmp/openrc
+      - multijob:
+          name: Deploy Spinnaker using Helm
+          condition: ALWAYS
+          projects:
+            - name: 'spinnaker-deploy-{distro}-{installer-type}-{type}-{ci-loop}-{spinnaker-branch}'
+              current-parameters: false
+              predefined-parameters: |
+                DISTRO=$DISTRO
+                OPENSTACK_CLOUD_PROVIDER=$OPENSTACK_CLOUD_PROVIDER
+                DEPLOY_TYPE=$DEPLOY_TYPE
+                PROVISIONER_TYPE=$PROVISIONER_TYPE
+                INSTALLER_TYPE=$INSTALLER_TYPE
+                DEPLOY_SCENARIO=$DEPLOY_SCENARIO
+                SPINNAKER_VERSION=$SPINNAKER_VERSION
+                POD_NAME=$POD_NAME
+                STACK_NAME=$STACK_NAME
+                HEAT_ENVIRONMENT_FILENAME=$HEAT_ENVIRONMENT_FILENAME
+                ENGINE_VERSION=$ENGINE_VERSION
+                ENGINE_REFSPEC=$ENGINE_REFSPEC
+                DEPLOY_SCENARIO_VERSION=$DEPLOY_SCENARIO_VERSION
+                DEPLOY_SCENARIO_REFSPEC=$DEPLOY_SCENARIO_REFSPEC
+              git-revision: true
+              node-parameters: true
+              kill-phase-on: NEVER
+              abort-all-job: false
+      - multijob:
+          name: Test Spinnaker Deployment (not activated)
+          condition: ALWAYS
+          projects:
+            - name: 'spinnaker-test-{distro}-{installer-type}-{type}-{ci-loop}-{spinnaker-branch}'
+              current-parameters: false
+              predefined-parameters: |
+                DISTRO=$DISTRO
+                OPENSTACK_CLOUD_PROVIDER=$OPENSTACK_CLOUD_PROVIDER
+                DEPLOY_TYPE=$DEPLOY_TYPE
+                PROVISIONER_TYPE=$PROVISIONER_TYPE
+                INSTALLER_TYPE=$INSTALLER_TYPE
+                DEPLOY_SCENARIO=$DEPLOY_SCENARIO
+                SPINNAKER_VERSION=$SPINNAKER_VERSION
+                POD_NAME=$POD_NAME
+                STACK_NAME=$STACK_NAME
+                HEAT_ENVIRONMENT_FILENAME=$HEAT_ENVIRONMENT_FILENAME
+                ENGINE_VERSION=$ENGINE_VERSION
+                ENGINE_REFSPEC=$ENGINE_REFSPEC
+                DEPLOY_SCENARIO_VERSION=$DEPLOY_SCENARIO_VERSION
+                DEPLOY_SCENARIO_REFSPEC=$DEPLOY_SCENARIO_REFSPEC
+              git-revision: true
+              node-parameters: true
+              kill-phase-on: NEVER
+              abort-all-job: false
+      - multijob:
+          name: Promote Spinnaker (not activated)
+          condition: ALWAYS
+          projects:
+            - name: 'promote-spinnaker-{distro}-{installer-type}-{type}-{ci-loop}-{spinnaker-branch}'
+              current-parameters: false
+              predefined-parameters: |
+                DISTRO=$DISTRO
+                OPENSTACK_CLOUD_PROVIDER=$OPENSTACK_CLOUD_PROVIDER
+                DEPLOY_TYPE=$DEPLOY_TYPE
+                PROVISIONER_TYPE=$PROVISIONER_TYPE
+                INSTALLER_TYPE=$INSTALLER_TYPE
+                DEPLOY_SCENARIO=$DEPLOY_SCENARIO
+                SPINNAKER_VERSION=$SPINNAKER_VERSION
+                POD_NAME=$POD_NAME
+                STACK_NAME=$STACK_NAME
+                HEAT_ENVIRONMENT_FILENAME=$HEAT_ENVIRONMENT_FILENAME
+                ENGINE_VERSION=$ENGINE_VERSION
+                ENGINE_REFSPEC=$ENGINE_REFSPEC
+                DEPLOY_SCENARIO_VERSION=$DEPLOY_SCENARIO_VERSION
+                DEPLOY_SCENARIO_REFSPEC=$DEPLOY_SCENARIO_REFSPEC
+              git-revision: true
+              node-parameters: true
+              kill-phase-on: NEVER
+              abort-all-job: false
+
+    publishers:
+      - postbuildscript:
+          builders:
+            - role: SLAVE
+              build-on:
+                - SUCCESS
+                - FAILURE
+                - ABORTED
+                - NOT_BUILT
+                - UNSTABLE
+              build-steps:
+                - shell:
+                    !include-raw-escape: ./wait-for-pkg-manager.sh
+                - shell:
+                    !include-raw: ./delete-heat-stack.sh
+
+- job-template:
+    name: '{phase}-{distro}-{installer-type}-{type}-{ci-loop}-{spinnaker-branch}'
+
+    disabled: false
+
+    concurrent: false
+
+    properties:
+      - logrotate
+
+    parameters:
+      - project-parameters:
+          project: '{project}'
+          branch: '{nordix-branch}'
+      - nordix-gerrit-parameters
+      - label:
+          name: SLAVE_LABEL
+          default: 'city-jumphost-ubuntu1804'
+          description: 'Slave label to schedule this job on. All slaves have Ubuntu1604 no matter what distro target nodes use'
+      - string:
+          name: PROVISIONER_TYPE
+          default: 'heat'
+          description: 'Provisioner to use for provisioning nodes'
+      - string:
+          name: INSTALLER_TYPE
+          default: 'kubespray'
+          description: 'Installer to use for deploying the scenario'
+      - string:
+          name: DEPLOY_SCENARIO
+          default: 'k8-calico-spinnaker'
+          description: 'Scenario to deploy and test'
+      - string:
+          name: DEPLOY_TYPE
+          default: 'cloud'
+          description: 'Type of the deployment'
+      - string:
+          name: DISTRO
+          default: '{distro}'
+          description: 'Distribution to use for configuring target nodes (networking etc.)'
+      - string:
+          name: OPENSTACK_CLOUD_PROVIDER
+          default: '{cloud}'
+          description: 'Name of the cloud where this job is run'
+      - string:
+          name: SPINNAKER_VERSION
+          default: '{spinnaker-branch}'
+          description: 'Spinnaker version to deploy'
+      - string:
+          name: STACK_NAME
+          default: 'nordix-cicd-{deploy-scenario}-{spinnaker-branch}'
+      - string:
+          name: HEAT_ENVIRONMENT_FILENAME
+          default: "heat-environment-full.yaml"
+          description: 'Heat environment file to use for creating the stack'
+      - string:
+          name: ENGINE_VERSION
+          default: '{engine-version}'
+          description: 'Development purposes only! Nordix Cloud Infra Engine version to use for deploying Spinnaker. Could be sha, branch'
+      - string:
+          name: ENGINE_REFSPEC
+          default: '{engine-refspec}'
+          description: 'Development purposes only! Nordix Cloud Infra Engine version to use for deploying Spinnaker. Must be refspec.'
+      - string:
+          name: DEPLOY_SCENARIO_VERSION
+          default: '{deploy-scenario-version}'
+          description: 'Development purposes only! Nordix Cloud Infra Scenario version to use for deploying Spinnaker. Depends on DEPLOY_SCENARIO_REFSPEC and could be sha, branch.'
+      - string:
+          name: DEPLOY_SCENARIO_REFSPEC
+          default: '{deploy-scenario-refspec}'
+          description: 'Development purposes only! Nordix Cloud Infra Scenario version to use for deploying Spinnaker. Depends on DEPLOY_SCENARIO_VERSION and must be refspec.'
+      - string:
+          name: POD_NAME
+          default: '{pod-name}'
+          description: 'Development purposes only! Set to none for disabling test results DB reporting.'
+      - string:
+          name: DELETE_STACK
+          default: '{delete-stack}'
+          description: 'Development purposes only! Whether delete the stack or not. It must either be yes or no. Setting this to no will increase the cost!'
+
+    wrappers:
+      - mask-passwords
+      - build-timeout:
+          timeout: '{build-timeout}'
+      - fix-workspace-permissions
+      - credentials-binding:
+          - username-password-separated:
+              credential-id: 'nordix-cicd-arm-credentials'
+              username: NORDIX_ARM_USERNAME
+              password: NORDIX_ARM_TOKEN
+          - username-password-separated:
+              credential-id: 'nordix-cicd-harbor-credentials'
+              username: NORDIX_HARBOR_USERNAME
+              password: NORDIX_HARBOR_PASSWORD
+
+    scm:
+      - git-scm:
+          ssh-credentials-id: nordixinfra-nordix-gerrit-ssh
+          branch: '{nordix-branch}'
+          refspec: ''
+          wipe_workspace: true
+          clean_before: false
+
+    builders:
+      - description-setter:
+          description: $DEPLOY_SCENARIO | Spinnaker $SPINNAKER_VERSION | $OPENSTACK_CLOUD_PROVIDER
+      - '{phase}-macro'
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/jjb/cloud-infra/scripts/promote-spinnaker.sh b/jjb/cloud-infra/scripts/promote-spinnaker.sh
new file mode 100644
index 0000000..a204a14
--- /dev/null
+++ b/jjb/cloud-infra/scripts/promote-spinnaker.sh
@@ -0,0 +1,23 @@
+#!/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=========================================================
+
+echo "Hello world!"
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/jjb/cloud-infra/scripts/spinnaker-deploy.sh b/jjb/cloud-infra/scripts/spinnaker-deploy.sh
new file mode 100644
index 0000000..bef1b12
--- /dev/null
+++ b/jjb/cloud-infra/scripts/spinnaker-deploy.sh
@@ -0,0 +1,76 @@
+#!/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=========================================================
+
+set -o errexit
+set -o nounset
+
+cd $WORKSPACE
+/bin/rm -f ../inventory.ini
+echo "Info: Preparing for Spinnaker deployment"
+
+# checkout given engine version
+if [[ "$ENGINE_VERSION" != "master" ]]; then
+  echo "Warning: Checking out $ENGINE_VERSION"
+  git checkout -q $ENGINE_VERSION
+fi
+
+# checkout given engine refspec
+if [[ "$ENGINE_REFSPEC" != "master" ]]; then
+  echo "Warning: Checking out engine $ENGINE_REFSPEC"
+  echo "-------------------------------------------------------------------------"
+  git fetch https://gerrit.nordix.org/infra/engine $ENGINE_REFSPEC && git checkout -q FETCH_HEAD
+  echo "-------------------------------------------------------------------------"
+fi
+
+# update scenario version and refspec in engine/envine/var/sdf.yml
+if [[ "$DEPLOY_SCENARIO_VERSION" != "master" && "$DEPLOY_SCENARIO_REFSPEC" != "master" ]]; then
+  echo "Warning: Adding $DEPLOY_SCENARIO_VERSION as scenario version and $DEPLOY_SCENARIO_REFSPEC as scenario refspec"
+cat << EOF > $WORKSPACE/engine/var/sdf.yml
+scenario:
+  $DEPLOY_SCENARIO:
+    scm: git
+    src: https://gerrit.nordix.org/infra/swconfig.git
+    version: $DEPLOY_SCENARIO_VERSION
+    refspec: $DEPLOY_SCENARIO_REFSPEC
+    provisioners:
+      - $PROVISIONER_TYPE
+    installers:
+      $INSTALLER_TYPE:
+        role: scenarios/$DEPLOY_SCENARIO/$INSTALLER_TYPE/role/$DEPLOY_SCENARIO
+        distros:
+          - $DISTRO
+EOF
+
+  echo "Info: Temporary SDF content"
+  echo "-------------------------------------------------------------------------"
+  cat $WORKSPACE/engine/var/sdf.yml
+  echo "-------------------------------------------------------------------------"
+fi
+
+echo "Info: Starting K8S cluster creation and Spinnaker deployment"
+echo "-------------------------------------------------------------------------"
+cd $WORKSPACE
+./engine/deploy.sh -c -r $PROVISIONER_TYPE -u /tmp/openrc \
+  -s $DEPLOY_SCENARIO -e $HEAT_ENVIRONMENT_FILE
+
+cd $WORKSPACE
+/bin/cp $WORKSPACE/.cache/config/inventory.ini ../inventory.ini
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/jjb/cloud-infra/scripts/spinnaker-test.sh b/jjb/cloud-infra/scripts/spinnaker-test.sh
new file mode 100644
index 0000000..a204a14
--- /dev/null
+++ b/jjb/cloud-infra/scripts/spinnaker-test.sh
@@ -0,0 +1,23 @@
+#!/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=========================================================
+
+echo "Hello world!"
+
+# vim: set ts=2 sw=2 expandtab:
diff --git a/jjb/cloud-infra/spinnaker-macros.yaml b/jjb/cloud-infra/spinnaker-macros.yaml
new file mode 100644
index 0000000..c67fcdc
--- /dev/null
+++ b/jjb/cloud-infra/spinnaker-macros.yaml
@@ -0,0 +1,44 @@
+---
+#
+# ============LICENSE_START=======================================================
+#  Copyright (C) 2019 Nordix Foundation.
+# ================================================================================
+# 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=========================================================
+
+- builder:
+    name: 'spinnaker-deploy-macro'
+    builders:
+      - shell:
+          !include-raw: ./wait-for-pkg-manager.sh
+      - shell:
+          !include-raw: ./scripts/spinnaker-deploy.sh
+
+- builder:
+    name: 'spinnaker-test-macro'
+    builders:
+      - shell:
+          !include-raw: ./wait-for-pkg-manager.sh
+      - shell:
+          !include-raw: ./scripts/spinnaker-test.sh
+- builder:
+    name: 'promote-spinnaker-macro'
+    builders:
+      - shell:
+          !include-raw: ./wait-for-pkg-manager.sh
+      - shell:
+          !include-raw: ./scripts/promote-spinnaker.sh
+
+# vim: set ts=2 sw=2 expandtab: