Fuel Web UI
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_real_plugin_tests.sh 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/bash
  2. # Copyright 2016 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. # Variables for tests
  17. export TESTS_ROOT="$(pwd)/static/tests/functional/real_plugin"
  18. export SCRIPT_PATH="${TESTS_ROOT}/update_plugin.sh"
  19. export TEST_PREFIX=${TEST_PREFIX:-'test_*'}
  20. export TESTS_DIR_NAME=${TESTS_DIR_NAME:-'feature_nics'}
  21. export CONF_PATH="${TESTS_ROOT}/${TESTS_DIR_NAME}/plugin_conf"
  22. export NO_NAILGUN_START=${NO_NAILGUN_START:-0}
  23. export FUEL_WEB_ROOT=$(readlink -f ${FUEL_WEB_ROOT:-"$(dirname $0)/../fuel-web"})
  24. export ARTIFACTS=${ARTIFACTS:-"$(pwd)/test_run/${TESTS_DIR_NAME}"}
  25. export PLUGIN_RPM=${PLUGIN_RPM:-''}
  26. if [ -z "${PLUGIN_RPM}" ]; then
  27. plugins='https://product-ci.infra.mirantis.net/view/All/job/9.0.build-fuel-plugins'
  28. path='lastSuccessfulBuild/artifact/built_plugins/fuel_plugin_example_v5-1.0-1.0.0-1.noarch.rpm'
  29. plugin_url=${PLUGIN_URL:-"${plugins}/${path}"}
  30. export PLUGIN_RPM="${CONF_PATH}/plugin.rpm"
  31. wget --no-check-certificate -O "${PLUGIN_RPM}" "${plugin_url}"
  32. fi
  33. if [ ${TESTS_DIR_NAME} == 'feature_nics' ]; then
  34. export PLUGIN_RPM_SECOND=${PLUGIN_RPM_SECOND:-''}
  35. if [ -z "${PLUGIN_RPM_SECOND}" ]; then
  36. plugins='http://plugins.mirantis.com/repository/f/u/fuel-plugin-vmware-dvs'
  37. path='fuel-plugin-vmware-dvs-3.1-3.1.0-1.noarch.rpm'
  38. plugin_url=${PLUGIN_URL_SECOND:-"${plugins}/${path}"}
  39. export PLUGIN_RPM_SECOND="${CONF_PATH}/plugin2.rpm"
  40. wget --no-check-certificate -O "${PLUGIN_RPM_SECOND}" "${plugin_url}"
  41. fi
  42. fi
  43. # Variables for nailgun
  44. export NAILGUN_PORT=${NAILGUN_PORT:-5544}
  45. export NAILGUN_START_MAX_WAIT_TIME=${NAILGUN_START_MAX_WAIT_TIME:-30}
  46. export NAILGUN_DB_HOST=${NAILGUN_DB_HOST:-/var/run/postgresql}
  47. export NAILGUN_DB=${NAILGUN_DB:-nailgun}
  48. export NAILGUN_DB_USER=${NAILGUN_DB_USER:-nailgun}
  49. export NAILGUN_DB_USERPW=${NAILGUN_DB_USERPW:-nailgun}
  50. export DB_ROOT=${DB_ROOT:-postgres}
  51. export NAILGUN_ROOT=$FUEL_WEB_ROOT/nailgun
  52. export NAILGUN_STATIC=$ARTIFACTS/static
  53. export NAILGUN_TEMPLATES=$NAILGUN_STATIC
  54. export NAILGUN_CHECK_URL='/api/version'
  55. mkdir -p "$ARTIFACTS"
  56. function install_prepare_plugin {
  57. plugin_rpm=$1
  58. mkdir -p "${nailgun_plugins_path}"
  59. local plugin_dir=$(sudo alien -i "${plugin_rpm}" | grep -oP 'Setting up \K[^ ]*')
  60. export PLUGIN_PATH=$(echo ${nailgun_plugins_path}/${plugin_dir//[-_]/\*})
  61. meta=${PLUGIN_PATH}/metadata.yaml
  62. plugin_name=$(grep -oP '^name: \K(.*)' "${meta}")
  63. plugin_version=$(grep -oP '^version: \K(.*)' "${meta}")
  64. # Fix versions
  65. sudo sed -i -e "s/fuel_version: .*/fuel_version: \['10.0'\]/" "${meta}"
  66. sudo sed -i -e "s/package_version: .*/package_version: '5.0.0'/" "${meta}"
  67. sudo sed -i -e "s/mitaka-9.0/newton-10.0/" "${meta}" # release version
  68. # Fix requirements
  69. sudo sed -i -e '/requires/,$s/^/#/' ${PLUGIN_PATH}/components.yaml
  70. sudo sed -i -e '/error/ s/^/#/' ${PLUGIN_PATH}/environment_config.yaml
  71. fuel --os-username admin --os-password admin plugins \
  72. --register "${plugin_name}==${plugin_version//\'/}"
  73. export INSTALLED_PLUGINS="${INSTALLED_PLUGINS};${plugin_name}==${plugin_version//\'/}"
  74. }
  75. function remove_plugins {
  76. for plug in $(echo ${INSTALLED_PLUGINS} | tr ";" "\n")
  77. do
  78. fuel --os-username admin --os-password admin plugins \
  79. --remove "${plug}" 2>/dev/null && \
  80. echo "${plug} was removed" || echo "Can not remove plugin ${plug}"
  81. done
  82. }
  83. function run_component_tests {
  84. local GULP='./node_modules/.bin/gulp'
  85. local TESTS_DIR="static/tests/functional/real_plugin/${TESTS_DIR_NAME}"
  86. local TESTS=${TESTS_DIR}/${TEST_PREFIX}.js
  87. local result=0
  88. export SERVER_ADDRESS=${SERVER_ADDRESS:-'127.0.0.1'}
  89. export SERVER_PORT=${NAILGUN_PORT}
  90. export nailgun_plugins_path='/var/www/nailgun/plugins'
  91. pip install python-fuelclient
  92. fuelclient="${VENV}/lib/python2.7/site-packages/fuelclient"
  93. sed -i -e "s/if self.auth_required/if True/" "${fuelclient}/client.py"
  94. echo "Building tests..."
  95. ${GULP} intern:transpile
  96. if [ "${NO_NAILGUN_START}" -ne 1 ]; then
  97. pushd "$FUEL_WEB_ROOT" > /dev/null
  98. tox -e stop
  99. tox -e cleanup
  100. tox -e start
  101. ./nailgun/manage.py loaddata ${TESTS_ROOT}/fixture_nodes.json
  102. popd > /dev/null
  103. fi
  104. export INSTALLED_PLUGINS=''
  105. if [ ${TESTS_DIR_NAME} == 'feature_nics' ]; then
  106. install_prepare_plugin "${PLUGIN_RPM_SECOND}"
  107. for conf in 'nic' 'node' 'bond'; do
  108. sudo cp ${CONF_PATH}/${conf}_plugin2.yaml ${PLUGIN_PATH}/${conf}_config.yaml
  109. done
  110. fi
  111. install_prepare_plugin "${PLUGIN_RPM}"
  112. ${GULP} build --no-sourcemaps --extra-entries=sinon --static-dir="$NAILGUN_STATIC"
  113. if [ $? -ne 0 ]; then
  114. return 1
  115. fi
  116. for test_case in $TESTS; do
  117. echo "INFO: Running test case ${test_case}"
  118. ARTIFACTS=$ARTIFACTS \
  119. ${GULP} functional-tests --no-transpile --suites="${test_case}" || result=1
  120. done
  121. remove_plugins
  122. if [ "${NO_NAILGUN_START}" -ne 1 ]; then
  123. pushd "$FUEL_WEB_ROOT" > /dev/null
  124. tox -e stop
  125. popd > /dev/null
  126. fi
  127. return $result
  128. }
  129. run_component_tests