Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 17.63 KB | None | 0 0
  1. timeout(time: 60, unit: 'MINUTES') {{
  2.                     stage('Provision') {{
  3.                         dir('infrared') {{
  4.                             if ("${{DEPLOY_STEP}}" == 'Full') {{
  5.                                 OS_PARAMS = '--medium-id 24 '
  6.                                 if ("${{RHEL_VERSION}}" == 'rhel7.6') {{
  7.                                     OS_PARAMS += '--os-id 51'
  8.                                 }}
  9.                                 if ("${{RHEL_VERSION}}" == 'rhel7.5') {{
  10.                                     OS_PARAMS += '--os-id 44'
  11.                                 }}
  12.                                 if ("${{RHEL_VERSION}}" == 'rhel7.4') {{
  13.                                     OS_PARAMS += '--os-id 35'
  14.                                 }}
  15.                                 sh2 """
  16.                                    . $ir_venv/bin/activate
  17.                                    infrared foreman -v \
  18.                                        --url=https://theforeman.eng.lab.tlv.redhat.com \
  19.                                        --user=rhos-qe \
  20.                                        --password=qum5net \
  21.                                        --host-address=$HOST \
  22.                                        --host-key={private-key} \
  23.                                        --role baremetal,undercloud,tester \
  24.                                        ${{OS_PARAMS}}
  25.                                """, basename: 'ir-provision'
  26.                                 }}
  27.  
  28.                             if ("${{DEPLOY_STEP}}" == 'Full' || "${{DEPLOY_STEP}}" == 'Virsh_Cleanup') {{
  29.                                 HYBRID_IMAGE = ''
  30.                                 if ("${{RHEL_VERSION}}" == 'rhel7.6') {{
  31.                                     HYBRID_IMAGE = '{rhel_76}'
  32.                                 }}
  33.                                 if ("${{RHEL_VERSION}}" == 'rhel7.5') {{
  34.                                     HYBRID_IMAGE = '{rhel_75}'
  35.                                 }}
  36.                                 if ("${{RHEL_VERSION}}" == 'rhel7.4') {{
  37.                                     HYBRID_IMAGE = '{rhel_74}'
  38.                                }}
  39.                                sh2 """
  40.                                    . $ir_venv/bin/activate
  41.                                    if [[ '{DEPLOY_STEP}' == Virsh_Cleanup ]]; then
  42.                                        infrared virsh -v \
  43.                                            --topology-nodes controller:3 \
  44.                                            --host-address $HOST \
  45.                                            --host-key {private-key} \
  46.                                            --cleanup yes
  47.  
  48.                                    elif [[ '{hybrid}' == True || '{DEPLOY_STEP}' == Virsh_Cleanup ]]; then
  49.                                        infrared workspace cleanup ci
  50.  
  51.                                        infrared virsh -v \
  52.                                            --topology-nodes {hybrid_topology} \
  53.                                            -e override.controller.memory={controller_memory} \
  54.                                            -e override.undercloud.memory={undercloud_memory} \
  55.                                            -e override.controller.cpu={controller_cpu} \
  56.                                            -e override.undercloud.cpu={undercloud_cpu} \
  57.                                            --host-address $HOST \
  58.                                            --host-key {private-key} \
  59.                                            --topology-network 4_nets_3_bridges_hybrid \
  60.                                            -e override.networks.net1.nic={hybrid_provision_interface} \
  61.                                            -e override.networks.net1.ip_address={hybrid_provision_ip_address} \
  62.                                            --host-mtu-size {hybrid_mtu} \
  63.                                            --image-url ${{HYBRID_IMAGE}}
  64.                                    fi
  65.                              """, basename: 'ir-provision'
  66.                             }}
  67.                         }}
  68.                     }}
  69.                 }}
  70.  
  71.                 stage('Generate inventory file') {{
  72.                   dir('ansible-nfv') {{
  73.                       if ("${{DEPLOY_STEP}}" == 'Introspection' || "${{DEPLOY_STEP}}" == 'Overcloud' || "${{DEPLOY_STEP}}" == 'Tempest_or_Performance') {{
  74.                           SETUP_TYPE='baremetal'
  75.                           USER='stack'
  76.                           UNDERCLOUD_GROUPS='undercloud,tester,shade,baremetal'
  77.                           GROUPS_CONFIG="-e undercloud_groups=${{ UNDERCLOUD_GROUPS }}"
  78.                           if ('{hw-topology}' == 'hybrid') {{
  79.                               SETUP_TYPE='virt'
  80.                               USER='root'
  81.                               UNDERCLOUD_GROUPS='undercloud,tester'
  82.                               HYPERVISOR_GROUPS='shade,hypervisor'
  83.                               GROUPS_CONFIG="-e undercloud_groups=${{ UNDERCLOUD_GROUPS }} -e hypervisor_groups=${{ HYPERVISOR_GROUPS }}"
  84.                           }}
  85.                           sh2 """
  86.                              . $ir_venv/bin/activate
  87.                              ansible-playbook -v \
  88.                                  playbooks/tripleo/post_install/tripleo_inventory.yml \
  89.                                  -e host=$HOST \
  90.                                  -e user=${{USER}} \
  91.                                  -e ssh_key={private-key} \
  92.                                  -e setup_type=${{SETUP_TYPE}} \
  93.                                  ${{ GROUPS_CONFIG }}
  94.  
  95.                              ln -sf ../../../ansible-nfv/inventory ../infrared/.workspaces/ci/hosts
  96.                          """, basename: 'ansible-nfv-generate-inventory'
  97.                         }}
  98.                     }}
  99.                 }}
  100.  
  101.                 timeout(time: 30, unit: 'MINUTES') {{
  102.                   stage('Delete Overcloud (if required)') {{
  103.                       dir('ansible-nfv') {{
  104.                           if ("${{DEPLOY_STEP}}" == 'Introspection' || "${{DEPLOY_STEP}}" == 'Overcloud') {{
  105.                               sh2 """
  106.                                  . $ir_venv/bin/activate
  107.                                  inventory=\$(cd ../infrared && infrared workspace inventory)
  108.  
  109.                                  ansible-playbook -v -i \$inventory \
  110.                                      playbooks/tripleo/post_install/openstack_tasks.yml \
  111.                                      -t setup_os_env,overcloud_delete \
  112.                                      -e setup_os_env=true \
  113.                                      -e overcloud_delete=true
  114.                              """, basename: 'ansible-nfv-delete-overcloud'
  115.                             }}
  116.                         }}
  117.                     }}
  118.                 }}
  119.  
  120.                 timeout(time: 60, unit: 'MINUTES') {{
  121.                   stage('Undercloud') {{
  122.                       dir('infrared') {{
  123.                           if ("${{DEPLOY_STEP}}" == 'Full' || "${{DEPLOY_STEP}}" == 'Virsh_Cleanup') {{
  124.                               sh2 """
  125.                                  . $ir_venv/bin/activate
  126.                                  infrared tripleo-undercloud -v \
  127.                                      -o install.yml \
  128.                                      --config-file {template-path}/undercloud.conf \
  129.                                      --version {product-version} \
  130.                                      --build $BUILD \
  131.                                      --images-task rpm \
  132.                                      --mirror {ir_tripleo_mirror}
  133.                              """, basename: 'ir-tripleo-undercloud'
  134.                             }}
  135.                         }}
  136.                     }}
  137.                 }}
  138.  
  139.                 timeout(time: 30, unit: 'MINUTES') {{
  140.                   stage('Introspection') {{
  141.                       dir('infrared') {{
  142.                           if ("${{DEPLOY_STEP}}" == 'Full' || "${{DEPLOY_STEP}}" == 'Virsh_Cleanup' || "${{DEPLOY_STEP}}" == 'Introspection') {{
  143.                               sh2 """
  144.                                  if [[ '{hybrid}' == True ]]; then
  145.                                      INSTACKENV='--hybrid {template-path}/hybrid.json -e provison_virsh_network_name=br-ctlplane'
  146.                                  else
  147.                                      INSTACKENV='--instackenv-file {template-path}/instackenv.json'
  148.                                  fi
  149.  
  150.                                  . $ir_venv/bin/activate
  151.                                  infrared tripleo-overcloud -v \
  152.                                      -o overcloud-install.yml \
  153.                                      --deployment-files {template-path} \
  154.                                      \$INSTACKENV \
  155.                                      --version {product-version} \
  156.                                      --introspect yes \
  157.                                      --tagging no \
  158.                                      --deploy no
  159.                              """, basename: 'ir-tripleo-introspection'
  160.                             }}
  161.                         }}
  162.                     }}
  163.                 }}
  164.  
  165.                 stage('Tagging') {{
  166.                   dir('infrared') {{
  167.                       if ("${{DEPLOY_STEP}}" == 'Full' || "${{DEPLOY_STEP}}" == 'Virsh_Cleanup' || "${{DEPLOY_STEP}}" == 'Introspection') {{
  168.                           sh2 """
  169.                              if [[ '{hybrid}' == True ]]; then
  170.                                  INSTACKENV='--hybrid {template-path}/hybrid.json -e provison_virsh_network_name=br-ctlplane'
  171.                              else
  172.                                  INSTACKENV='--instackenv-file {template-path}/instackenv.json'
  173.                              fi
  174.  
  175.                              . $ir_venv/bin/activate
  176.                              infrared tripleo-overcloud -v \
  177.                                  -o overcloud-install.yml \
  178.                                  --deployment-files {template-path} \
  179.                                  \$INSTACKENV \
  180.                                  --tagging yes \
  181.                                  --deploy no \
  182.                                  --introspect no
  183.                          """, basename: 'ir-tripleo-tagging'
  184.                         }}
  185.                     }}
  186.                 }}
  187.  
  188.                 timeout(time: 120, unit: 'MINUTES') {{
  189.                   stage('Overcloud') {{
  190.                       dir('infrared') {{
  191.                           if ("${{DEPLOY_STEP}}" == 'Full' || "${{DEPLOY_STEP}}" == 'Virsh_Cleanup' || "${{DEPLOY_STEP}}" == 'Introspection' || "${{DEPLOY_STEP}}" == 'Overcloud') {{
  192.                               sh2 """
  193.                                  if [[ '{hybrid}' == True ]]; then
  194.                                      INSTACKENV='--hybrid {template-path}/hybrid.json -e provison_virsh_network_name=br-ctlplane'
  195.                                  else
  196.                                      INSTACKENV='--instackenv-file {template-path}/instackenv.json'
  197.                                  fi
  198.  
  199.                                  . $ir_venv/bin/activate
  200.                                  infrared tripleo-overcloud -v \
  201.                                      -o overcloud-install.yml \
  202.                                      --version {product-version} \
  203.                                      --containers {containers} \
  204.                                      --deployment-files {template-path} \
  205.                                      --overcloud-script {template-path}/overcloud_deploy.sh \
  206.                                      \$INSTACKENV \
  207.                                      --introspect no \
  208.                                      --tagging no \
  209.                                      --deploy yes
  210.                              """, basename: 'ir-tripleo-overcloud'
  211.                             }}
  212.                         }}
  213.                     }}
  214.                 }}
  215.  
  216.                 timeout(time: 120, unit: 'MINUTES') {{
  217.                   stage('Tempest_or_Performance') {{
  218.                     dir('ansible-nfv') {{
  219.                         if ("${{DEPLOY_STEP}}" == 'Full' || "${{DEPLOY_STEP}}" == 'Virsh_Cleanup' || "${{DEPLOY_STEP}}" == 'Introspection' || "${{DEPLOY_STEP}}" == 'Overcloud' || "${{DEPLOY_STEP}}" == 'Tempest_or_Performance') {{
  220.                             sh2 """
  221.                                . $ir_venv/bin/activate
  222.                                if [[ '{run-test}' == 'tempest' ]]; then
  223.                                    inventory=\$(cd ../infrared && infrared workspace inventory)
  224.  
  225.                                    ansible-playbook -v -i \$inventory \
  226.                                        playbooks/tripleo/tester/tempest.yml \
  227.                                        -e @{ci-network-config} \
  228.                                        -e tempest_config={ci-network-config}
  229.  
  230.                                    #Copying the "core_puddle_file" file to the infrared's workspace directory
  231.                                    ansible undercloud-0 -v -i \$inventory \
  232.                                        -m fetch -a "src=/home/stack/core_puddle_version \
  233.                                        dest=$WORKSPACE/infrared/.workspaces/ci/core_puddle_version flat=yes" --become
  234.  
  235.                                    for file in tempest.xml tempest.log; do \
  236.                                        ansible -v -i \$inventory tester --become \
  237.                                            -m fetch -a "src=/home/stack/tempest/\$file \
  238.                                            dest=$WORKSPACE/infrared/.workspaces/ci/tempest_results/\${{file//tempest/tempest_results}} \
  239.                                            flat=yes fail_on_missing=yes"; done
  240.                                elif [[ '{run-test}' == 'performance' ]]; then
  241.                                    inventory=\$(cd ../infrared && infrared workspace inventory)
  242.                                    cat << EOF >> \$inventory
  243.  
  244. moongen ansible_ssh_host=$MOONGEN ansible_ssh_user=root ansible_ssh_private_key_file={private-key}
  245.  
  246. [moongen]
  247. moongen
  248. EOF
  249.  
  250.                                    ansible-playbook -v -i \$inventory \
  251.                                        playbooks/tripleo/tester/{performance-play}.yml \
  252.                                        -e @{ci-network-config}
  253.                                fi
  254.                            """, basename: 'nfv-tempest-or-performance'
  255.                             }}
  256.                         }}
  257.                     }}
  258.                 }}
  259.                 status = "SUCCESS"
  260.  
  261.                 }} finally {{
  262.                       currentBuild.result = status
  263.  
  264.                       // Creating a variable defenition of puddle version for the jump tool.
  265.                       core_puddle_file = '$WORKSPACE/infrared/.workspaces/ci/core_puddle_version'
  266.                       def puddle_version=sh(returnStdout: true, script: """ [[ -f $core_puddle_file ]] && cat $core_puddle_file || echo '' """)
  267.  
  268.                       jumpStage('results', '{polarion_test_run_id}', ir_venv, puddle_version)
  269.  
  270.                       dir('infrared') {{
  271.                           sh2 """
  272.                              . $ir_venv/bin/activate
  273.                              infrared workspace export -f workspace
  274.                              ANSIBLE_FORCE_COLOR=false \
  275.                              infrared collect-logs -v --gzip yes --dest-dir=$WORKSPACE/infrared &> collect.log
  276.  
  277.                              rm -rf $ir_venv
  278.                          """, basename: 'ir-collect'
  279.  
  280.                           archiveArtifacts allowEmptyArchive: true, artifacts: 'ansible.cfg, *.yml, pip*, collect.log, .workspaces/**, workspace.tgz, *.tar.gz'
  281.                           junit allowEmptyResults: true, testResults: '**/tests_results.xml, logs/test_*.xml, **/ci/**/tempest*.xml, **/nosetests.xml'
  282.  
  283.                           // Remove lock from host
  284.                           sh "ssh -i $HOME/.ssh/rhos-jenkins/id_rsa root@$HOST 'rm -f $lock_file'"
  285.                       }}
  286.  
  287.                       if (env.SKIPMAIL == 'true') {{
  288.                           echo "Skipping email report due to SKIPMAIL parameter."
  289.                       }} else if (currentBuild.result == 'ABORTED') {{
  290.                           echo "Skipping email report as this build is ABORTED."
  291.                       }} else if ('{email_recipients}' == '') {{
  292.                           echo "Skipping email report as recipients is empty."
  293.                       }} else {{
  294.                       emailext (
  295.                           from: '{email_replyto}',
  296.                           to: '{email_recipients}',
  297.                           replyTo: '{email_replyto}',
  298.                           subject: "NFV CI Job - $currentBuild.result - $env.JOB_NAME",
  299.                           body: """The $env.JOB_NAME job finished with $currentBuild.result status.
  300.  
  301.                                <p>The job could be found at: $env.BUILD_URL</p>
  302.                                <p>Full job log and tempest log are attached.</p>""",
  303.                           mimeType: 'text/html',
  304.                           attachmentsPattern: 'infrared/.workspaces/ci/tempest_results/tempest*',
  305.                           attachLog: true,
  306.                           compressLog: true
  307.                           )
  308.                       }}
  309.  
  310.                       if ('{run-next-job}' != '' && status == 'SUCCESS' && "${{STOP_NEXT_JOB_RUN}}" == 'false') {{
  311.                           build job: "{run-next-job}", propagate: false, wait: false
  312.                       }}
  313.                   }}
  314.               }}
  315.           }}
  316.       }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement