Skip to content

Commit 226686b

Browse files
committed
feat: add match_mode options for string validation and enhance test coverage
1 parent a9bc910 commit 226686b

9 files changed

Lines changed: 76 additions & 18 deletions

File tree

scripts/sap_automation_qa.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Available Test Cases for groups:
7575
azure-lb => Azure Load Balancer
7676
sapcontrol-config => SAP Control Configuration
7777
ascs-migration => ASCS Migration
78+
ascs-node-crash => ASCS Node Crash
7879
block-network => Block Network
7980
kill-message-server => Kill Message Server
8081
kill-enqueue-server => Kill Enqueue Server

src/modules/configuration_check_module.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,16 @@ def validate_string(self, check: Check, collected_data: str) -> Dict[str, Any]:
447447
expected = expected.lower()
448448
collected = collected.lower()
449449

450+
match_mode = check.validator_args.get("match_mode", "exact")
451+
if match_mode == "contains":
452+
is_valid = expected in collected
453+
elif match_mode == "not_contains":
454+
is_valid = expected not in collected
455+
else:
456+
is_valid = collected == expected
457+
450458
return {
451-
"status": self._create_validation_result(check.severity, collected == expected),
459+
"status": self._create_validation_result(check.severity, is_valid),
452460
}
453461

454462
def validate_numeric_range(self, check: Check, collected_data: str) -> Dict[str, Any]:

src/roles/configuration_checks/tasks/files/hana.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ checks:
831831
high_availability_agent: [*fencing_agent]
832832
collector_type: *command
833833
collector_args:
834-
command: cibadmin --query --xpath "//nvpair[@name='msi']" | grep -o 'value=\"[^\"]*\"' | cut -d'"' -f2
834+
command: cibadmin --query --xpath "//nvpair[@name='msi']" 2>/dev/null | grep -o 'value="[^"]*"' 2>/dev/null | cut -d'"' -f2
835835
user: *root
836836
validator_type: *string
837837
validator_args:

src/roles/configuration_checks/tasks/files/network.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,12 @@ checks:
185185
nic=$(basename "$nic_id"); \
186186
status=$(az network nic show --resource-group {{ CONTEXT.resource_group_name }} --name "$nic" \
187187
--query "enableAcceleratedNetworking" -o tsv); \
188-
echo "$status"; \
188+
echo "$nic: AcceleratedNetworking=$status"; \
189189
done
190190
validator_type: *string
191191
validator_args:
192-
expected_output: "true"
192+
expected_output: "false"
193+
match_mode: "not_contains"
193194
report: *check
194195

195196
- id: "NET-0006"

src/roles/configuration_checks/tasks/files/virtual_machine.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ checks:
261261
database_type: *db
262262
collector_type: *command
263263
collector_args:
264-
command: "/bin/cat /etc/os-release | grep PRETTY_NAME | cut -d '=' -f2 | tr -d '\"'"
264+
command: "/bin/cat /etc/os-release | grep -v '^#' | grep PRETTY_NAME | cut -d '=' -f2 | tr -d '\"'"
265265
user: *root
266266
report: *check
267267

@@ -914,13 +914,13 @@ checks:
914914
severity: *info
915915
workload: *workload
916916
applicability:
917-
os_type: [*suse, *redhat, *oraclelinux]
917+
os_type: [*redhat]
918918
os_version: *all_versions
919919
hardware_type: *vm
920920
role: *role
921921
database_type: *db
922922
collector_type: *command
923923
collector_args:
924-
command: "/bin/systemctl status kdump.service | grep -o 'Active:.*'"
924+
command: "/bin/systemctl status kdump.service 2>/dev/null | grep -o 'Active:.*' || echo 'kdump.service not found. Recommendation: Install and enable kdump for crash dump analysis.'"
925925
user: *root
926926
report: *check

src/roles/ha_scs/tasks/ascs-node-crash.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@
9090
- name: "Test Execution: Determine test execution status"
9191
ansible.builtin.set_fact:
9292
test_execution_status: "{{ 'PASSED' if (
93-
(hostvars[cluster_status_pre.ers_node].cluster_status_test_execution.ascs_node == cluster_status_pre.ers_node and
94-
hostvars[cluster_status_pre.ers_node].cluster_status_test_execution.ers_node == cluster_status_pre.ascs_node) or
95-
(hostvars[cluster_status_pre.ers_node].cluster_status_test_execution.ascs_node == cluster_status_pre.ascs_node and
96-
hostvars[cluster_status_pre.ers_node].cluster_status_test_execution.ers_node == cluster_status_pre.ers_node)
93+
(hostvars[cluster_status_pre.ers_node]['cluster_status_test_execution']['ascs_node'] == cluster_status_pre.ers_node and
94+
hostvars[cluster_status_pre.ers_node]['cluster_status_test_execution']['ers_node'] == cluster_status_pre.ascs_node) or
95+
(hostvars[cluster_status_pre.ers_node]['cluster_status_test_execution']['ascs_node'] == cluster_status_pre.ascs_node and
96+
hostvars[cluster_status_pre.ers_node]['cluster_status_test_execution']['ers_node'] == cluster_status_pre.ers_node)
9797
) else 'FAILED' }}"
9898

