Skip to content

Commit 79ff8b2

Browse files
committed
Refactor command execution logic in CommandCollector and update DB2 configuration checks in YAML files for improved clarity and functionality
1 parent 5e11170 commit 79ff8b2

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

src/module_utils/collector.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,13 @@ def collect(self, check, context) -> str:
123123
)
124124
return f"ERROR: Command sanitization failed after substitution: {e}"
125125

126-
check.command = command
127126
if user and user != "root":
128-
if not re.match(r"^[a-zA-Z0-9_-]+$", user):
129-
self.parent.log(logging.ERROR, f"Invalid user parameter: {user}")
130-
return f"ERROR: Invalid user parameter: {user}"
131-
132127
if user == "db2sid":
133128
user = f"db2{context.get('database_sid', '').lower()}"
129+
command = f"su - {user} -c {shlex.quote(command)}"
130+
self.parent.log(logging.INFO, f"Executing command as user {user} {command}")
134131

135-
command = f"sudo -u {shlex.quote(user)} {command}"
132+
check.command = command
136133

137134
return self.parent.execute_command_subprocess(
138135
command, shell_command=check.collector_args.get("shell", True)

src/modules/configuration_check_module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def is_check_applicable(self, check: Check) -> bool:
281281
"""
282282
self.log(
283283
logging.DEBUG,
284-
f"Checking applicability for check {check.applicability} with context: {self.context}",
284+
f"Checking applicability for check {check.applicability}",
285285
)
286286
for rule in check.applicability:
287287
context_value = self.context.get(rule.property)

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

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,26 @@ checks:
142142
severity: *high
143143
workload: *sap
144144
applicability:
145-
os_type: [*suse, *redhat]
145+
os_type: [*redhat]
146146
os_version: *all_versions
147147
hardware_type: *vm
148148
storage_type: *all_storage
149149
role: *all_role
150150
database_type: [*db2]
151151
collector_type: *command
152152
collector_args:
153-
command: "grep '^SELINUX=' /etc/selinux/config | awk -F= '{print $2}'"
153+
command: "[ -f /etc/selinux/config ] && grep '^SELINUX=' /etc/selinux/config | awk -F= '{print $2}' || echo 'disabled'"
154154
user: *root
155-
validator_type: *string
155+
validator_type: *list
156156
validator_args:
157-
expected_output: "enforcing"
157+
valid_list: ["permissive", "disabled"]
158158
report: *check
159+
references:
160+
sap: "2936683"
159161

160162
- id: "DB-Db2-0004"
161-
name: "vm.max_map_count setting"
162-
description: "vm.max_map_count setting"
163+
name: "vm.max_map_count should be MemTotal/4096"
164+
description: "vm.max_map_count setting should be set to MemTotal/4096"
163165
category: *sap_check
164166
severity: *high
165167
workload: *sap
@@ -371,15 +373,15 @@ checks:
371373

372374
- id: "DB-Db2-0013"
373375
name: "HADR TIMEOUT"
374-
description: "HADR TIMEOUT"
376+
description: "HADR TIMEOUT should be 45 seconds for RHEL"
375377
category: *sap_check
376378
severity: *high
377379
workload: *sap
378380
applicability:
379381
os_type: [*redhat]
380382
os_version: *all_versions
381383
hardware_type: *vm
382-
storage_type: [*premium_storage]
384+
storage_type: *premium_storage
383385
role: [*db_role]
384386
database_type: [*db2]
385387
collector_type: *command
@@ -395,21 +397,21 @@ checks:
395397

396398
- id: "DB-Db2-0014"
397399
name: "HADR TIMEOUT"
398-
description: "HADR TIMEOUT"
400+
description: "HADR TIMEOUT should be 60 seconds for SUSE"
399401
category: *sap_check
400402
severity: *high
401403
workload: *sap
402404
applicability:
403405
os_type: [*suse]
404406
os_version: *all_versions
405407
hardware_type: *vm
406-
storage_type: [*premium_storage]
408+
storage_type: *premium_storage
407409
role: [*db_role]
408410
database_type: [*db2]
409411
collector_type: *command
410412
collector_args:
411-
command: "db2pd -alldbs -hadr | grep -i 'HADR_TIMEOUT' | awk '{print $NF}'"
412-
user: *root
413+
command: ". ~/sqllib/db2profile && db2pd -alldbs -hadr | grep -i 'HADR_TIMEOUT' | awk '{print $NF}'"
414+
user: *db2sid
413415
validator_type: *string
414416
validator_args:
415417
expected_output: "60"
@@ -419,15 +421,15 @@ checks:
419421

420422
- id: "DB-Db2-0015"
421423
name: "PEER WINDOW (seconds)"
422-
description: "PEER WINDOW (seconds) RedHat"
424+
description: "PEER WINDOW should be 240 seconds for RHEL"
423425
category: *sap_check
424426
severity: *high
425427
workload: *sap
426428
applicability:
427429
os_type: [*redhat]
428430
os_version: *all_versions
429431
hardware_type: *vm
430-
storage_type: [*premium_storage]
432+
storage_type: *premium_storage
431433
role: [*db_role]
432434
database_type: [*db2]
433435
collector_type: *command
@@ -443,15 +445,15 @@ checks:
443445

444446
- id: "DB-Db2-0016"
445447
name: "PEER WINDOW (seconds)"
446-
description: "PEER WINDOW (seconds) SUSE SBD"
448+
description: "PEER WINDOW should be 300 seconds for SUSE with SBD"
447449
category: *sap_check
448450
severity: *high
449451
workload: *sap
450452
applicability:
451453
os_type: [*suse]
452454
os_version: *all_versions
453455
hardware_type: *vm
454-
storage_type: [*premium_storage]
456+
storage_type: *premium_storage
455457
role: [*db_role]
456458
database_type: [*db2]
457459
high_availability_agent: *sbd
@@ -468,15 +470,15 @@ checks:
468470

469471
- id: "DB-Db2-0017"
470472
name: "PEER WINDOW (seconds)"
471-
description: "PEER WINDOW (seconds) SUSE Fencing Agent"
473+
description: "PEER WINDOW should be 900 seconds for SUSE with Fencing Agent"
472474
category: *sap_check
473475
severity: *high
474476
workload: *sap
475477
applicability:
476478
os_type: [*suse]
477479
os_version: *all_versions
478480
hardware_type: *vm
479-
storage_type: [*premium_storage]
481+
storage_type: *premium_storage
480482
role: [*db_role]
481483
database_type: [*db2]
482484
high_availability_agent: *fencing_agent
@@ -493,7 +495,7 @@ checks:
493495

494496
- id: "DB-Db2-0018"
495497
name: "Maximum shared memory segments"
496-
description: "Maximum shared memory segments"
498+
description: "Maximum shared memory segments should be at least 256 times the total physical memory in GB"
497499
category: *sap_check
498500
severity: *high
499501
workload: *sap
@@ -506,7 +508,7 @@ checks:
506508
database_type: [*db2]
507509
collector_type: *command
508510
collector_args:
509-
command: "[ $((256 * $(free -g | grep Mem: | awk '{print $2}'))) -ge $(/sbin/sysctl kernel.shmmni -n) ] && echo OK || echo $(/sbin/sysctl kernel.shmmni -n)"
511+
command: "shmmni=$(/sbin/sysctl kernel.shmmni -n); mem_gb=$(free -g | grep Mem: | awk '{print $2}'); min_required=$((256 * mem_gb)); [ $shmmni -ge $min_required ] && echo OK || echo \"kernel.shmmni=$shmmni (required: >= $min_required, memory: ${mem_gb}GB)\""
510512
user: *root
511513
validator_type: *string
512514
validator_args:
@@ -518,20 +520,20 @@ checks:
518520

519521
- id: "DB-Db2-0019"
520522
name: "Instance Memory size"
521-
description: "Instance Memory size"
523+
description: "Instance Memory size should be at least 64 GB"
522524
category: *sap_check
523525
severity: *high
524526
workload: *sap
525527
applicability:
526528
os_type: [*suse, *redhat]
527529
os_version: *all_versions
528530
hardware_type: *vm
529-
storage_type: [*premium_storage]
531+
storage_type: *premium_storage
530532
role: [*db_role]
531533
database_type: [*db2]
532534
collector_type: *command
533535
collector_args:
534-
command: ". ~/sqllib/db2profile && output=$(db2pd -dbmcfg | grep INSTANCE_MEMORY | awk '{print $NF}'); [[ $output -le 100 ]] && echo $output || echo $(awk -v output=$output 'BEGIN {print output * 4096 / 1024 / 1024 / 1024}')"
536+
command: ". ~/sqllib/db2profile && db2pd -dbmcfg | grep INSTANCE_MEMORY | awk \"{if(\\$NF<=100) print \\$NF; else print \\$NF*4096/1024/1024/1024}\""
535537
user: *db2sid
536538
validator_type: *range
537539
validator_args:

src/templates/azure-pipeline.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# | |
88
# +------------------------------------4--------------------------------------*/
99

10-
name: SAP Quality Assurance $(sap_system_configuration_name)
10+
name: SAP Quality Assurance
1111

1212
parameters:
1313
- name: sap_system_configuration_name
@@ -25,18 +25,17 @@ parameters:
2525
type: string
2626
default: ''
2727

28-
- name: sap_on_azure_quality_checks
29-
displayName: SAP on Azure Quality Checks
28+
- name: sap_configuration_checks
29+
displayName: SAP Configuration Checks (v2 of SAP on Azure Quality Checks)
3030
type: boolean
3131
default: true
3232

33-
3433
- name: sap_functional_tests
3534
displayName: SAP Functional Tests
3635
type: boolean
3736
default: true
3837

39-
- name: sap_functional_test_type
38+
- name: SAP_FUNCTIONAL_TEST_TYPE
4039
displayName: SAP Functional Tests Type
4140
type: string
4241
default: "DatabaseHighAvailability"
@@ -70,14 +69,14 @@ extends:
7069
template: ./resources.yml
7170
parameters:
7271
stages:
73-
- template: deploy\pipelines\13-sap-quality-assurance.yaml@sap-automation
72+
- template: deploy\pipelines\13-sap-automation-qa.yaml@sap-automation
7473
parameters:
7574
sap_system_configuration_name: ${{ parameters.sap_system_configuration_name }}
7675
environment: ${{ parameters.environment }}
77-
sap_on_azure_quality_checks: ${{ parameters.sap_on_azure_quality_checks }}
7876
sap_automation_repo_path: $(Build.SourcesDirectory)/sap-automation
7977
config_repo_path: $(Build.SourcesDirectory)/config
8078
extra_params: ${{ parameters.extra_params }}
8179
sap_functional_tests: ${{ parameters.sap_functional_tests }}
82-
sap_functional_test_type: ${{ parameters.sap_functional_test_type }}
80+
SAP_FUNCTIONAL_TEST_TYPE: ${{ parameters.SAP_FUNCTIONAL_TEST_TYPE }}
8381
telemetry_data_destination: ${{ parameters.telemetry_data_destination }}
82+
sap_configuration_checks: ${{ parameters.sap_configuration_checks }}

0 commit comments

Comments
 (0)