With the advent of plugins and their settings files it has become
possible to disable_service in local.conf only to have the service
re-enabled in a plugin settings file. This happens because of
processing order.
To get around this the disable_service function now aggregates
service names into a DISABLED_SERVICES variable which is then checked
during enable_service. If something tries to enable something that
was previously disabled, a warning is produced in the log and the
service is not enabled.
Then after all configuration has been sourced a final check is to
done by verify_disabled_services to confirm that something has not
manually adjusted ENABLED_SERVICES to overcome a previously called
disable_service. If something has, the stack dies with an error.
Change-Id: I0f9403f44ed2fe693a46cd02486bd94043ce6b1a
Closes-Bug: #1504304
... | ... |
@@ -1729,6 +1729,7 @@ function run_phase { |
1729 | 1729 |
# the source phase corresponds to settings loading in plugins |
1730 | 1730 |
if [[ "$mode" == "source" ]]; then |
1731 | 1731 |
load_plugin_settings |
1732 |
+ verify_disabled_services |
|
1732 | 1733 |
elif [[ "$mode" == "override_defaults" ]]; then |
1733 | 1734 |
plugin_override_defaults |
1734 | 1735 |
else |
... | ... |
@@ -1784,25 +1785,26 @@ function disable_negated_services { |
1784 | 1784 |
ENABLED_SERVICES=$(remove_disabled_services "$remaining" "$to_remove") |
1785 | 1785 |
} |
1786 | 1786 |
|
1787 |
-# disable_service() removes the services passed as argument to the |
|
1788 |
-# ``ENABLED_SERVICES`` list, if they are present. |
|
1787 |
+# disable_service() prepares the services passed as argument to be |
|
1788 |
+# removed from the ``ENABLED_SERVICES`` list, if they are present. |
|
1789 | 1789 |
# |
1790 | 1790 |
# For example: |
1791 | 1791 |
# disable_service rabbit |
1792 | 1792 |
# |
1793 |
-# This function does not know about the special cases |
|
1794 |
-# for nova, glance, and neutron built into is_service_enabled(). |
|
1795 |
-# Uses global ``ENABLED_SERVICES`` |
|
1793 |
+# Uses global ``DISABLED_SERVICES`` |
|
1796 | 1794 |
# disable_service service [service ...] |
1797 | 1795 |
function disable_service { |
1798 |
- local tmpsvcs=",${ENABLED_SERVICES}," |
|
1796 |
+ local disabled_svcs="${DISABLED_SERVICES}" |
|
1797 |
+ local enabled_svcs=",${ENABLED_SERVICES}," |
|
1799 | 1798 |
local service |
1800 | 1799 |
for service in $@; do |
1800 |
+ disabled_svcs+=",$service" |
|
1801 | 1801 |
if is_service_enabled $service; then |
1802 |
- tmpsvcs=${tmpsvcs//,$service,/,} |
|
1802 |
+ enabled_svcs=${enabled_svcs//,$service,/,} |
|
1803 | 1803 |
fi |
1804 | 1804 |
done |
1805 |
- ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") |
|
1805 |
+ DISABLED_SERVICES=$(_cleanup_service_list "$disabled_svcs") |
|
1806 |
+ ENABLED_SERVICES=$(_cleanup_service_list "$enabled_svcs") |
|
1806 | 1807 |
} |
1807 | 1808 |
|
1808 | 1809 |
# enable_service() adds the services passed as argument to the |
... | ... |
@@ -1819,6 +1821,10 @@ function enable_service { |
1819 | 1819 |
local tmpsvcs="${ENABLED_SERVICES}" |
1820 | 1820 |
local service |
1821 | 1821 |
for service in $@; do |
1822 |
+ if [[ ,${DISABLED_SERVICES}, =~ ,${service}, ]]; then |
|
1823 |
+ warn $LINENO "Attempt to enable_service ${service} when it has been disabled" |
|
1824 |
+ continue |
|
1825 |
+ fi |
|
1822 | 1826 |
if ! is_service_enabled $service; then |
1823 | 1827 |
tmpsvcs+=",$service" |
1824 | 1828 |
fi |
... | ... |
@@ -1923,6 +1929,18 @@ function use_exclusive_service { |
1923 | 1923 |
return 0 |
1924 | 1924 |
} |
1925 | 1925 |
|
1926 |
+# Make sure that nothing has manipulated ENABLED_SERVICES in a way |
|
1927 |
+# that conflicts with prior calls to disable_service. |
|
1928 |
+# Uses global ``ENABLED_SERVICES`` |
|
1929 |
+function verify_disabled_services { |
|
1930 |
+ local service |
|
1931 |
+ for service in ${ENABLED_SERVICES//,/ }; do |
|
1932 |
+ if [[ ,${DISABLED_SERVICES}, =~ ,${service}, ]]; then |
|
1933 |
+ die $LINENO "ENABLED_SERVICES directly modified to overcome 'disable_service ${service}'" |
|
1934 |
+ fi |
|
1935 |
+ done |
|
1936 |
+} |
|
1937 |
+ |
|
1926 | 1938 |
|
1927 | 1939 |
# System Functions |
1928 | 1940 |
# ================ |