System configuration for OpenStack Infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

apply-test.sh 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/bash -ex
  2. # Copyright 2014 Hewlett-Packard Development Company, L.P.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. . ./tools/prep-apply.sh
  16. if [[ ! -d applytest ]] ; then
  17. mkdir applytest
  18. fi
  19. # First split the variables at the beginning of the file
  20. csplit -sf applytest/prep $PUPPET_MANIFEST '/^$/' {0}
  21. # Then split the class defs.
  22. csplit -sf applytest/puppetapplytest applytest/prep01 '/^}$/' {*}
  23. # Remove } header left by csplit
  24. sed -i -e '/^\}$/d' applytest/puppetapplytest*
  25. # Comment out anything that doesn't begin with a space.
  26. # This gives us the node {} internal contents.
  27. sed -i -e 's/^[^][:space:]$]/#&/g' applytest/prep00 applytest/puppetapplytest*
  28. sed -i -e 's@hiera(.\([^.]*\).,\([^)]*\))@\2@' applytest/prep00 applytest/puppetapplytest*
  29. sed -i -e "s@hiera(.\([^.]*\).)@'\1NoDefault'@" applytest/prep00 applytest/puppetapplytest*
  30. mv applytest/prep00 applytest/head # These are the top-level variables defined in site.pp
  31. if [[ `lsb_release -i -s` == 'CentOS' ]]; then
  32. if [[ `lsb_release -r -s` =~ '7' ]]; then
  33. CODENAME='centos7'
  34. fi
  35. elif [[ `lsb_release -i -s` == 'Debian' ]]; then
  36. CODENAME=`lsb_release -c -s`
  37. elif [[ `lsb_release -i -s` == 'Ubuntu' ]]; then
  38. CODENAME=`lsb_release -c -s`
  39. elif [[ `lsb_release -i -s` == 'Fedora' ]]; then
  40. REL=`lsb_release -r -s`
  41. CODENAME="fedora$REL"
  42. fi
  43. FOUND=0
  44. for f in `find applytest -name 'puppetapplytest*' -print` ; do
  45. if grep -q "Node-OS: $CODENAME" $f; then
  46. if grep -q "Puppet-Version: !${PUPPET_VERSION}" $f; then
  47. echo "Skipping $f due to unsupported puppet version"
  48. continue
  49. else
  50. cat applytest/head $f > $f.final
  51. FOUND=1
  52. fi
  53. fi
  54. done
  55. if [[ $FOUND == "0" ]]; then
  56. echo "No hosts found for node type $CODENAME"
  57. exit 1
  58. fi
  59. cat > applytest/primer.pp << EOF
  60. class helloworld {
  61. notify { 'hello, world!': }
  62. }
  63. EOF
  64. sudo mkdir -p /var/run/puppet
  65. echo "Running apply test primer to avoid setup races when run in parallel."
  66. ./tools/test_puppet_apply.sh applytest/primer.pp
  67. THREADS=$(nproc)
  68. if grep -qi centos /etc/os-release ; then
  69. # Single thread on centos to workaround a race with rsync on centos
  70. # when copying puppet modules for multiple puppet applies at the same
  71. # time.
  72. THREADS=1
  73. fi
  74. echo "Running apply test on these hosts:"
  75. find applytest -name 'puppetapplytest*.final' -print0
  76. find applytest -name 'puppetapplytest*.final' -print0 | \
  77. xargs -0 -P $THREADS -n 1 -I filearg \
  78. ./tools/test_puppet_apply.sh filearg