77
88from  cmapi_server  import  node_manipulation 
99from  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+ )
1113from  cmapi_server .test .unittest_global  import  BaseNodeManipTestCase , tmp_mcs_config_filename 
1214from  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
282286class  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' )
0 commit comments