1- from typing import (
2- Iterable ,
3- List ,
4- Mapping ,
5- )
1+ from typing import Mapping
62
73from lxml .etree import _Element
84
95from pcs .common import reports
106from pcs .common .services .interfaces import ServiceManagerInterface
117from pcs .common .tools import timeout_to_seconds
128from pcs .common .types import StringSequence
13- from pcs .lib import (
14- sbd ,
15- validate ,
16- )
9+ from pcs .lib import sbd , validate
1710from pcs .lib .cib import nvpair_multi
1811from pcs .lib .cib .tools import (
1912 IdProvider ,
2316from pcs .lib .errors import LibraryError
2417from pcs .lib .external import CommandRunner
2518from pcs .lib .pacemaker .values import is_false
26- from pcs .lib .resource_agent import ResourceAgentParameter
19+ from pcs .lib .resource_agent import ResourceAgentFacade
2720
2821READONLY_CLUSTER_PROPERTY_LIST = [
2922 "cluster-infrastructure" ,
3326 "last-lrm-refresh" ,
3427]
3528_DEFAULT_CLUSTER_PROPERTY_SET_ID = "cib-bootstrap-options"
29+ _STONITH_WATCHDOG_TIMEOUT_PROPERTIES = [
30+ "stonith-watchdog-timeout" ,
31+ "fencing-watchdog-timeout" ,
32+ ]
3633
3734
3835def _validate_stonith_watchdog_timeout_property (
@@ -69,7 +66,7 @@ def _validate_stonith_watchdog_timeout_property(
6966
7067def _validate_not_disabling_fencing (
7168 to_be_set_properties : Mapping [str , str ],
72- ) -> List [ reports .ReportItem ] :
69+ ) -> reports .ReportItemList :
7370 problematic_properties_setting = {
7471 key : to_be_set_properties [key ]
7572 for key in ["stonith-enabled" , "fencing-enabled" ]
@@ -90,7 +87,7 @@ def _validate_not_disabling_fencing(
9087
9188def validate_set_cluster_properties ( # noqa: PLR0912
9289 runner : CommandRunner ,
93- params_spec : Iterable [ ResourceAgentParameter ] ,
90+ cluster_properties_facade : ResourceAgentFacade ,
9491 properties_set_id : str ,
9592 configured_properties : StringSequence ,
9693 new_properties : Mapping [str , str ],
@@ -100,7 +97,7 @@ def validate_set_cluster_properties( # noqa: PLR0912
10097 """
10198 Validate that cluster properties and their values can be set.
10299
103- params_spec -- params specified by agent "cluster-options"
100+ cluster_properties_facade -- facade for cluster properties metadata
104101 properties_set_id -- id of the properties set to be updated
105102 configured_properties -- names of currently configured cluster properties
106103 new_properties -- dictionary of properties and their values to be set
@@ -111,7 +108,7 @@ def validate_set_cluster_properties( # noqa: PLR0912
111108 # pylint: disable=too-many-locals
112109 possible_properties_dict = {
113110 parameter .name : parameter
114- for parameter in params_spec
111+ for parameter in cluster_properties_facade . metadata . parameters
115112 if parameter .name not in READONLY_CLUSTER_PROPERTY_LIST
116113 }
117114 severity = reports .get_severity (reports .codes .FORCE , force )
@@ -124,33 +121,37 @@ def validate_set_cluster_properties( # noqa: PLR0912
124121 else :
125122 to_be_removed_properties .append (name )
126123
127- report_list = validate .validate_set_unset_items (
128- to_be_set_properties .keys (),
129- to_be_removed_properties ,
130- configured_properties ,
131- reports .const .ADD_REMOVE_CONTAINER_TYPE_PROPERTY_SET ,
132- reports .const .ADD_REMOVE_ITEM_TYPE_PROPERTY ,
133- properties_set_id ,
134- severity = severity ,
135- )
124+ report_list = []
136125
137126 report_list .extend (
138- validate .NamesIn (
139- possible_properties_dict .keys (),
140- option_type = "cluster property" ,
141- banned_name_list = READONLY_CLUSTER_PROPERTY_LIST ,
127+ validate .ValidatorAll (
128+ cluster_properties_facade .get_validators_deprecated_parameters ()
129+ ).validate (new_properties )
130+ )
131+ report_list .extend (
132+ validate .validate_set_unset_items (
133+ to_be_set_properties .keys (),
134+ to_be_removed_properties ,
135+ configured_properties ,
136+ reports .const .ADD_REMOVE_CONTAINER_TYPE_PROPERTY_SET ,
137+ reports .const .ADD_REMOVE_ITEM_TYPE_PROPERTY ,
138+ properties_set_id ,
142139 severity = severity ,
140+ )
141+ )
142+ report_list .extend (
143+ validate .ValidatorAll (
144+ cluster_properties_facade .get_validators_allowed_parameters (
145+ force = force ,
146+ banned_parameter_list = READONLY_CLUSTER_PROPERTY_LIST ,
147+ )
143148 ).validate (
144149 # Allow removing properties unknown to pacemaker while preventing
145150 # setting them. Prevent removing read-only properties.
146151 {
147152 name : value
148153 for name , value in new_properties .items ()
149- if not (
150- value == ""
151- and name not in READONLY_CLUSTER_PROPERTY_LIST
152- and name not in possible_properties_dict
153- )
154+ if value != "" or name in READONLY_CLUSTER_PROPERTY_LIST
154155 }
155156 )
156157 )
@@ -213,7 +214,7 @@ def validate_set_cluster_properties( # noqa: PLR0912
213214 )
214215 elif property_metadata .type in ["time" , "timeout" ]:
215216 # make stonith-watchdog-timeout value not forcable
216- if property_metadata .name == "stonith-watchdog-timeout" :
217+ if property_metadata .name in _STONITH_WATCHDOG_TIMEOUT_PROPERTIES :
217218 validators .append (
218219 validate .ValueTimeInterval (
219220 property_metadata .name ,
@@ -239,17 +240,17 @@ def validate_set_cluster_properties( # noqa: PLR0912
239240
240241 # Only validate SWT if it is being set, or if it is being removed and it
241242 # actually exists in the current configuration.
242- if "stonith-watchdog-timeout" in new_properties and (
243- new_properties ["stonith-watchdog-timeout" ]
244- or "stonith-watchdog-timeout" in configured_properties
245- ):
246- report_list .extend (
247- _validate_stonith_watchdog_timeout_property (
248- service_manager ,
249- new_properties ["stonith-watchdog-timeout" ],
250- force = force ,
243+ for prop_name in _STONITH_WATCHDOG_TIMEOUT_PROPERTIES :
244+ if prop_name in new_properties and (
245+ new_properties [prop_name ] or prop_name in configured_properties
246+ ):
247+ report_list .extend (
248+ _validate_stonith_watchdog_timeout_property (
249+ service_manager ,
250+ new_properties [prop_name ],
251+ force = force ,
252+ )
251253 )
252- )
253254
254255 report_list .extend (_validate_not_disabling_fencing (to_be_set_properties ))
255256
0 commit comments