From 8606c98c53722f425525fa06eee554b7d30f62f6 Mon Sep 17 00:00:00 2001 From: fumihiko kakuma Date: Mon, 13 Apr 2015 09:55:06 +0900 Subject: [PATCH] Fix remove_disabled_extensions to remove an extension at the last position remove_disabled_extensions do matching by '$ext_to_remove","'. So it doesn't match an extension at the last position in extensions_list. This patch fixes that. Closes-Bug: #1443254 Change-Id: I194b483de797697ba06b320cf33f1bac67fc0cc7 --- functions-common | 41 +++++++++++++++++++++++++---------------- lib/tempest | 5 +---- tests/test_functions.sh | 25 +++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/functions-common b/functions-common index 52d80fb95b..ff9261161c 100644 --- a/functions-common +++ b/functions-common @@ -1629,7 +1629,6 @@ function disable_all_services { function disable_negated_services { local to_remove="" local remaining="" - local enabled="" local service # build up list of services that should be removed; i.e. they @@ -1644,21 +1643,7 @@ function disable_negated_services { # go through the service list. if this service appears in the "to # be removed" list, drop it - for service in ${remaining//,/ }; do - local remove - local add=1 - for remove in ${to_remove//,/ }; do - if [[ ${remove} == ${service} ]]; then - add=0 - break - fi - done - if [[ $add == 1 ]]; then - enabled="${enabled},$service" - fi - done - - ENABLED_SERVICES=$(_cleanup_service_list "$enabled") + ENABLED_SERVICES=$(remove_disabled_services "$remaining" "$to_remove") } # disable_service() removes the services passed as argument to the @@ -1762,6 +1747,30 @@ function is_service_enabled { return $enabled } +# remove specified list from the input string +# remove_disabled_services service-list remove-list +function remove_disabled_services { + local service_list=$1 + local remove_list=$2 + local service + local enabled="" + + for service in ${service_list//,/ }; do + local remove + local add=1 + for remove in ${remove_list//,/ }; do + if [[ ${remove} == ${service} ]]; then + add=0 + break + fi + done + if [[ $add == 1 ]]; then + enabled="${enabled},$service" + fi + done + _cleanup_service_list "$enabled" +} + # Toggle enable/disable_service for services that must run exclusive of each other # $1 The name of a variable containing a space-separated list of services # $2 The name of a variable in which to store the enabled service's name diff --git a/lib/tempest b/lib/tempest index 6c34323802..ffb59ff59b 100644 --- a/lib/tempest +++ b/lib/tempest @@ -91,10 +91,7 @@ function remove_disabled_extensions { local extensions_list=$1 shift local disabled_exts=$* - for ext_to_remove in ${disabled_exts//,/ } ; do - extensions_list=${extensions_list/$ext_to_remove","} - done - echo $extensions_list + remove_disabled_services "$extensions_list" "$disabled_exts" } # configure_tempest() - Set config files, create data dirs, etc diff --git a/tests/test_functions.sh b/tests/test_functions.sh index 1d82792ca7..f555de8dff 100755 --- a/tests/test_functions.sh +++ b/tests/test_functions.sh @@ -137,6 +137,31 @@ test_disable_negated_services 'a,aa,-a' 'aa' test_disable_negated_services 'a,av2,-a,a' 'av2' test_disable_negated_services 'a,-a,av2' 'av2' +echo "Testing remove_disabled_services()" + +function test_remove_disabled_services { + local service_list="$1" + local remove_list="$2" + local expected="$3" + + results=$(remove_disabled_services "$service_list" "$remove_list") + if [ "$results" = "$expected" ]; then + passed "OK: '$service_list' - '$remove_list' -> '$results'" + else + failed "getting '$expected' from '$service_list' - '$remove_list' failed: '$results'" + fi +} + +test_remove_disabled_services 'a,b,c' 'a,c' 'b' +test_remove_disabled_services 'a,b,c' 'b' 'a,c' +test_remove_disabled_services 'a,b,c,d' 'a,c d' 'b' +test_remove_disabled_services 'a,b c,d' 'a d' 'b,c' +test_remove_disabled_services 'a,b,c' 'a,b,c' '' +test_remove_disabled_services 'a,b,c' 'd' 'a,b,c' +test_remove_disabled_services 'a,b,c' '' 'a,b,c' +test_remove_disabled_services '' 'a,b,c' '' +test_remove_disabled_services '' '' '' + echo "Testing is_package_installed()" if [[ -z "$os_PACKAGE" ]]; then