From 5586bfaad41db434b818e2b5151986929351bce4 Mon Sep 17 00:00:00 2001 From: ekhomyakova Date: Fri, 23 Dec 2016 14:30:41 +0400 Subject: [PATCH] Adapt plugin-tests to run on real nailgun Change-Id: I2e97be848f0acbeac919564d60a649d486dde0a4 --- run_real_plugin_tests.sh | 4 +- run_real_plugin_tests_on_real_nailgun.sh | 124 ++++++++++++++++++ static/tests/functional/config/intern.js | 7 +- static/tests/functional/helpers.js | 2 +- .../real_plugin/feature_nics/test_bonds.js | 16 +-- .../real_plugin/feature_nics/test_nics.js | 15 +-- .../real_plugin/feature_nics/test_nodes.js | 13 +- .../functional/real_plugin/plugin_helpers.js | 4 +- .../real_plugin/update_plugin_on_real.sh | 49 +++++++ 9 files changed, 201 insertions(+), 33 deletions(-) create mode 100755 run_real_plugin_tests_on_real_nailgun.sh create mode 100644 static/tests/functional/real_plugin/update_plugin_on_real.sh diff --git a/run_real_plugin_tests.sh b/run_real_plugin_tests.sh index 0a53ea844..689ec404e 100755 --- a/run_real_plugin_tests.sh +++ b/run_real_plugin_tests.sh @@ -25,7 +25,7 @@ export CONF_PATH="${TESTS_ROOT}/${TESTS_DIR_NAME}/plugin_conf" export NO_NAILGUN_START=${NO_NAILGUN_START:-0} export FUEL_WEB_ROOT=$(readlink -f ${FUEL_WEB_ROOT:-"$(dirname $0)/../fuel-web"}) -export ARTIFACTS=${ARTIFACTS:-"$(pwd)/test_run/ui_component"} +export ARTIFACTS=${ARTIFACTS:-"$(pwd)/test_run/${TESTS_DIR_NAME}"} export PLUGIN_RPM=${PLUGIN_RPM:-''} if [ -z "${PLUGIN_RPM}" ]; then @@ -91,7 +91,7 @@ function install_prepare_plugin { } function remove_plugins { - for plug in $(echo $INSTALLED_PLUGINS | tr ";") + for plug in $(echo ${INSTALLED_PLUGINS} | tr ";" "\n") do fuel --os-username admin --os-password admin plugins \ --remove "${plug}" 2>/dev/null && \ diff --git a/run_real_plugin_tests_on_real_nailgun.sh b/run_real_plugin_tests_on_real_nailgun.sh new file mode 100755 index 000000000..004484e37 --- /dev/null +++ b/run_real_plugin_tests_on_real_nailgun.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +# Copyright 2016 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +set -eu + +# Variables for remote (master node) +export REMOTE_HOST=${REMOTE_HOST:-'10.109.0.2'} +export REMOTE_USER=${REMOTE_USER:-'root'} +export REMOTE_SSH_PORT=${REMOTE_SSH_PORT:-22} +export REMOTE_PASSWORD=${REMOTE_PASSWORD:-'r00tme'} +export REMOTE_DIR=${REMOTE_DIR:-'/root'} + +export FUEL_UI_HOST=${FUEL_UI_HOST:-${REMOTE_HOST}} + +export REMOTE_EXEC="sshpass -p ${REMOTE_PASSWORD} + ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no + -p ${REMOTE_SSH_PORT} ${REMOTE_USER}@${REMOTE_HOST}" + +# Variables for tests +export TESTS_ROOT="$(pwd)/static/tests/functional/real_plugin" +export SCRIPT_PATH="${TESTS_ROOT}/update_plugin_on_real.sh" +export TEST_PREFIX=${TEST_PREFIX:-'test_*'} +export TESTS_DIR_NAME=${TESTS_DIR_NAME:-'feature_nics'} +export CONF_PATH="${TESTS_ROOT}/${TESTS_DIR_NAME}/plugin_conf" + +export ARTIFACTS=${ARTIFACTS:-"$(pwd)/test_run/${TESTS_DIR_NAME}"} + +plugins='https://product-ci.infra.mirantis.net/view/All/job/9.0.build-fuel-plugins' +path='lastSuccessfulBuild/artifact/built_plugins/fuel_plugin_example_v5-1.0-1.0.0-1.noarch.rpm' +plugin_url=${PLUGIN_URL:-"${plugins}/${path}"} + +plugins='http://plugins.mirantis.com/repository/f/u/fuel-plugin-vmware-dvs' +path='fuel-plugin-vmware-dvs-3.1-3.1.0-1.noarch.rpm' +plugin2_url=${PLUGIN_URL_SECOND:-"${plugins}/${path}"} + +export NAILGUN_STATIC=$ARTIFACTS/static +mkdir -p "$ARTIFACTS" + +function install_prepare_plugin { + url=$1 + file_name=$2 + ${REMOTE_EXEC} wget --no-check-certificate -O "${REMOTE_DIR}/${file_name}.rpm" "${url}" + + export PLUGIN_PATH=$( + ${REMOTE_EXEC} fuel plugins --install "${REMOTE_DIR}/${file_name}.rpm" | awk '/Installing:/ { getline; print $1 }' + ) + + export PLUGIN_PATH="/var/www/nailgun/plugins/${PLUGIN_PATH}" + + meta="${PLUGIN_PATH}/metadata.yaml" + export plugin_name=$(${REMOTE_EXEC} egrep '^name: ' "${meta}" | cut -d ' ' -f 2) + export plugin_version=$(${REMOTE_EXEC} egrep '^version: ' "${meta}" | cut -d ' ' -f 2) + + # Fix package version + ${REMOTE_EXEC} sed -i '$!s/4.0.0/5.0.0/' ${PLUGIN_PATH}/metadata.yaml + ${REMOTE_EXEC} fuel plugins --sync + + # Fix components settings + ${REMOTE_EXEC} sed -i '/requires/,/+$/s/^/#/' ${PLUGIN_PATH}/components.yaml + ${REMOTE_EXEC} fuel plugins --sync + + export INSTALLED_PLUGINS="${INSTALLED_PLUGINS};${plugin_name}==${plugin_version//\'/}" +} + +function remove_plugin { + for plug in $(echo ${INSTALLED_PLUGINS} | tr ";" "\n") + do + ${REMOTE_EXEC} fuel plugins --remove "${plug}" 2>/dev/null && \ + echo "${plug} was removed" || echo "Can not remove plugin ${plug}" + done +} + +function remote_scp { + local_file=$1 + + sshpass -p ${REMOTE_PASSWORD} \ + scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ + -P ${REMOTE_SSH_PORT} $local_file ${REMOTE_USER}@${REMOTE_HOST}:/${REMOTE_DIR}/ +} + +function run_component_tests { + local GULP='./node_modules/.bin/gulp' + local TESTS_DIR="static/tests/functional/real_plugin/${TESTS_DIR_NAME}" + local TESTS=${TESTS_DIR}/${TEST_PREFIX}.js + local result=0 + + export INSTALLED_PLUGINS='' + + if [ ${TESTS_DIR_NAME} == 'feature_nics' ]; then + install_prepare_plugin ${plugin2_url} "plugin2" + for conf in 'nic' 'node' 'bond'; do + remote_scp ${CONF_PATH}/${conf}_plugin2.yaml + ${REMOTE_EXEC} cp ${REMOTE_DIR}/${conf}_plugin2.yaml ${PLUGIN_PATH}/${conf}_config.yaml + done + fi + + install_prepare_plugin ${plugin_url} "plugin" + + for test_case in $TESTS; do + echo "INFO: Running test case ${test_case}" + + ARTIFACTS=$ARTIFACTS \ + ${GULP} intern:functional --suites="${test_case}" || result=1 + done + + remove_plugin + + return $result +} + +run_component_tests diff --git a/static/tests/functional/config/intern.js b/static/tests/functional/config/intern.js index 03af1a0d8..d57900e78 100644 --- a/static/tests/functional/config/intern.js +++ b/static/tests/functional/config/intern.js @@ -19,10 +19,15 @@ define(function() { return { proxyPort: 9057, + tunnelOptions: { + hostname: process.env.SELENIUM_SERVER_HOST || 'localhost', + port: process.env.SELENIUM_SERVER_PORT || 4444 + }, proxyUrl: 'http://localhost:9057/', maxConcurrency: 1, grep: /^/, excludeInstrumentation: /^/, - reporters: ['Runner', 'tests/functional/screenshot_on_fail'] + reporters: ['Runner', 'tests/functional/screenshot_on_fail', + {id: 'JUnit', filename: process.env.ARTIFACTS + '/junit.xml'}] }; }); diff --git a/static/tests/functional/helpers.js b/static/tests/functional/helpers.js index 9feb0c367..1d2b078f6 100644 --- a/static/tests/functional/helpers.js +++ b/static/tests/functional/helpers.js @@ -503,7 +503,7 @@ define([ } }); - var serverHost = '127.0.0.1'; + var serverHost = process.env.NAILGUN_HOST || '127.0.0.1'; var serverPort = process.env.NAILGUN_PORT || 5544; var serverUrl = 'http://' + serverHost + ':' + serverPort; var username = 'admin'; diff --git a/static/tests/functional/real_plugin/feature_nics/test_bonds.js b/static/tests/functional/real_plugin/feature_nics/test_bonds.js index 700059058..d88edeb4f 100644 --- a/static/tests/functional/real_plugin/feature_nics/test_bonds.js +++ b/static/tests/functional/real_plugin/feature_nics/test_bonds.js @@ -52,14 +52,9 @@ define([ return this.remote .deleteCluster(modal); }, - 'Set up attributes': function() { - return this.remote - .updatePlugin('update_bonds bond_setup') - - .newClusterWithPlugin(modal); - }, - 'Test attributes for BOND interfaces provided by plugin': function() { + test_bonds: function() { // Test attributes for BOND interfaces provided by plugin return this.remote + .updatePlugin('update_bonds bond_setup') .newClusterWithPlugin(modal) // Add one node, open interface configuration @@ -77,7 +72,7 @@ define([ // Save changes .applyItfChanges(); }, - 'Test Load defaults for BONDs': function() { + bond_defaults: function() { // Test Load defaults for BONDs return this.remote .newClusterWithPlugin(modal) @@ -103,14 +98,13 @@ define([ .assertElementNotExists('input[label="bond0"]', 'Interfaces were not unbonded') .applyItfChanges(); }, - 'Test several plugins with different attributes for BOND': function() { + bond_multiple_plugins: function() { // Test several plugins with different BOND configs var bondCheckboxDVS = 'input[type="checkbox"][name="attribute_checkbox_b"]'; return this.remote // Create cluster with plugins .newClusterFillName(modal) .pressKeys('\uE007') // go to Compute - .clickByCssSelector('input[name="hypervisor:vmware"]') .pressKeys('\uE007') // Networking .clickByCssSelector('input[name="network:neutron:ml2:dvs"]') .pressKeys('\uE007') // Storage @@ -190,7 +184,7 @@ define([ // Save with default values .applyItfChanges(); }, - 'Test restrictions for Bonds': function() { + bond_restrictions: function() { // Test restrictions for Bonds return this.remote .updatePlugin('update_bonds bond_restrict') .newClusterWithPlugin(modal) diff --git a/static/tests/functional/real_plugin/feature_nics/test_nics.js b/static/tests/functional/real_plugin/feature_nics/test_nics.js index fc9e95af5..e15e80a92 100644 --- a/static/tests/functional/real_plugin/feature_nics/test_nics.js +++ b/static/tests/functional/real_plugin/feature_nics/test_nics.js @@ -52,7 +52,7 @@ define([ return this.remote .deleteCluster(modal); }, - 'Set up all attributes': function() { + set_up: function() { // Set up all attributes return this.remote .updatePlugin('update_nics nic_setup') .updatePlugin('update_nodes node_setup') @@ -60,7 +60,7 @@ define([ .newClusterWithPlugin(modal); }, - 'Test attributes for NIC interfaces': function() { + test_nics: function() { // Test attributes for NIC interfaces return this.remote .newClusterWithPlugin(modal) @@ -86,7 +86,7 @@ define([ // Save changes .applyItfChanges(); }, - 'Test Load defaults attributes for NIC': function() { + nic_defaults: function() { // Test Load defaults attributes for NIC return this.remote .newClusterWithPlugin(modal) @@ -121,7 +121,7 @@ define([ // Save with default values .applyItfChanges(); }, - 'Test cluster without plugin has only core attributes': function() { + test_core: function() { // Test cluster without plugin has only core attributes return this.remote // Create cluster without plugin .clickByCssSelector('.create-cluster') @@ -183,7 +183,7 @@ define([ return modal.waitToClose(); }); }, - 'Test that NIC config may be changed for several nodes simultaneously': function() { + test_mass_config: function() { // Test NICs may be changed for two nodes simultaneously return this.remote .newClusterWithPlugin(modal) @@ -224,7 +224,7 @@ define([ .applyItfChanges(); }, - 'Test several plugins with different attributes for NIC': function() { + nic_multiple_plugins: function() { // Test several plugins with different NIC configs var nicCheckboxDVS = 'input[type="checkbox"][name="attribute_checkbox_b"]'; var nicTextItf1 = '.ifc-list > div:nth-child(1) ' + nicText; @@ -232,7 +232,6 @@ define([ // Create cluster with plugins .newClusterFillName(modal) .pressKeys('\uE007') // go to Compute - .clickByCssSelector('input[name="hypervisor:vmware"]') .pressKeys('\uE007') // Networking .clickByCssSelector('input[name="network:neutron:ml2:dvs"]') .pressKeys('\uE007') // Storage @@ -303,7 +302,7 @@ define([ // Save with default values .applyItfChanges(); }, - 'Test restrictions': function() { + nic_restrictions: function() { // Test restrictions for NICs var nicText = 'input[type="text"][name="attribute_text_r"]'; return this.remote diff --git a/static/tests/functional/real_plugin/feature_nics/test_nodes.js b/static/tests/functional/real_plugin/feature_nics/test_nodes.js index ea5e60ef7..35ce010b6 100644 --- a/static/tests/functional/real_plugin/feature_nics/test_nodes.js +++ b/static/tests/functional/real_plugin/feature_nics/test_nodes.js @@ -50,13 +50,9 @@ define([ return this.remote .deleteCluster(modal); }, - 'Set up attributes': function() { + test_nodes: function() { // Test attributes for Nodes return this.remote .updatePlugin('update_nodes node_setup') - .newClusterWithPlugin(modal); - }, - 'Test attributes for Nodes': function() { - return this.remote .newClusterWithPlugin(modal) // Add node and open settings for it @@ -90,7 +86,7 @@ define([ return modal.waitToClose(); }); }, - 'Test Load defaults for Nodes': function() { + node_defaults: function() { // Test Load defaults for Nodes return this.remote .newClusterWithPlugin(modal) @@ -129,14 +125,13 @@ define([ return modal.waitToClose(); }); }, - 'Test several plugins with different attributes for Nodes': function() { + node_multiple_plugins: function() { // Test several plugins with different Nodes configs var nodeCheckboxDVS = 'input[type=checkbox][name="attribute_checkbox_b"]'; return this.remote // Create cluster with plugins .newClusterFillName(modal) .pressKeys('\uE007') // go to Compute - .clickByCssSelector('input[name="hypervisor:vmware"]') .pressKeys('\uE007') // Networking .clickByCssSelector('input[name="network:neutron:ml2:dvs"]') .pressKeys('\uE007') // Storage @@ -214,7 +209,7 @@ define([ return modal.waitToClose(); }); }, - 'Test restrictions for Nodes': function() { + node_restrictions: function() { // Test restrictions for Nodes return this.remote .updatePlugin('update_nodes node_restrict') .newClusterWithPlugin(modal) diff --git a/static/tests/functional/real_plugin/plugin_helpers.js b/static/tests/functional/real_plugin/plugin_helpers.js index 344fe0b7d..040b2d6fd 100644 --- a/static/tests/functional/real_plugin/plugin_helpers.js +++ b/static/tests/functional/real_plugin/plugin_helpers.js @@ -104,7 +104,9 @@ define([ .clickIfExists('button.remove-cluster-btn') .then(function() { modal.waitToClose(); - }); + }) + + .waitForCssSelector('.create-cluster', 1000); }); }, clickObjectByIndex: function(objectsCssSelector, index) { diff --git a/static/tests/functional/real_plugin/update_plugin_on_real.sh b/static/tests/functional/real_plugin/update_plugin_on_real.sh new file mode 100644 index 000000000..4653e8377 --- /dev/null +++ b/static/tests/functional/real_plugin/update_plugin_on_real.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +function remote_scp { + local_file=$1 + + sshpass -p ${REMOTE_PASSWORD} \ + scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \ + -P ${REMOTE_SSH_PORT} $local_file ${REMOTE_USER}@${REMOTE_HOST}:/${REMOTE_DIR}/ +} + +function update_components { + default=${CONF_PATH}/$1.yaml + components_file=${CONF_PATH}/$2.yaml + + remote_scp ${components_file} + remote_scp ${default} + + ${REMOTE_EXEC} sh -c "cat ${REMOTE_DIR}/$1.yaml ${REMOTE_DIR}/$1.yaml > ${PLUGIN_PATH}/components.yaml" +} + +function update_nics { + nic_file=${CONF_PATH}/$1.yaml + + remote_scp ${nic_file} + ${REMOTE_EXEC} cp ${REMOTE_DIR}/$1.yaml ${PLUGIN_PATH}/nic_config.yaml +} + +function update_nodes { + node_file=${CONF_PATH}/$1.yaml + + remote_scp ${node_file} + ${REMOTE_EXEC} cp ${REMOTE_DIR}/$1.yaml ${PLUGIN_PATH}/node_config.yaml +} + +function update_bonds { + bond_file=${CONF_PATH}/$1.yaml + + remote_scp ${bond_file} + ${REMOTE_EXEC} cp ${REMOTE_DIR}/$1.yaml ${PLUGIN_PATH}/bond_config.yaml +} + +case $1 in + update_components|update_nics|update_nodes|update_bonds) func=$1; params="${@:2}";; + *) func=update_components; params="$@";; +esac + +$func $params + +${REMOTE_EXEC} fuel plugins --sync