---
- project:
    name: 'opnfv-xci-verify'

    project: releng-xci
    # -------------------------------
    # branches
    # -------------------------------
    stream:
      - master:
          branch: '{stream}'
    # -------------------------------
    # distros
    # -------------------------------
    distro:
      - ubuntu:
          disabled: false
          successful: false
          failed: false
          unstable: false
          notbuilt: false
      - centos:
          disabled: true
          successful: true
          failed: true
          unstable: true
          notbuilt: true
      - opensuse:
          disabled: false
          successful: false
          failed: false
          unstable: false
          notbuilt: false
    # -------------------------------
    # type
    # -------------------------------
    type:
      - virtual
    # -------------------------------
    # patch verification phases
    # -------------------------------
    phase:
      - 'deploy'
      - 'healthcheck'
    # -------------------------------
    # jobs
    # -------------------------------
    jobs:
      - 'xci-verify-{distro}-{type}-{stream}'
      - 'xci-verify-{distro}-{phase}-{type}-{stream}'
# -------------------------------
# job templates
# -------------------------------
- job-template:
    name: 'xci-verify-{distro}-{type}-{stream}'

    project-type: multijob

    disabled: '{obj:disabled}'

    concurrent: true

    properties:
      - logrotate-default
      - build-blocker:
          use-build-blocker: true
          blocking-jobs:
            - 'xci-verify-{distro}-.*'
            - 'xci-merge-{distro}-.*'
            - 'xci-os-.*'
            - 'xci-k8-.*'
            - 'openstack-bifrost-verify-{distro}-.*'
            - 'xci-osa-verify-{distro}-.*'
            - 'xci-osa-periodic-{distro}-.*'
          blocking-level: 'NODE'
      - throttle:
          max-per-node: 2
          max-total: 10
          categories:
            - xci-verify-virtual
          option: category

    wrappers:
      - ssh-agent-wrapper
      - build-timeout:
          timeout: 240
      - fix-workspace-permissions

    scm:
      - git-scm-gerrit

    triggers:
      - gerrit:
          server-name: 'gerrit.opnfv.org'
          trigger-on:
            - patchset-created-event:
                exclude-drafts: 'false'
                exclude-trivial-rebase: 'false'
                exclude-no-code-change: 'true'
            - draft-published-event
            - comment-added-contains-event:
                comment-contains-value: 'recheck'
            - comment-added-contains-event:
                comment-contains-value: 'reverify'
          projects:
            - project-compare-type: 'ANT'
              project-pattern: 'releng-xci'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              disable-strict-forbidden-file-verification: 'false'
              forbidden-file-paths:
                - compare-type: ANT
                  pattern: 'xci/scripts/vm/**'
                - compare-type: ANT
                  pattern: 'docs/**'
                - compare-type: ANT
                  pattern: 'upstream/**'
            - project-compare-type: 'REG_EXP'
              project-pattern: 'sfc|sdnvpn|releng-xci-scenarios'
              branches:
                - branch-compare-type: 'ANT'
                  branch-pattern: '**/{branch}'
              disable-strict-forbidden-file-verification: 'true'
              file-paths:
                - compare-type: ANT
                  pattern: 'scenarios/**'
          readable-message: true
          custom-url: '* $JOB_NAME $BUILD_URL'
          skip-vote:
            successful: '{obj:successful}'
            failed: '{obj:failed}'
            unstable: '{obj:unstable}'
            notbuilt: '{obj:notbuilt}'

    parameters:
      - project-parameter:
          project: $GERRIT_PROJECT
          branch: '{branch}'
      - label:
          name: SLAVE_LABEL
          default: 'xci-virtual'
          all-nodes: false
          node-eligibility: 'ignore-offline'
      - string:
          name: DISTRO
          default: '{distro}'
      - string:
          name: CLEAN_DIB_IMAGES
          default: 'true'
      - string:
          name: CI_LOOP
          default: 'verify'
      - string:
          name: FUNCTEST_VERSION
          default: 'hunter'
      - string:
          name: FUNCTEST_MODE
          default: 'tier'
      - string:
          name: FUNCTEST_SUITE_NAME
          default: 'healthcheck'
      - string:
          name: GIT_BASE
          default: https://gerrit.opnfv.org/gerrit/$PROJECT
          description: 'Git URL to use on this Jenkins Slave'

    builders:
      - 'xci-verify-clean-vm-macro'
      - 'xci-verify-set-scenario-macro'
      - inject:
          properties-file: "/tmp/$GERRIT_CHANGE_NUMBER/$DISTRO/scenario.properties"
      - description-setter:
          description: "Scenario: $DEPLOY_SCENARIO | Node: $NODE_NAME"
      - multijob:
          name: deploy
          condition: SUCCESSFUL
          projects:
            - name: 'xci-verify-{distro}-deploy-{type}-{stream}'
              current-parameters: true
              predefined-parameters: |
                DISTRO={distro}
                CLEAN_DIB_IMAGES=$CLEAN_DIB_IMAGES
                GERRIT_PROJECT=$GERRIT_PROJECT
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
                GERRIT_CHANGE_COMMIT_MESSAGE=$GERRIT_CHANGE_COMMIT_MESSAGE
                CI_LOOP=$CI_LOOP
                FUNCTEST_VERSION=$FUNCTEST_VERSION
                FUNCTEST_MODE=$FUNCTEST_MODE
                FUNCTEST_SUITE_NAME=$FUNCTEST_SUITE_NAME
              node-parameters: true
              kill-phase-on: FAILURE
              abort-all-job: true
      - multijob:
          name: healthcheck
          condition: SUCCESSFUL
          projects:
            - name: 'xci-verify-{distro}-healthcheck-{type}-{stream}'
              current-parameters: true
              predefined-parameters: |
                DISTRO={distro}
                CLEAN_DIB_IMAGES=$CLEAN_DIB_IMAGES
                GERRIT_PROJECT=$GERRIT_PROJECT
                GERRIT_BRANCH=$GERRIT_BRANCH
                GERRIT_REFSPEC=$GERRIT_REFSPEC
                GERRIT_CHANGE_NUMBER=$GERRIT_CHANGE_NUMBER
                GERRIT_CHANGE_COMMIT_MESSAGE=$GERRIT_CHANGE_COMMIT_MESSAGE
                CI_LOOP=$CI_LOOP
                FUNCTEST_VERSION=$FUNCTEST_VERSION
                FUNCTEST_MODE=$FUNCTEST_MODE
                FUNCTEST_SUITE_NAME=$FUNCTEST_SUITE_NAME
              node-parameters: true
              kill-phase-on: NEVER
              abort-all-job: true

    publishers:
      - postbuildscript:
          builders:
            - role: BOTH
              build-on:
                - ABORTED
                - NOT_BUILT
                - SUCCESS
                - UNSTABLE
              build-steps:
                - shell: !include-raw: ./xci-cleanup.sh
          mark-unstable-if-failed: true


