Skip to content

Commit 43cbd2c

Browse files
committed
Refactor cluster status checking logic and improve logging for node attributes
1 parent 9ef298a commit 43cbd2c

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

src/module_utils/get_cluster_status.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,17 @@ def _validate_cluster_basic_status(self, cluster_status_xml: ET.Element) -> bool
6868
:return: True if the cluster is stable, False otherwise.
6969
:rtype: bool
7070
"""
71-
# Check pacemaker status
7271
if self.execute_command_subprocess(PACEMAKER_STATUS).strip() == "active":
7372
self.result["pacemaker_status"] = "running"
7473
else:
7574
self.result["pacemaker_status"] = "stopped"
7675
self.log(logging.INFO, f"Pacemaker status: {self.result['pacemaker_status']}")
7776

78-
# Check node count
7977
if int(cluster_status_xml.find("summary").find("nodes_configured").attrib["number"]) < 2:
8078
self.result["message"] = "Pacemaker cluster isn't stable (insufficient nodes)"
8179
self.log(logging.WARNING, self.result["message"])
8280
return False
8381

84-
# Check if all nodes are online
8582
nodes = cluster_status_xml.find("nodes")
8683
for node in nodes:
8784
if node.attrib["online"] != "true":
@@ -114,7 +111,6 @@ def run(self) -> Dict[str, str]:
114111
self._get_stonith_action()
115112

116113
try:
117-
# Implementing a common loop structure
118114
while not self._is_cluster_ready():
119115
self.result["cluster_status"] = self.execute_command_subprocess(CLUSTER_STATUS)
120116
cluster_status_xml = ET.fromstring(self.result["cluster_status"])

src/modules/get_cluster_status_scs.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,22 @@ def _process_node_attributes(self, node_attributes: ET.Element) -> Dict[str, Any
4040
:return: Dictionary with ASCS and ERS node information.
4141
:rtype: Dict[str, Any]
4242
"""
43+
if node_attributes is None:
44+
self.log(logging.WARNING, "Node attributes is None")
45+
return {}
4346
attribute_name = f"runs_ers_{self.sap_sid.upper()}"
47+
4448
for node in node_attributes:
49+
node_name = node.attrib.get("name", "unknown")
4550
for attribute in node:
46-
if attribute.attrib["name"] == attribute_name:
47-
if attribute.attrib["value"] == "1":
48-
self.result["ers_node"] = node.attrib["name"]
51+
attr_name = attribute.attrib.get("name", "")
52+
if attr_name == attribute_name:
53+
if attribute.attrib.get("value") == "1":
54+
self.result["ers_node"] = node_name
4955
else:
50-
self.result["ascs_node"] = node.attrib["name"]
51-
else:
52-
continue
56+
self.result["ascs_node"] = node_name
57+
58+
return self.result
5359

5460
def _is_cluster_ready(self) -> bool:
5561
"""
@@ -58,9 +64,6 @@ def _is_cluster_ready(self) -> bool:
5864
:return: True if the cluster is ready, False otherwise.
5965
:rtype: bool
6066
"""
61-
self.log(
62-
logging.INFO, f"Checking if the cluster is ready, ASCS NODE {self.result['ascs_node']}"
63-
)
6467
return self.result["ascs_node"] != ""
6568

6669
def _is_cluster_stable(self) -> bool:

0 commit comments

Comments
 (0)