|
9 | 9 | import time |
10 | 10 | import json |
11 | 11 | import re |
| 12 | +import sys |
12 | 13 | from typing import Optional, Dict, Any, List, Type |
13 | 14 | from datetime import datetime |
14 | 15 | from concurrent.futures import ThreadPoolExecutor |
@@ -91,6 +92,7 @@ def _init_validator_registry(self) -> Dict[str, Any]: |
91 | 92 | "string": self.validate_string, |
92 | 93 | "range": self.validate_numeric_range, |
93 | 94 | "list": self.validate_list, |
| 95 | + "min_list": self.validate_min_list, |
94 | 96 | "check_support": self.validate_vm_support, |
95 | 97 | "properties": self.validate_properties, |
96 | 98 | } |
@@ -497,6 +499,58 @@ def validate_list(self, check: Check, collected_data: str) -> Dict[str, Any]: |
497 | 499 | ), |
498 | 500 | } |
499 | 501 |
|
| 502 | + def validate_min_list(self, check: Check, collected_data: str) -> Dict[str, Any]: |
| 503 | + """ |
| 504 | + Validate that each value in a space-separated list meets or exceeds minimum values. |
| 505 | + Used for kernel parameters like kernel.sem where actual values must be >= minimum required. |
| 506 | +
|
| 507 | + :param check: Check definition containing min_values and separator in validator_args |
| 508 | + :type check: Check |
| 509 | + :param collected_data: Space-separated string of values from system |
| 510 | + :type collected_data: str |
| 511 | + :return: Validation result dictionary |
| 512 | + :rtype: Dict[str, Any] |
| 513 | + """ |
| 514 | + min_values = check.validator_args.get("min_values", []) |
| 515 | + separator = check.validator_args.get("separator", " ") |
| 516 | + try: |
| 517 | + |
| 518 | + if not isinstance(min_values, list): |
| 519 | + return { |
| 520 | + "status": TestStatus.ERROR.value, |
| 521 | + } |
| 522 | + |
| 523 | + collected_values = ( |
| 524 | + str(collected_data).strip().split(separator) if collected_data else [] |
| 525 | + ) |
| 526 | + collected_values = [val.strip() for val in collected_values if val.strip()] |
| 527 | + if len(collected_values) != len(min_values): |
| 528 | + return { |
| 529 | + "status": self._create_validation_result(check.severity, False), |
| 530 | + } |
| 531 | + all_valid = True |
| 532 | + for actual, minimum in zip(collected_values, min_values): |
| 533 | + try: |
| 534 | + actual_int = int(actual) |
| 535 | + minimum_int = int(minimum) |
| 536 | + if actual_int > sys.maxsize or minimum_int > sys.maxsize: |
| 537 | + continue |
| 538 | + if actual_int < minimum_int: |
| 539 | + all_valid = False |
| 540 | + break |
| 541 | + except (ValueError, OverflowError): |
| 542 | + all_valid = False |
| 543 | + break |
| 544 | + |
| 545 | + return { |
| 546 | + "status": self._create_validation_result(check.severity, all_valid), |
| 547 | + } |
| 548 | + except Exception as ex: |
| 549 | + self.log(logging.ERROR, f"Error while validating min list {ex}") |
| 550 | + return { |
| 551 | + "status": TestStatus.ERROR.value, |
| 552 | + } |
| 553 | + |
500 | 554 | def validate_vm_support(self, check: Check, collected_data: str) -> Dict[str, Any]: |
501 | 555 | """ |
502 | 556 | Validates if a VM SKU is supported for the given role and database type |
@@ -609,6 +663,11 @@ def create_result( |
609 | 663 | valid_list = check.validator_args.get("valid_list", []) |
610 | 664 | if isinstance(valid_list, list) and valid_list: |
611 | 665 | expected_value = ", ".join(str(v) for v in valid_list) |
| 666 | + elif check.validator_type == "min_list": |
| 667 | + min_values = check.validator_args.get("min_values", []) |
| 668 | + separator = check.validator_args.get("separator", " ") |
| 669 | + if isinstance(min_values, list) and min_values: |
| 670 | + expected_value = f"Min: {separator.join(str(v) for v in min_values)}" |
612 | 671 | elif check.validator_type == "properties": |
613 | 672 | props = check.validator_args.get("properties", []) |
614 | 673 | if isinstance(props, list) and props: |
@@ -875,7 +934,7 @@ def run(self): |
875 | 934 | context["hostname"] = custom_hostname |
876 | 935 |
|
877 | 936 | self.set_context(context) |
878 | | - if self.context.get("check_type", {}).get("file_name") == "hana": |
| 937 | + if self.context.get("check_type", {}).get("file_name") in ["hana", "db2"]: |
879 | 938 | temp_context = FileSystemCollector(parent=self).collect( |
880 | 939 | check=None, context=self.context |
881 | 940 | ) |
|
0 commit comments