9999
- name: "Test Execution: Stop timer"
@@ -104,15 +104,15 @@
104104
ansible.builtin.set_fact:
105105
test_case_message_from_test_case: |
106106
Old ASCS: {{ cluster_status_pre.ascs_node }}
107-
New ASCS: {{ hostvars[cluster_status_pre.ers_node].cluster_status_test_execution.ascs_node | default('N/A') }}
107+
New ASCS: {{ hostvars[cluster_status_pre.ers_node]['cluster_status_test_execution']['ascs_node'] | default('N/A') }}
108108
Old ERS: {{ cluster_status_pre.ers_node }}
109-
New ERS: {{ hostvars[cluster_status_pre.ers_node].cluster_status_test_execution.ers_node | default('N/A') }}
109+
New ERS: {{ hostvars[cluster_status_pre.ers_node]['cluster_status_test_execution']['ers_node'] | default('N/A') }}
110110
test_case_details_from_test_case: {
111111
"Pre Validations: Validate HANA DB cluster status": "{{ cluster_status_pre }}",
112112
"Pre Validations: CleanUp any failed resource": "{{ cleanup_failed_resource_pre }}",
113113
"Test Execution: Crash ASCS resource": "{{ ascs_crash_result }}",
114114
"Test Execution: Cleanup resources": "{{ cleanup_failed_resource_test_execution }}",
115-
"Post Validations Result": "{{ hostvars[cluster_status_pre.ers_node].cluster_status_test_execution }}",
115+
"Post Validations Result": "{{ hostvars[cluster_status_pre.ers_node]['cluster_status_test_execution'] }}",
116116
}
117117
# /*---------------------------------------------------------------------------
118118
# | Post Validations |

src/roles/ha_scs/tasks/files/constants.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,12 @@ RESOURCE_DEFAULTS:
208208
value: "5000"
209209
required: false
210210
priority:
211-
value: "100"
212-
required: true
211+
ENSA1:
212+
value: "10"
213+
required: true
214+
ENSA2:
215+
value: "100"
216+
required: true
213217
operations:
214218
monitor:
215219
interval:
@@ -267,8 +271,12 @@ RESOURCE_DEFAULTS:
267271
value: "5000"
268272
required: false
269273
priority:
270-
value: "100"
271-
required: false
274+
ENSA1:
275+
value: "1000"
276+
required: true
277+
ENSA2:
278+
value: "100"
279+
required: true
272280
operations:
273281
monitor:
274282
interval:

src/roles/ha_scs/tasks/sapcontrol-config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- name: "Test Execution: Validate sapcontrol commands"
5353
ansible.builtin.set_fact:
5454
test_execution_end: "{{ now(utc=true, fmt='%Y-%m-%d %H:%M:%S') }}"
55+
test_execution_status: "{{ 'PASSED' if sapcontrol_results.results | map(attribute='rc') | reject('equalto', 0) | list | length == 0 else 'FAILED' }}"
5556
test_case_message_from_test_case: >-
5657
Commands executed:
5758
{% for res in sapcontrol_results.results %}

tests/modules/configuration_check_module_test.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,45 @@ def test_validate_string_whitespace_handling(self, config_module, sample_check):
257257
result = config_module.validate_string(sample_check, " test value ")
258258
assert result["status"] == TestStatus.SUCCESS.value
259259

260+
def test_validate_string_contains_mode_success(self, config_module, sample_check):
261+
"""Test string validation with match_mode contains"""
262+
sample_check.validator_args = {"expected": "true", "match_mode": "contains"}
263+
result = config_module.validate_string(sample_check, "nic1: AcceleratedNetworking=true")
264+
assert result["status"] == TestStatus.SUCCESS.value
265+
266+
def test_validate_string_contains_mode_failure(self, config_module, sample_check):
267+
"""Test string validation with match_mode contains"""
268+
sample_check.validator_args = {"expected": "false", "match_mode": "contains"}
269+
sample_check.severity = TestSeverity.WARNING
270+
result = config_module.validate_string(sample_check, "nic1: AcceleratedNetworking=true")
271+
assert result["status"] == TestStatus.WARNING.value
272+
273+
def test_validate_string_not_contains_mode_success(self, config_module, sample_check):
274+
"""Test string validation with match_mode not_contains"""
275+
sample_check.validator_args = {"expected": "false", "match_mode": "not_contains"}
276+
result = config_module.validate_string(
277+
sample_check, "nic1: AcceleratedNetworking=true nic2: AcceleratedNetworking=true"
278+
)
279+
assert result["status"] == TestStatus.SUCCESS.value
280+
281+
def test_validate_string_not_contains_mode_failure(self, config_module, sample_check):
282+
"""Test string validation with match_mode not_contains"""
283+
sample_check.validator_args = {"expected": "false", "match_mode": "not_contains"}
284+
sample_check.severity = TestSeverity.WARNING
285+
result = config_module.validate_string(
286+
sample_check, "nic1: AcceleratedNetworking=true nic2: AcceleratedNetworking=false"
287+
)
288+
assert result["status"] == TestStatus.WARNING.value
289+
290+
def test_validate_string_default_match_mode_is_exact(self, config_module, sample_check):
291+
"""Test that default match_mode is exact (backward compatible)"""
292+
sample_check.validator_args = {"expected": "true"}
293+
result = config_module.validate_string(sample_check, "true")
294+
assert result["status"] == TestStatus.SUCCESS.value
295+
sample_check.severity = TestSeverity.WARNING
296+
result = config_module.validate_string(sample_check, "nic: true")
297+
assert result["status"] == TestStatus.WARNING.value
298+
260299
def test_validate_numeric_range_within_bounds(self, config_module, sample_check):
261300
"""Test numeric range validation within bounds"""
262301
sample_check.validator_args = {"min": 10, "max": 100}

0 commit comments

Comments
 (0)