Fuel plugins
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.

run_tests.sh 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/bin/bash
  2. # Copyright 2014 Mirantis, Inc.
  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. set -eu
  16. function usage {
  17. echo "Usage: $0 [OPTION]..."
  18. echo "Run fuel plugin building"
  19. echo ""
  20. echo " -b, --build Builds all of the plugins"
  21. echo " -B, --no-build Don't run plugins build"
  22. echo " -f, --fpb Run tests for fpb"
  23. echo " -F, --no-fpb Don't run tests for fpb"
  24. echo " -h, --help Print this usage message"
  25. echo ""
  26. echo "Note: with no options specified, the script will try to run "
  27. echo " all available tests with all available checks."
  28. exit
  29. }
  30. function process_options {
  31. for arg in $@; do
  32. case "$arg" in
  33. -h|--help) usage;;
  34. -b|--build) plugins_build=1;;
  35. -B|--no-build) no_plugins_build=1;;
  36. -f|--fpb) fpb_tests=1;;
  37. -F|--no-fpb) no_fpb_tests=1;;
  38. -*) testropts="$testropts $arg";;
  39. *) testrargs="$testrargs $arg"
  40. esac
  41. done
  42. }
  43. # Settings
  44. ROOT=$(dirname `readlink -f $0`)
  45. FPB_VENV_PATH=${FPB_VENV_PATH:-"${ROOT}/fpb_venv"}
  46. BUILT_PLUGINS_PATH=${BUILT_PLUGINS_PATH:-"${ROOT}/built_plugins"}
  47. # Initialize global variables
  48. plugins_build=0
  49. no_plugins_build=0
  50. fpb_tests=0
  51. no_fpb_tests=0
  52. function run_tests {
  53. run_cleanup
  54. # This variable collects all failed tests. It'll be printed in
  55. # the end of this function as a small statistic for user.
  56. local errors=""
  57. # Enable all tests if none was specified skipping all explicitly
  58. # disabled tests.
  59. if [[ $plugins_build -eq 0 && \
  60. $fpb_tests -eq 0 ]]; then
  61. if [ $no_plugins_build -ne 1 ]; then plugins_build=1; fi
  62. if [ $no_fpb_tests -ne 1 ]; then fpb_tests=1; fi
  63. fi
  64. # Run all enabled tests
  65. if [ $plugins_build -eq 1 ]; then
  66. echo "Starting plugins build..."
  67. run_build || errors+=" plugins_build"
  68. fi
  69. if [ $fpb_tests -eq 1 ]; then
  70. echo "Starting fpb testing..."
  71. run_fpb || errors+=" fpb_tests"
  72. fi
  73. if [ -n "$errors" ]; then
  74. echo Failed tests: $errors
  75. exit 1
  76. fi
  77. exit
  78. }
  79. function run_cleanup {
  80. find ${ROOT} -type f -name *.pyc -delete
  81. }
  82. function run_fpb {
  83. local result=0
  84. pushd "${ROOT}" >> /dev/null
  85. tox || result=1
  86. popd >> /dev/null
  87. return $result
  88. }
  89. # Build all of the plugins with current version of plugins builder
  90. function run_build {
  91. virtualenv $FPB_VENV_PATH
  92. # virtualenv has unbound variables
  93. # disable it during virtualenv usage
  94. set +u
  95. source $FPB_VENV_PATH/bin/activate || return 1
  96. fpb_path="${ROOT}"
  97. pushd $fpb_path
  98. pip install .
  99. popd
  100. mkdir -p $BUILT_PLUGINS_PATH
  101. rm -f $BUILT_PLUGINS_PATH/*.fp
  102. rm -f $BUILT_PLUGINS_PATH/*.rpm
  103. # Find plugins
  104. for dir in $ROOT/examples/*/metadata.yaml;
  105. do
  106. plugin_dir=$(dirname "${dir}");
  107. pushd "${plugin_dir}"
  108. fpb --build "${plugin_dir}" --debug || return 1
  109. cp *.fp $BUILT_PLUGINS_PATH/
  110. cp *.rpm $BUILT_PLUGINS_PATH/
  111. popd
  112. done
  113. deactivate
  114. set -u
  115. return 0
  116. }
  117. # Parse command line arguments and run the tests
  118. process_options $@
  119. run_tests