Skip to content

Commit edb67d0

Browse files
Added tests
1 parent e086e12 commit edb67d0

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

cmapi/cmapi_server/node_manipulation.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,11 +1216,6 @@ def update_dbroots_of_readonly_nodes(root: etree.Element) -> None:
12161216
if read_only_nodes is None:
12171217
return
12181218
for n in read_only_nodes.findall("./Node"):
1219-
add_dbroots = n.get("add_other_nodes_dbroots", "true").lower() == "true"
1220-
if not add_dbroots:
1221-
logging.info(f"Not adding dbroots of other nodes to {n.text} because it is a coordinator node")
1222-
continue
1223-
12241219
ro_node = n.text
12251220
# Get PM num by IP address
12261221
this_ip_pm_num = None
@@ -1229,8 +1224,13 @@ def update_dbroots_of_readonly_nodes(root: etree.Element) -> None:
12291224
this_ip_pm_num = pm_num
12301225
break
12311226
if this_ip_pm_num is not None:
1232-
# Add dbroots of other nodes to this read-only node
1233-
add_dbroots_of_other_nodes(root, this_ip_pm_num)
1227+
add_dbroots = n.get("add_other_nodes_dbroots", "true").lower() == "true"
1228+
if add_dbroots:
1229+
# Add dbroots of other nodes to this read-only node
1230+
add_dbroots_of_other_nodes(root, this_ip_pm_num)
1231+
else:
1232+
logging.info(f"Not adding dbroots of other nodes to {n.text} because it is a coordinator node")
1233+
remove_dbroots_of_node(root, this_ip_pm_num)
12341234
else: # This should not happen
12351235
err_msg = f"Could not find PM number for read-only node {ro_node}"
12361236
logging.error(err_msg)

cmapi/cmapi_server/test/test_node_manip.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
from cmapi_server import node_manipulation
99
from cmapi_server.constants import MCS_DATA_PATH
10-
from cmapi_server.node_manipulation import add_dbroots_of_other_nodes, remove_dbroots_of_node, update_dbroots_of_readonly_nodes
10+
from cmapi_server.node_manipulation import (
11+
_add_read_only_node, add_dbroots_of_other_nodes, remove_dbroots_of_node, update_dbroots_of_readonly_nodes
12+
)
1113
from cmapi_server.test.unittest_global import BaseNodeManipTestCase, tmp_mcs_config_filename
1214
from mcs_node_control.models.node_config import NodeConfig
1315

@@ -26,14 +28,16 @@ def test_add_remove_node(self):
2628

2729
with patch('cmapi_server.node_manipulation.update_dbroots_of_readonly_nodes') as mock_update_dbroots_of_readonly_nodes:
2830
node_manipulation.add_node(
29-
self.NEW_NODE_NAME, tmp_mcs_config_filename, self.tmp_files[0]
31+
self.NEW_NODE_NAME, tmp_mcs_config_filename, self.tmp_files[0],
32+
read_only=False,
3033
)
3134
mock_update_dbroots_of_readonly_nodes.assert_not_called()
3235

3336
node_manipulation.add_node(
34-
hostaddr, self.tmp_files[0], self.tmp_files[1]
37+
hostaddr, self.tmp_files[0], self.tmp_files[1],
38+
read_only=False,
3539
)
36-
mock_update_dbroots_of_readonly_nodes.assert_called_once()
40+
mock_update_dbroots_of_readonly_nodes.assert_not_called()
3741

3842
# get a NodeConfig, read test.xml
3943
# look for some of the expected changes.
@@ -281,6 +285,8 @@ def test_unassign_dbroot1(self):
281285

282286
class TestDBRootsManipulation(unittest.TestCase):
283287
our_module_idx = 3
288+
rw_node1_ip = '192.168.1.1'
289+
rw_node2_ip = '192.168.1.2'
284290
ro_node1_ip = '192.168.1.3'
285291
ro_node2_ip = '192.168.1.4'
286292

@@ -292,9 +298,9 @@ def setUp(self):
292298
module_count = etree.SubElement(smc, 'ModuleCount3')
293299
module_count.text = '2'
294300
module1_ip = etree.SubElement(smc, 'ModuleIPAddr1-1-3')
295-
module1_ip.text = '192.168.1.1'
301+
module1_ip.text = self.rw_node1_ip
296302
module2_ip = etree.SubElement(smc, 'ModuleIPAddr2-1-3')
297-
module2_ip.text = '192.168.1.2'
303+
module2_ip.text = self.rw_node2_ip
298304

299305
system_config = etree.SubElement(self.root, 'SystemConfig')
300306
dbroot_count = etree.SubElement(system_config, 'DBRootCount')
@@ -308,8 +314,8 @@ def test_get_pm_module_num_to_addr_map(self):
308314
result = node_manipulation.get_pm_module_num_to_addr_map(self.root)
309315

310316
expected = {
311-
1: '192.168.1.1',
312-
2: '192.168.1.2',
317+
1: self.rw_node1_ip,
318+
2: self.rw_node2_ip,
313319
}
314320
self.assertEqual(result, expected)
315321

@@ -383,3 +389,24 @@ def test_update_dbroots_of_readonly_nodes(self):
383389
self.assertIsNotNone(dbroot2)
384390
self.assertEqual(dbroot1.text, '1')
385391
self.assertEqual(dbroot2.text, '2')
392+
393+
def test_update_dbroots_of_readonly_nodes_ignores_coordinator_nodes(self):
394+
"""Test that update_dbroots_of_readonly_nodes doesn't add dbroots to coordinator nodes
395+
(read-only nodes that have add_other_nodes_dbroots="false")
396+
"""
397+
# Add read-only nodes
398+
for ip, is_coordinator in zip([self.ro_node1_ip, self.ro_node2_ip], [True, False]):
399+
node = etree.SubElement(self.root.find('./ReadOnlyNodes'), 'Node')
400+
node.text = ip
401+
node.set('add_other_nodes_dbroots', str(is_coordinator).lower())
402+
403+
update_dbroots_of_readonly_nodes(self.root)
404+
405+
# Check that RO node 1 has no dbroots
406+
module_count = self.root.find(f'./SystemModuleConfig/ModuleDBRootCount3-3')
407+
self.assertIsNone(module_count)
408+
409+
# Check that RO node 2 has dbroots
410+
module_count = self.root.find(f'./SystemModuleConfig/ModuleDBRootCount4-3')
411+
self.assertIsNotNone(module_count)
412+
self.assertEqual(module_count.text, '2')

cmapi/mcs_node_control/models/node_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def get_all_dbroots(self, root):
592592

593593
def get_read_only_nodes(self, root=None) -> list[str]:
594594
"""Get names of read only nodes from config"""
595-
root = root or self.get_current_config_root()
595+
root = root if root is not None else self.get_current_config_root()
596596
return [node.text for node in root.findall('./ReadOnlyNodes/Node')]
597597

598598
def is_read_only(self, root=None) -> bool:

0 commit comments

Comments
 (0)