Browse code

Merge "Perform additional disable_service checks" into stable/liberty

Jenkins authored on 2016/06/15 10:08:36
Showing 2 changed files
... ...
@@ -1772,6 +1772,7 @@ function run_phase {
1772 1772
     # the source phase corresponds to settings loading in plugins
1773 1773
     if [[ "$mode" == "source" ]]; then
1774 1774
         load_plugin_settings
1775
+        verify_disabled_services
1775 1776
     elif [[ "$mode" == "override_defaults" ]]; then
1776 1777
         plugin_override_defaults
1777 1778
     else
... ...
@@ -1827,25 +1828,26 @@ function disable_negated_services {
1827 1827
     ENABLED_SERVICES=$(remove_disabled_services "$remaining" "$to_remove")
1828 1828
 }
1829 1829
 
1830
-# disable_service() removes the services passed as argument to the
1831
-# ``ENABLED_SERVICES`` list, if they are present.
1830
+# disable_service() prepares the services passed as argument to be
1831
+# removed from the ``ENABLED_SERVICES`` list, if they are present.
1832 1832
 #
1833 1833
 # For example:
1834 1834
 #   disable_service rabbit
1835 1835
 #
1836
-# This function does not know about the special cases
1837
-# for nova, glance, and neutron built into is_service_enabled().
1838
-# Uses global ``ENABLED_SERVICES``
1836
+# Uses global ``DISABLED_SERVICES``
1839 1837
 # disable_service service [service ...]
1840 1838
 function disable_service {
1841
-    local tmpsvcs=",${ENABLED_SERVICES},"
1839
+    local disabled_svcs="${DISABLED_SERVICES}"
1840
+    local enabled_svcs=",${ENABLED_SERVICES},"
1842 1841
     local service
1843 1842
     for service in $@; do
1843
+        disabled_svcs+=",$service"
1844 1844
         if is_service_enabled $service; then
1845
-            tmpsvcs=${tmpsvcs//,$service,/,}
1845
+            enabled_svcs=${enabled_svcs//,$service,/,}
1846 1846
         fi
1847 1847
     done
1848
-    ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
1848
+    DISABLED_SERVICES=$(_cleanup_service_list "$disabled_svcs")
1849
+    ENABLED_SERVICES=$(_cleanup_service_list "$enabled_svcs")
1849 1850
 }
1850 1851
 
1851 1852
 # enable_service() adds the services passed as argument to the
... ...
@@ -1862,6 +1864,10 @@ function enable_service {
1862 1862
     local tmpsvcs="${ENABLED_SERVICES}"
1863 1863
     local service
1864 1864
     for service in $@; do
1865
+        if [[ ,${DISABLED_SERVICES}, =~ ,${service}, ]]; then
1866
+            warn $LINENO "Attempt to enable_service ${service} when it has been disabled"
1867
+            continue
1868
+        fi
1865 1869
         if ! is_service_enabled $service; then
1866 1870
             tmpsvcs+=",$service"
1867 1871
         fi
... ...
@@ -1965,6 +1971,18 @@ function use_exclusive_service {
1965 1965
     return 0
1966 1966
 }
1967 1967
 
1968
+# Make sure that nothing has manipulated ENABLED_SERVICES in a way
1969
+# that conflicts with prior calls to disable_service.
1970
+# Uses global ``ENABLED_SERVICES``
1971
+function verify_disabled_services {
1972
+    local service
1973
+    for service in ${ENABLED_SERVICES//,/ }; do
1974
+        if [[ ,${DISABLED_SERVICES}, =~ ,${service}, ]]; then
1975
+            die $LINENO "ENABLED_SERVICES directly modified to overcome 'disable_service ${service}'"
1976
+        fi
1977
+    done
1978
+}
1979
+
1968 1980
 
1969 1981
 # System Functions
1970 1982
 # ================
... ...
@@ -543,6 +543,7 @@ source $TOP_DIR/lib/dstat
543 543
 # Phase: source
544 544
 run_phase source
545 545
 
546
+
546 547
 # Interactive Configuration
547 548
 # -------------------------
548 549