1111from tests .common .gu_utils import create_checkpoint , delete_checkpoint , rollback_or_reload
1212
1313pytestmark = [
14- pytest .mark .topology ('t0' , 'm0' , 'mx' , "m1" , "m2" , "m3" ),
14+ pytest .mark .topology ('t0' , 'm0' , 'mx' , "m1" , "m2" , "m3" , 't2' ),
1515]
1616
1717logger = logging .getLogger (__name__ )
1818
1919
20- def get_bgp_monitor_runningconfig (duthost ):
20+ def get_bgp_monitor_runningconfig (duthost , cli_namespace_prefix ):
2121 """ Get bgp listener config
2222 """
23- cmds = "show runningconfiguration bgp"
23+ cmds = "show runningconfiguration bgp {}" . format ( cli_namespace_prefix )
2424 output = duthost .shell (cmds )
2525 pytest_assert (not output ['rc' ], "'{}' failed with rc={}" .format (cmds , output ['rc' ]))
2626
@@ -32,23 +32,25 @@ def get_bgp_monitor_runningconfig(duthost):
3232
3333
3434@pytest .fixture (autouse = True )
35- def setup_env (duthosts , rand_one_dut_hostname ):
35+ def setup_env (duthosts , rand_one_dut_front_end_hostname , enum_rand_one_frontend_asic_index , cli_namespace_prefix ):
3636 """
3737 Setup/teardown fixture for bgpmon config
3838 Args:
3939 duthosts: list of DUTs.
40- rand_selected_dut: The fixture returns a randomly selected DuT.
40+ rand_selected_front_end_dut: The fixture returns a randomly selected DuT.
41+ enum_rand_one_frontend_asic_index: random selected asic namespace.
42+ cli_namespace_prefix: Formatted asic namespace for cli commands
4143 """
42- duthost = duthosts [rand_one_dut_hostname ]
43- original_bgp_listener_config = get_bgp_monitor_runningconfig (duthost )
44+ duthost = duthosts [rand_one_dut_front_end_hostname ]
45+ original_bgp_listener_config = get_bgp_monitor_runningconfig (duthost , cli_namespace_prefix )
4446 create_checkpoint (duthost )
4547
4648 yield
4749
4850 try :
4951 logger .info ("Rolled back to original checkpoint" )
5052 rollback_or_reload (duthost )
51- current_bgp_listener_config = get_bgp_monitor_runningconfig (duthost )
53+ current_bgp_listener_config = get_bgp_monitor_runningconfig (duthost , cli_namespace_prefix )
5254 pytest_assert (
5355 set (original_bgp_listener_config ) == set (current_bgp_listener_config ),
5456 "bgp listener config are not suppose to change after test"
@@ -58,42 +60,43 @@ def setup_env(duthosts, rand_one_dut_hostname):
5860
5961
6062@pytest .fixture (scope = "module" )
61- def bgpmon_setup_info (rand_selected_dut ):
63+ def bgpmon_setup_info (rand_selected_front_end_dut ):
6264 """ Get initial setup info for BGPMONITOR
6365 """
64- peer_addr = generate_ip_through_default_route (rand_selected_dut )
66+ peer_addr = generate_ip_through_default_route (rand_selected_front_end_dut )
6567 pytest_assert (peer_addr , "Failed to generate ip address for test" )
6668 peer_addr = str (IPNetwork (peer_addr ).ip )
6769
68- mg_facts = rand_selected_dut .minigraph_facts (host = rand_selected_dut .hostname )['ansible_facts' ]
70+ mg_facts = rand_selected_front_end_dut .minigraph_facts (host = rand_selected_front_end_dut .hostname )['ansible_facts' ]
6971 local_addr = mg_facts ['minigraph_lo_interfaces' ][0 ]['addr' ]
7072
7173 return peer_addr , local_addr , str (mg_facts ['minigraph_bgp_asn' ])
7274
7375
74- def bgpmon_cleanup_config (duthost ):
76+ def bgpmon_cleanup_config (duthost , cli_namespace_prefix ):
7577 """ Clean up BGPMONITOR config to make sure t0 is not broken by other tests
7678 """
77- cmds = 'sonic-db-cli CONFIG_DB keys "BGP_MONITORS|*" | xargs -r sonic-db-cli CONFIG_DB del'
79+ cmds = 'sonic-db-cli {} CONFIG_DB keys "BGP_MONITORS|*" | xargs -r sonic-db-cli CONFIG_DB del' .format (
80+ cli_namespace_prefix )
7881 output = duthost .shell (cmds )
7982 pytest_assert (not output ['rc' ], "bgpmon cleanup config failed" )
8083
8184
82- def check_bgpmon_with_addr (duthost , addr ):
85+ def check_bgpmon_with_addr (duthost , addr , cli_namespace_prefix ):
8386 """ Check BGP MONITOR config change is taken into effect
8487 """
85- cmds = "show ip bgp summary | grep -w {}" .format (addr )
88+ cmds = "show ip bgp summary {} | grep -w {}" .format (cli_namespace_prefix , addr )
8689 output = duthost .shell (cmds )
8790 pytest_assert (not output ['rc' ], "BGPMonitor with addr {} is not being setup." .format (addr ))
8891
8992
90- def bgpmon_tc1_add_init (duthost , bgpmon_setup_info ):
93+ def bgpmon_tc1_add_init (duthost , bgpmon_setup_info , cli_namespace_prefix , namespace = None ):
9194 """ Test to add initial bgpmon config
9295
9396 Make sure bgpmon is cleaned up for current topo.
9497 Then test to add initial setup for bgpmon.
9598 """
96- bgpmon_cleanup_config (duthost )
99+ bgpmon_cleanup_config (duthost , cli_namespace_prefix )
97100
98101 peer_addr , local_addr , bgp_asn = bgpmon_setup_info
99102 json_patch = [
@@ -114,7 +117,8 @@ def bgpmon_tc1_add_init(duthost, bgpmon_setup_info):
114117 }
115118 }
116119 ]
117- json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch , is_asic_specific = True )
120+ json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch ,
121+ is_asic_specific = True , asic_namespaces = [namespace ])
118122
119123 tmpfile = generate_tmpfile (duthost )
120124 logger .info ("tmpfile {}" .format (tmpfile ))
@@ -123,12 +127,12 @@ def bgpmon_tc1_add_init(duthost, bgpmon_setup_info):
123127 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
124128 expect_op_success (duthost , output )
125129
126- check_bgpmon_with_addr (duthost , peer_addr )
130+ check_bgpmon_with_addr (duthost , peer_addr , cli_namespace_prefix )
127131 finally :
128132 delete_tmpfile (duthost , tmpfile )
129133
130134
131- def bgpmon_tc1_add_duplicate (duthost , bgpmon_setup_info ):
135+ def bgpmon_tc1_add_duplicate (duthost , bgpmon_setup_info , cli_namespace_prefix , namespace = None ):
132136 """ Test to add duplicate config to bgpmon
133137 """
134138 peer_addr , local_addr , bgp_asn = bgpmon_setup_info
@@ -148,7 +152,8 @@ def bgpmon_tc1_add_duplicate(duthost, bgpmon_setup_info):
148152 }
149153 }
150154 ]
151- json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch , is_asic_specific = True )
155+ json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch ,
156+ is_asic_specific = True , asic_namespaces = [namespace ])
152157
153158 tmpfile = generate_tmpfile (duthost )
154159 logger .info ("tmpfile {}" .format (tmpfile ))
@@ -157,12 +162,12 @@ def bgpmon_tc1_add_duplicate(duthost, bgpmon_setup_info):
157162 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
158163 expect_op_success (duthost , output )
159164
160- check_bgpmon_with_addr (duthost , peer_addr )
165+ check_bgpmon_with_addr (duthost , peer_addr , cli_namespace_prefix )
161166 finally :
162167 delete_tmpfile (duthost , tmpfile )
163168
164169
165- def bgpmon_tc1_admin_change (duthost , bgpmon_setup_info ):
170+ def bgpmon_tc1_admin_change (duthost , bgpmon_setup_info , cli_namespace_prefix , namespace = None ):
166171 """ Test to admin down bgpmon config
167172 """
168173 peer_addr , _ , _ = bgpmon_setup_info
@@ -173,7 +178,8 @@ def bgpmon_tc1_admin_change(duthost, bgpmon_setup_info):
173178 "value" : "down"
174179 }
175180 ]
176- json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch , is_asic_specific = True )
181+ json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch ,
182+ is_asic_specific = True , asic_namespaces = [namespace ])
177183
178184 tmpfile = generate_tmpfile (duthost )
179185 logger .info ("tmpfile {}" .format (tmpfile ))
@@ -182,15 +188,15 @@ def bgpmon_tc1_admin_change(duthost, bgpmon_setup_info):
182188 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
183189 expect_op_success (duthost , output )
184190
185- cmds = "show ip bgp summary | grep -w {}" .format (peer_addr )
191+ cmds = "show ip bgp summary {} | grep -w {}" .format (cli_namespace_prefix , peer_addr )
186192 output = duthost .shell (cmds )
187193 pytest_assert (not output ['rc' ] and "Idle (Admin)" in output ['stdout' ],
188194 "BGPMonitor with addr {} failed to admin down." .format (peer_addr ))
189195 finally :
190196 delete_tmpfile (duthost , tmpfile )
191197
192198
193- def bgpmon_tc1_ip_change (duthost , bgpmon_setup_info ):
199+ def bgpmon_tc1_ip_change (duthost , bgpmon_setup_info , cli_namespace_prefix , namespace = None ):
194200 """ Test to replace bgpmon ip address
195201 """
196202 peer_addr , local_addr , bgp_asn = bgpmon_setup_info
@@ -216,7 +222,8 @@ def bgpmon_tc1_ip_change(duthost, bgpmon_setup_info):
216222 }
217223 }
218224 ]
219- json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch , is_asic_specific = True )
225+ json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch ,
226+ is_asic_specific = True , asic_namespaces = [namespace ])
220227
221228 tmpfile = generate_tmpfile (duthost )
222229 logger .info ("tmpfile {}" .format (tmpfile ))
@@ -225,12 +232,12 @@ def bgpmon_tc1_ip_change(duthost, bgpmon_setup_info):
225232 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
226233 expect_op_success (duthost , output )
227234
228- check_bgpmon_with_addr (duthost , peer_addr_replaced )
235+ check_bgpmon_with_addr (duthost , peer_addr_replaced , cli_namespace_prefix )
229236 finally :
230237 delete_tmpfile (duthost , tmpfile )
231238
232239
233- def bgpmon_tc1_remove (duthost ):
240+ def bgpmon_tc1_remove (duthost , cli_namespace_prefix , namespace = None ):
234241 """ Test to remove bgpmon config
235242 """
236243 json_patch = [
@@ -239,7 +246,8 @@ def bgpmon_tc1_remove(duthost):
239246 "path" : "/BGP_MONITORS"
240247 }
241248 ]
242- json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch , is_asic_specific = True )
249+ json_patch = format_json_patch_for_multiasic (duthost = duthost , json_data = json_patch ,
250+ is_asic_specific = True , asic_namespaces = [namespace ])
243251
244252 tmpfile = generate_tmpfile (duthost )
245253 logger .info ("tmpfile {}" .format (tmpfile ))
@@ -248,18 +256,20 @@ def bgpmon_tc1_remove(duthost):
248256 output = apply_patch (duthost , json_data = json_patch , dest_file = tmpfile )
249257 expect_op_success (duthost , output )
250258
251- output = duthost .shell ("show ip bgp summary" )
259+ output = duthost .shell ("show ip bgp summary {}" . format ( cli_namespace_prefix ) )
252260 pytest_assert (not output ['rc' ], "Failed to get info from BGP summary" )
253261 pytest_assert ("BGPMonitor" not in output ['stdout' ], "Failed to remove BGPMonitor" )
254262 finally :
255263 delete_tmpfile (duthost , tmpfile )
256264
257265
258- def test_bgpmon_tc1_add_and_remove (rand_selected_dut , bgpmon_setup_info ):
266+ def test_bgpmon_tc1_add_and_remove (rand_selected_front_end_dut , bgpmon_setup_info ,
267+ enum_rand_one_frontend_asic_index , cli_namespace_prefix ):
259268 """ Test to verify bgpmon config addition and deletion
260269 """
261- bgpmon_tc1_add_init (rand_selected_dut , bgpmon_setup_info )
262- bgpmon_tc1_add_duplicate (rand_selected_dut , bgpmon_setup_info )
263- bgpmon_tc1_admin_change (rand_selected_dut , bgpmon_setup_info )
264- bgpmon_tc1_ip_change (rand_selected_dut , bgpmon_setup_info )
265- bgpmon_tc1_remove (rand_selected_dut )
270+ asic_namespace = rand_selected_front_end_dut .get_namespace_from_asic_id (enum_rand_one_frontend_asic_index )
271+ bgpmon_tc1_add_init (rand_selected_front_end_dut , bgpmon_setup_info , cli_namespace_prefix , asic_namespace )
272+ bgpmon_tc1_add_duplicate (rand_selected_front_end_dut , bgpmon_setup_info , cli_namespace_prefix , asic_namespace )
273+ bgpmon_tc1_admin_change (rand_selected_front_end_dut , bgpmon_setup_info , cli_namespace_prefix , asic_namespace )
274+ bgpmon_tc1_ip_change (rand_selected_front_end_dut , bgpmon_setup_info , cli_namespace_prefix , asic_namespace )
275+ bgpmon_tc1_remove (rand_selected_front_end_dut , cli_namespace_prefix , asic_namespace )
0 commit comments