kitchen-macosxmojave-py3 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. @Library('salt@master-1.2') _
  2. // Define the maximum time, in hours, that a test run should run for
  3. def testrun_timeout = 6
  4. // Now define a global pipeline timeout. This is the test run timeout with one(1) additional
  5. // hour to allow for artifacts to be downloaded, if possible.
  6. def global_timeout = testrun_timeout + 1;
  7. def distro_name = 'macosx'
  8. def distro_version = 'mojave'
  9. def python_version = 'py3'
  10. def nox_env_name = 'runtests-zeromq'
  11. def salt_target_branch = 'master'
  12. def golden_images_branch = '2019.2'
  13. def nox_passthrough_opts = ''
  14. def concurrent_builds = 1
  15. def jenkins_slave_label = 'kitchen-slave-mac'
  16. properties([
  17. buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '30')),
  18. parameters([
  19. booleanParam(defaultValue: true, description: 'Run full test suite', name: 'runFull')
  20. ])
  21. ])
  22. // Be sure to cancel any previously running builds
  23. def buildNumber = env.BUILD_NUMBER as int
  24. if (buildNumber > concurrent_builds) {
  25. // This will cancel the previous build which also defined a matching milestone
  26. milestone(buildNumber - concurrent_builds)
  27. }
  28. // Define a milestone for this build so that, if another build starts, this one will be aborted
  29. milestone(buildNumber)
  30. wrappedNode(jenkins_slave_label, global_timeout, '#jenkins-prod-pr') {
  31. withEnv([
  32. 'SALT_KITCHEN_PLATFORMS=/var/jenkins/workspace/platforms.yml',
  33. 'SALT_KITCHEN_VERIFIER=/var/jenkins/workspace/verifier.yml',
  34. 'SALT_KITCHEN_DRIVER=/var/jenkins/workspace/driver.yml',
  35. "NOX_ENV_NAME=${nox_env_name}",
  36. 'NOX_ENABLE_FROM_FILENAMES=true',
  37. "NOX_PASSTHROUGH_OPTS=${nox_passthrough_opts}",
  38. "SALT_TARGET_BRANCH=${salt_target_branch}",
  39. "GOLDEN_IMAGES_CI_BRANCH=${golden_images_branch}",
  40. "PATH=/Users/parallels/.rbenv/shims:/Users/parallels/.rbenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/salt/bin:/usr/local/sbin",
  41. 'RBENV_VERSION=2.6.3',
  42. "TEST_SUITE=${python_version}",
  43. "TEST_PLATFORM=${distro_name}-${distro_version}",
  44. "FORCE_FULL=${params.runFull}",
  45. ]) {
  46. stage('VM Cleanup') {
  47. sh '''
  48. for i in `prlctl list -aij|jq -r '.[]|select((.Uptime|tonumber > 86400) and (.State == "running"))|.ID'`
  49. do
  50. prlctl stop $i --kill
  51. done
  52. # don't delete vm's that haven't started yet ((.State == "stopped") and (.Uptime == "0"))
  53. for i in `prlctl list -aij|jq -r '.[]|select((.Uptime|tonumber > 0) and (.State != "running"))|.ID'`
  54. do
  55. prlctl delete $i
  56. done
  57. '''
  58. }
  59. // Checkout the repo
  60. stage('Clone') {
  61. cleanWs notFailBuild: true
  62. checkout scm
  63. sh 'git fetch --no-tags https://github.com/saltstack/salt.git +refs/heads/${SALT_TARGET_BRANCH}:refs/remotes/origin/${SALT_TARGET_BRANCH}'
  64. }
  65. // Setup the kitchen required bundle
  66. stage('Setup') {
  67. sh 'bundle install --with vagrant macos --without ec2 windows opennebula docker'
  68. }
  69. stage('Create VM') {
  70. sh '''
  71. bundle exec kitchen create $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";
  72. '''
  73. sh """
  74. if [ -s ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ]; then
  75. mv ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ".kitchen/logs/${python_version}-${distro_name}-${distro_version}-create.log"
  76. fi
  77. if [ -s ".kitchen/logs/kitchen.log" ]; then
  78. mv ".kitchen/logs/kitchen.log" ".kitchen/logs/kitchen-create.log"
  79. fi
  80. """
  81. }
  82. try {
  83. timeout(time: testrun_timeout, unit: 'HOURS') {
  84. stage('Converge VM') {
  85. sh '''
  86. ssh-agent /bin/bash -c 'ssh-add ~/.vagrant.d/insecure_private_key; bundle exec kitchen converge $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?"'
  87. '''
  88. sh """
  89. if [ -s ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ]; then
  90. mv ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ".kitchen/logs/${python_version}-${distro_name}-${distro_version}-converge.log"
  91. fi
  92. if [ -s ".kitchen/logs/kitchen.log" ]; then
  93. mv ".kitchen/logs/kitchen.log" ".kitchen/logs/kitchen-converge.log"
  94. fi
  95. """
  96. }
  97. stage('Run Tests') {
  98. sh 'bundle exec kitchen verify $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";'
  99. }
  100. }
  101. } finally {
  102. try {
  103. sh """
  104. if [ -s ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ]; then
  105. mv ".kitchen/logs/${python_version}-${distro_name}-${distro_version}.log" ".kitchen/logs/${python_version}-${distro_name}-${distro_version}-verify.log"
  106. fi
  107. if [ -s ".kitchen/logs/kitchen.log" ]; then
  108. mv ".kitchen/logs/kitchen.log" ".kitchen/logs/kitchen-verify.log"
  109. fi
  110. """
  111. archiveArtifacts(
  112. artifacts: "artifacts/*,artifacts/**/*,.kitchen/logs/*-create.log,.kitchen/logs/*-converge.log,.kitchen/logs/*-verify.log,.kitchen/logs/*-download.log,artifacts/xml-unittests-output/*.xml",
  113. allowEmptyArchive: true
  114. )
  115. junit 'artifacts/xml-unittests-output/*.xml'
  116. } finally {
  117. stage('Cleanup') {
  118. sh '''
  119. bundle exec kitchen destroy $TEST_SUITE-$TEST_PLATFORM; echo "ExitCode: $?";
  120. '''
  121. }
  122. stage('Upload Coverage') {
  123. def distro_strings = [
  124. distro_name,
  125. distro_version
  126. ]
  127. def report_strings = (
  128. [python_version] + nox_env_name.split('-')
  129. ).flatten()
  130. uploadCodeCoverage(
  131. report_path: 'artifacts/coverage/coverage.xml',
  132. report_name: "${distro_strings.join('-')}-${report_strings.join('-')}",
  133. report_flags: ([distro_strings.join('')] + report_strings).flatten()
  134. )
  135. }
  136. }
  137. }
  138. }
  139. }
  140. // vim: ft=groovy