- job-template:
    name: 'xci-verify-{distro}-{phase}-{type}-{stream}'

    disabled: false

    concurrent: true

    properties:
      - logrotate-default
      - build-blocker:
          use-build-blocker: true
          blocking-jobs:
            - '.*-bifrost-verify-.*'
            - '.*-bifrost-periodic-.*'
            - 'osa-verify-.*'
            - 'osa-periodic-.*'
          blocking-level: 'NODE'

    parameters:
      - string:
          name: PROJECT
          default: $GERRIT_PROJECT
      - string:
          name: DISTRO
          default: 'ubuntu'
      - string:
          name: CI_LOOP
          default: 'verify'
      - string:
          name: FUNCTEST_VERSION
          default: 'hunter'
      - string:
          name: FUNCTEST_MODE
          default: 'tier'
      - string:
          name: FUNCTEST_SUITE_NAME
          default: 'healthcheck'
      - string:
          name: XCI_FLAVOR
          default: 'mini'
      - string:
          name: CLEAN_DIB_IMAGES
          default: 'true'
      - string:
          name: OPNFV_RELENG_DEV_PATH
          default: $WORKSPACE/
      - string:
          name: GIT_BASE
          default: https://gerrit.opnfv.org/gerrit/$PROJECT
          description: 'Git URL to use on this Jenkins Slave'

    wrappers:
      - inject:
          properties-file: "/tmp/$GERRIT_CHANGE_NUMBER/$DISTRO/scenario.properties"
      - ssh-agent-wrapper
      - build-timeout:
          timeout: 240
      - fix-workspace-permissions

    scm:
      - git-scm-gerrit

    builders:
      - description-setter:
          description: "Scenario: $DEPLOY_SCENARIO | Node: $NODE_NAME"
      - 'xci-verify-{phase}-macro'

# -------------------------------
# builder macros
# -------------------------------
- builder:
    name: 'xci-verify-clean-vm-macro'
    builders:
      - shell:
          !include-raw: ./xci-cleanup.sh

- builder:
    name: 'xci-verify-set-scenario-macro'
    builders:
      - shell:
          !include-raw: ./xci-set-scenario.sh

- builder:
    name: 'xci-verify-deploy-macro'
    builders:
      - shell:
          !include-raw: ./xci-start-new-vm.sh

      - shell:
          !include-raw: ./xci-start-deployment.sh

- builder:
    name: 'xci-verify-healthcheck-macro'
    builders:
      - shell:
          !include-raw: ./xci-run-functest.sh