Merge "Fix remove_disabled_extensions to remove an extension at the last position"

This commit is contained in:
Jenkins 2015-05-26 12:35:49 +00:00 committed by Gerrit Code Review
commit 7b71d376f9
3 changed files with 51 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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