###################################
# job configuration for functest
###################################
- project:
    name: functest

    project: '{name}'

#--------------------------------
# BRANCH ANCHORS
#--------------------------------
    master: &master
        stream: master
        branch: '{stream}'
        gs-pathname: ''
        docker-tag: 'latest'
    colorado: &colorado
        stream: colorado
        branch: 'stable/{stream}'
        gs-pathname: '/{stream}'
        docker-tag: 'stable'
#--------------------------------
# POD, INSTALLER, AND BRANCH MAPPING
#--------------------------------
#    Installers using labels
#            CI PODs
# This section should only contain the installers
# that have been switched using labels for slaves
#--------------------------------
    pod:
# fuel CI PODs
        - baremetal:
            slave-label: fuel-baremetal
            installer: fuel
            <<: *master
        - virtual:
            slave-label: fuel-virtual
            installer: fuel
            <<: *master
        - baremetal:
            slave-label: fuel-baremetal
            installer: fuel
            <<: *colorado
        - virtual:
            slave-label: fuel-virtual
            installer: fuel
            <<: *colorado
# joid CI PODs
        - baremetal:
            slave-label: joid-baremetal
            installer: joid
            <<: *master
        - virtual:
            slave-label: joid-virtual
            installer: joid
            <<: *master
        - baremetal:
            slave-label: joid-baremetal
            installer: joid
            <<: *colorado
        - virtual:
            slave-label: joid-virtual
            installer: joid
            <<: *colorado
# compass CI PODs
        - baremetal:
            slave-label: compass-baremetal
            installer: compass
            <<: *master
        - virtual:
            slave-label: compass-virtual
            installer: compass
            <<: *master
        - baremetal:
            slave-label: compass-baremetal
            installer: compass
            <<: *colorado
        - virtual:
            slave-label: compass-virtual
            installer: compass
            <<: *colorado
# apex CI PODs
        - apex-verify-master:
            slave-label: '{pod}'
            installer: apex
            <<: *master
        - apex-daily-master:
            slave-label: '{pod}'
            installer: apex
            <<: *master
        - apex-verify-colorado:
            slave-label: '{pod}'
            installer: apex
            <<: *colorado
        - apex-daily-colorado:
            slave-label: '{pod}'
            installer: apex
            <<: *colorado
# armband CI PODs
        - armband-baremetal:
            slave-label: armband-baremetal
            installer: fuel
            <<: *master
        - armband-virtual:
            slave-label: armband-virtual
            installer: fuel
            <<: *master
        - armband-baremetal:
            slave-label: armband-baremetal
            installer: fuel
            <<: *colorado
        - armband-virtual:
            slave-label: armband-virtual
            installer: fuel
            <<: *colorado
#--------------------------------
#        None-CI PODs
#--------------------------------
        - orange-pod1:
            slave-label: '{pod}'
            installer: joid
            <<: *master
        - orange-pod5:
            slave-label: '{pod}'
            installer: fuel
            <<: *master
        - orange-pod2:
            slave-label: '{pod}'
            installer: joid
            <<: *master
        - huawei-pod5:
            slave-label: '{pod}'
            installer: compass
            <<: *master
        - nokia-pod1:
            slave-label: '{pod}'
            installer: apex
            <<: *master
        - arm-pod2:
            slave-label: '{pod}'
            installer: fuel
            <<: *master
        - arm-pod3:
            slave-label: '{pod}'
            installer: fuel
            <<: *master
        - zte-pod1:
            slave-label: '{pod}'
            installer: fuel
            <<: *master
        - zte-pod1:
            slave-label: '{pod}'
            installer: fuel
            <<: *colorado
        - zte-pod2:
            slave-label: '{pod}'
            installer: fuel
            <<: *master
        - zte-pod3:
            slave-label: '{pod}'
            installer: fuel
            <<: *master
        - zte-pod3:
            slave-label: '{pod}'
            installer: fuel
            <<: *colorado
        - arm-pod2:
            slave-label: '{pod}'
            installer: fuel
            <<: *colorado
        - arm-pod3:
            slave-label: '{pod}'
            installer: fuel
            <<: *colorado
# PODs for verify jobs triggered by each patch upload
        - ool-virtual1:
            slave-label: '{pod}'
            installer: apex
            <<: *master
#--------------------------------

    testsuite:
        - 'suite':
            job-timeout: 60
        - 'daily':
            job-timeout: 180
        - 'weekly':
            job-timeout: 400

    jobs:
        - 'functest-{installer}-{pod}-{testsuite}-{stream}'

