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
(cherry picked from commit c6d470142e0a0359a7322e9b76d61ba15caf95bc)
| ... | ... |
@@ -1740,6 +1740,7 @@ function run_phase {
|
| 1740 | 1740 |
# the source phase corresponds to settings loading in plugins |
| 1741 | 1741 |
if [[ "$mode" == "source" ]]; then |
| 1742 | 1742 |
load_plugin_settings |
| 1743 |
+ verify_disabled_services |
|
| 1743 | 1744 |
elif [[ "$mode" == "override_defaults" ]]; then |
| 1744 | 1745 |
plugin_override_defaults |
| 1745 | 1746 |
else |
| ... | ... |
@@ -1795,25 +1796,26 @@ function disable_negated_services {
|
| 1795 | 1795 |
ENABLED_SERVICES=$(remove_disabled_services "$remaining" "$to_remove") |
| 1796 | 1796 |
} |
| 1797 | 1797 |
|
| 1798 |
-# disable_service() removes the services passed as argument to the |
|
| 1799 |
-# ``ENABLED_SERVICES`` list, if they are present. |
|
| 1798 |
+# disable_service() prepares the services passed as argument to be |
|
| 1799 |
+# removed from the ``ENABLED_SERVICES`` list, if they are present. |
|
| 1800 | 1800 |
# |
| 1801 | 1801 |
# For example: |
| 1802 | 1802 |
# disable_service rabbit |
| 1803 | 1803 |
# |
| 1804 |
-# This function does not know about the special cases |
|
| 1805 |
-# for nova, glance, and neutron built into is_service_enabled(). |
|
| 1806 |
-# Uses global ``ENABLED_SERVICES`` |
|
| 1804 |
+# Uses global ``DISABLED_SERVICES`` |
|
| 1807 | 1805 |
# disable_service service [service ...] |
| 1808 | 1806 |
function disable_service {
|
| 1809 |
- local tmpsvcs=",${ENABLED_SERVICES},"
|
|
| 1807 |
+ local disabled_svcs="${DISABLED_SERVICES}"
|
|
| 1808 |
+ local enabled_svcs=",${ENABLED_SERVICES},"
|
|
| 1810 | 1809 |
local service |
| 1811 | 1810 |
for service in $@; do |
| 1811 |
+ disabled_svcs+=",$service" |
|
| 1812 | 1812 |
if is_service_enabled $service; then |
| 1813 |
- tmpsvcs=${tmpsvcs//,$service,/,}
|
|
| 1813 |
+ enabled_svcs=${enabled_svcs//,$service,/,}
|
|
| 1814 | 1814 |
fi |
| 1815 | 1815 |
done |
| 1816 |
- ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") |
|
| 1816 |
+ DISABLED_SERVICES=$(_cleanup_service_list "$disabled_svcs") |
|
| 1817 |
+ ENABLED_SERVICES=$(_cleanup_service_list "$enabled_svcs") |
|
| 1817 | 1818 |
} |
| 1818 | 1819 |
|
| 1819 | 1820 |
# enable_service() adds the services passed as argument to the |
| ... | ... |
@@ -1830,6 +1832,10 @@ function enable_service {
|
| 1830 | 1830 |
local tmpsvcs="${ENABLED_SERVICES}"
|
| 1831 | 1831 |
local service |
| 1832 | 1832 |
for service in $@; do |
| 1833 |
+ if [[ ,${DISABLED_SERVICES}, =~ ,${service}, ]]; then
|
|
| 1834 |
+ warn $LINENO "Attempt to enable_service ${service} when it has been disabled"
|
|
| 1835 |
+ continue |
|
| 1836 |
+ fi |
|
| 1833 | 1837 |
if ! is_service_enabled $service; then |
| 1834 | 1838 |
tmpsvcs+=",$service" |
| 1835 | 1839 |
fi |
| ... | ... |
@@ -1933,6 +1939,18 @@ function use_exclusive_service {
|
| 1933 | 1933 |
return 0 |
| 1934 | 1934 |
} |
| 1935 | 1935 |
|
| 1936 |
+# Make sure that nothing has manipulated ENABLED_SERVICES in a way |
|
| 1937 |
+# that conflicts with prior calls to disable_service. |
|
| 1938 |
+# Uses global ``ENABLED_SERVICES`` |
|
| 1939 |
+function verify_disabled_services {
|
|
| 1940 |
+ local service |
|
| 1941 |
+ for service in ${ENABLED_SERVICES//,/ }; do
|
|
| 1942 |
+ if [[ ,${DISABLED_SERVICES}, =~ ,${service}, ]]; then
|
|
| 1943 |
+ die $LINENO "ENABLED_SERVICES directly modified to overcome 'disable_service ${service}'"
|
|
| 1944 |
+ fi |
|
| 1945 |
+ done |
|
| 1946 |
+} |
|
| 1947 |
+ |
|
| 1936 | 1948 |
|
| 1937 | 1949 |
# System Functions |
| 1938 | 1950 |
# ================ |