From 6b8319e32a94c228ff4258cf31dcd6c271350e1c Mon Sep 17 00:00:00 2001 From: vponomaryov Date: Mon, 9 Nov 2015 19:36:56 +0200 Subject: [PATCH] Split common logic of CI hooks to separate file Manila contains CI hooks located in "contrib/ci" dir. Split common logic to separate file to be able to just "source" it and then use env vars and bash functions in different CI jobs and projects. Current change allows to do two things: - Reuse env var "MANILA_TEMPEST_COMMIT" in third-party CIs - Wait for drivers init in other projects like OpenStack Rally. Where, for the moment, one of jobs fails because of absense of "waiting". Usage: $ source %manila%/contrib/ci/common.sh $ echo $MANILA_TEMPEST_COMMIT $ manila_wait_for_drivers_init "/etc/manila/manila.conf" Change-Id: I94514405628ab8337d1f4153e431f064614e3596 --- contrib/ci/common.sh | 69 ++++++++++++++++++++++++++++++++++++ contrib/ci/post_test_hook.sh | 53 +++------------------------ contrib/ci/pre_test_hook.sh | 4 +-- 3 files changed, 75 insertions(+), 51 deletions(-) create mode 100755 contrib/ci/common.sh diff --git a/contrib/ci/common.sh b/contrib/ci/common.sh new file mode 100755 index 0000000000..ecdf59ec3f --- /dev/null +++ b/contrib/ci/common.sh @@ -0,0 +1,69 @@ +# Environment variables + +export MANILA_TEMPEST_COMMIT="c43c8f91" # 05 Nov, 2015 + +# ---------------------------------------------- + +# Functions + +function manila_check_service_vm_availability { + # First argument is expected to be IP address of a service VM + + wait_step=10 + wait_timeout=300 + available='false' + while (( wait_timeout > 0 )) ; do + if [[ "$(ping -w 1 $1)" =~ "1 received" ]]; then + available='true' + break + fi + ((wait_timeout-=$wait_step)) + sleep $wait_step + done + + if [[ $available == 'true' ]]; then + echo "SUCCESS! Service VM $1 is available." + else + echo "FAILURE! Service VM $1 is not available." + exit 1 + fi +} + +function manila_wait_for_generic_driver_init { + # First argument is expected to be file path to Manila config + + MANILA_CONF=$1 + DRIVER_GROUPS=$(iniget $MANILA_CONF DEFAULT enabled_share_backends) + for driver_group in ${DRIVER_GROUPS//,/ }; do + SHARE_DRIVER=$(iniget $MANILA_CONF $driver_group share_driver) + GENERIC_DRIVER='manila.share.drivers.generic.GenericShareDriver' + DHSS=$(iniget $MANILA_CONF $driver_group driver_handles_share_servers) + if [[ $SHARE_DRIVER == $GENERIC_DRIVER && $(trueorfalse False DHSS) == False ]]; then + # Wait for availability + source /opt/stack/new/devstack/openrc admin demo + vm_id=$(iniget $MANILA_CONF $driver_group service_instance_name_or_id) + vm_ips=$(nova show $vm_id | grep "private network") + attempts=0 + for vm_ip in ${vm_ips//,/ }; do + # Get IPv4 address + if [[ $vm_ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + # Check availability + ((attempts++)) + manila_check_service_vm_availability $vm_ip + break + fi + done + if [[ (( attempts < 1 )) ]]; then + echo "No IPv4 addresses found among private IPs of '$vm_id' for '$GENERIC_DRIVER'. "\ + "Reported IPs: '$vm_ips'." + exit 1 + fi + fi + done +} + +function manila_wait_for_drivers_init { + # First argument is expected to be file path to Manila config + + manila_wait_for_generic_driver_init $1 +} diff --git a/contrib/ci/post_test_hook.sh b/contrib/ci/post_test_hook.sh index d6a2794f5a..2f12057205 100755 --- a/contrib/ci/post_test_hook.sh +++ b/contrib/ci/post_test_hook.sh @@ -51,10 +51,11 @@ iniset $BASE/new/tempest/etc/tempest.conf share run_consistency_group_tests $RUN RUN_MANILA_MANAGE_TESTS=${RUN_MANILA_MANAGE_TESTS:-True} iniset $BASE/new/tempest/etc/tempest.conf share run_manage_unmanage_tests $RUN_MANILA_MANAGE_TESTS +MANILA_CONF=${MANILA_CONF:-/etc/manila/manila.conf} + if [[ -z "$MULTITENANCY_ENABLED" ]]; then # Define whether share drivers handle share servers or not. # Requires defined config option 'driver_handles_share_servers'. - MANILA_CONF=${MANILA_CONF:-/etc/manila/manila.conf} NO_SHARE_SERVER_HANDLING_MODES=0 WITH_SHARE_SERVER_HANDLING_MODES=0 @@ -108,56 +109,10 @@ elif [[ "$JOB_NAME" =~ "no-share-servers" ]]; then MANILA_TEMPEST_CONCURRENCY=8 fi -function check_service_vm_availability { - wait_step=10 - wait_timeout=300 - available='false' - while (( wait_timeout > 0 )) ; do - if [[ "$(ping -w 1 $1)" =~ "1 received" ]]; then - available='true' - break - fi - ((wait_timeout-=$wait_step)) - sleep $wait_step - done - - if [[ $available == 'true' ]]; then - echo "SUCCESS! Service VM $1 is available." - else - echo "FAILURE! Service VM $1 is not available." - exit 1 - fi -} - # Also, we should wait until service VM is available # before running Tempest tests using Generic driver in DHSS=False mode. -DRIVER_GROUPS=$(iniget $MANILA_CONF DEFAULT enabled_share_backends) -for driver_group in ${DRIVER_GROUPS//,/ }; do - SHARE_DRIVER=$(iniget $MANILA_CONF $driver_group share_driver) - GENERIC_DRIVER='manila.share.drivers.generic.GenericShareDriver' - DHSS=$(iniget $MANILA_CONF $driver_group driver_handles_share_servers) - if [[ $SHARE_DRIVER == $GENERIC_DRIVER && $(trueorfalse False DHSS) == False ]]; then - # Wait for availability - source /opt/stack/new/devstack/openrc admin demo - vm_id=$(iniget $MANILA_CONF $driver_group service_instance_name_or_id) - vm_ips=$(nova show $vm_id | grep "private network") - attempts=0 - for vm_ip in ${vm_ips//,/ }; do - # Get IPv4 address - if [[ $vm_ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then - # Check availability - ((attempts++)) - check_service_vm_availability $vm_ip - break - fi - done - if [[ (( attempts < 1 )) ]]; then - echo "No IPv4 addresses found among private IPs of '$vm_id' for '$GENERIC_DRIVER'. "\ - "Reported IPs: '$vm_ips'." - exit 1 - fi - fi -done +source $BASE/new/manila/contrib/ci/common.sh +manila_wait_for_drivers_init $MANILA_CONF # check if tempest plugin was installed correctly echo 'import pkg_resources; print list(pkg_resources.iter_entry_points("tempest.test_plugins"))' | python diff --git a/contrib/ci/pre_test_hook.sh b/contrib/ci/pre_test_hook.sh index 43b4f8979e..7679a431ff 100755 --- a/contrib/ci/pre_test_hook.sh +++ b/contrib/ci/pre_test_hook.sh @@ -59,9 +59,9 @@ echo 'ENABLE_ISOLATED_METADATA=True' >> $localrc_path # Go to Tempest dir and checkout stable commit to avoid possible # incompatibilities for plugin stored in Manila repo. -TEMPEST_COMMIT="c43c8f91" # 05 Nov, 2015 cd $BASE/new/tempest -git checkout $TEMPEST_COMMIT +source $BASE/new/manila/contrib/ci/common.sh +git checkout $MANILA_TEMPEST_COMMIT # Print current Tempest status git status