################################
# job template
################################
- job-template:
    name: 'functest-{installer}-{pod}-{testsuite}-{stream}'

    concurrent: true

    properties:
        - throttle:
            enabled: true
            max-per-node: 1
            option: 'project'

    wrappers:
        - build-name:
            name: '$BUILD_NUMBER Suite: $FUNCTEST_SUITE_NAME Scenario: $DEPLOY_SCENARIO'
        - timeout:
            timeout: '{job-timeout}'
            abort: true

    parameters:
        - project-parameter:
            project: '{project}'
        - '{installer}-defaults'
        - '{slave-label}-defaults'
        - 'functest-{testsuite}-parameter'
        - string:
            name: DEPLOY_SCENARIO
            default: 'os-odl_l2-nofeature-ha'
        - string:
            name: DOCKER_TAG
            default: '{docker-tag}'
            description: 'Tag to pull docker image'
        - functest-parameter:
            gs-pathname: '{gs-pathname}'

    scm:
        - git-scm:
            credentials-id: '{ssh-credentials}'
            refspec: ''
            branch: '{branch}'

    builders:
        - description-setter:
            description: "POD: $NODE_NAME"
        - 'functest-{testsuite}-builder'

########################
# parameter macros
########################
- parameter:
    name: functest-daily-parameter
    parameters:
        - string:
            name: FUNCTEST_SUITE_NAME
            default: 'daily'
            description: "Daily suite name to run"
- parameter:
    name: functest-weekly-parameter
    parameters:
        - string:
            name: FUNCTEST_SUITE_NAME
            default: 'weekly'
            description: "Weekly suite name to run"
- parameter:
    name: functest-suite-parameter
    parameters:
        - choice:
            name: FUNCTEST_SUITE_NAME
            choices:
                - 'healthcheck'
                - 'vping_userdata'
                - 'vping_ssh'
                - 'tempest_smoke_serial'
                - 'rally_sanity'
                - 'odl'
                - 'onos'
                - 'promise'
                - 'doctor'
                - 'bgpvpn'
                - 'security_scan'
                - 'tempest_full_parallel'
                - 'rally_full'
                - 'vims'
                - 'multisite'
                - 'parser'
        - string:
            name: TESTCASE_OPTIONS
            default: ''
            description: 'Addtional parameters specific to test case(s)'
- parameter:
    name: functest-parameter
    parameters:
        - string:
            name: GS_PATHNAME
            default: '{gs-pathname}'
            description: "Version directory where the opnfv documents will be stored in gs repository"
        - string:
            name: FUNCTEST_REPO_DIR
            default: "/home/opnfv/repos/functest"
            description: "Directory where the Functest repository is cloned"
        - string:
            name: PUSH_RESULTS_TO_DB
            default: "true"
            description: "Push the results of all the tests to the resultDB"
        - string:
            name: CI_DEBUG
            default: 'false'
            description: "Show debug output information"
########################
# trigger macros
########################
- trigger:
    name: 'functest-master'
    triggers:
        - pollscm:
            cron: "H 9 * * *"
########################
# builder macros
########################
- builder:
    name: functest-daily-builder
    builders:
        - 'functest-cleanup'
        - 'set-functest-env'
        - 'functest-daily'
        - 'functest-store-results'
        - 'functest-exit'

- builder:
    name: functest-weekly-builder
    builders:
        - 'functest-cleanup'
        - 'set-functest-env'
        - 'functest-weekly'
        - 'functest-store-results'
        - 'functest-exit'

- builder:
    name: functest-suite-builder
    builders:
        - 'functest-cleanup'
        - 'set-functest-env'
        - 'functest-suite'

- builder:
    name: functest-daily
    builders:
        - shell:
            !include-raw: ./functest-loop.sh

- builder:
    name: functest-weekly
    builders:
        - shell:
            !include-raw: ./functest-loop.sh

- builder:
    name: functest-suite
    builders:
        - shell:
            !include-raw: ./functest-suite.sh

- builder:
    name: set-functest-env
    builders:
        - shell:
            !include-raw: ./set-functest-env.sh

- builder:
    name: functest-store-results
    builders:
        - shell:
            !include-raw: ../../utils/push-test-logs.sh

- builder:
    name: functest-cleanup
    builders:
        - shell:
            !include-raw: ./functest-cleanup.sh

- builder:
    name: functest-exit
    builders:
        - shell:
            !include-raw: ./functest-exit.sh