Skip to content

Commit af35d6f

Browse files
committed
Refactor missing required parameter handling in HA cluster validator to improve logging and message clarity
1 parent 1383334 commit af35d6f

File tree

1 file changed

+43
-16
lines changed

1 file changed

+43
-16
lines changed

src/module_utils/get_pcmk_properties.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,15 @@ def _create_parameter(
190190
expected_config = (expected_value, False)
191191

192192
status = self._determine_parameter_status(value, expected_config)
193-
if status == TestStatus.WARNING.value and (not value or value == ""):
194-
is_required = False
195-
if isinstance(expected_config, tuple) and len(expected_config) == 2:
196-
is_required = expected_config[1]
197-
elif isinstance(expected_config, dict):
198-
is_required = expected_config.get("required", False)
199-
200-
if is_required:
201-
param_display_name = f"{op_name}_{name}" if op_name else name
202-
category_display = f"{category}_{subcategory}" if subcategory else category
203-
warning_msg = (
204-
f"Required parameter '{param_display_name}' in category '{category_display}' "
205-
+ "has no value configured.\n"
206-
)
207-
self.result["message"] += warning_msg
208-
self.log(logging.WARNING, warning_msg)
193+
194+
if status == TestStatus.WARNING.value and not value:
195+
self._handle_missing_required_parameter(
196+
expected_config=expected_config,
197+
name=name,
198+
category=category,
199+
subcategory=subcategory,
200+
op_name=op_name,
201+
)
209202

210203
display_expected_value = None
211204
if expected_config is None:
@@ -306,6 +299,40 @@ def _determine_parameter_status(self, value, expected_config):
306299
else TestStatus.ERROR.value
307300
)
308301

302+
def _handle_missing_required_parameter(
303+
self, expected_config, name, category, subcategory=None, op_name=None
304+
):
305+
"""
306+
Handle warnings for missing required parameters.
307+
Logs warning message and updates result when a required parameter has no value.
308+
309+
:param expected_config: The expected configuration (tuple or dict)
310+
:type expected_config: tuple or dict
311+
:param name: The parameter name
312+
:type name: str
313+
:param category: The parameter category
314+
:type category: str
315+
:param subcategory: The parameter subcategory, defaults to None
316+
:type subcategory: str, optional
317+
:param op_name: The operation name (if applicable), defaults to None
318+
:type op_name: str, optional
319+
"""
320+
is_required = False
321+
if isinstance(expected_config, tuple) and len(expected_config) == 2:
322+
is_required = expected_config[1]
323+
elif isinstance(expected_config, dict):
324+
is_required = expected_config.get("required", False)
325+
326+
if is_required:
327+
param_display_name = f"{op_name}_{name}" if op_name else name
328+
category_display = f"{category}_{subcategory}" if subcategory else category
329+
warning_msg = (
330+
f"Required parameter '{param_display_name}' in category '{category_display}' "
331+
+ "has no value configured.\n"
332+
)
333+
self.result["message"] += warning_msg
334+
self.log(logging.WARNING, warning_msg)
335+
309336
def _parse_nvpair_elements(self, elements, category, subcategory=None, op_name=None):
310337
"""
311338
Parse nvpair elements and create parameter dictionaries.

0 commit comments

Comments
 (0)