@@ -176,19 +176,19 @@ def change_bgp_dut_state(self, is_up=True):
176176 self .fails ['dut' ].add ('Stderr: %s' % stderr )
177177
178178 def verify_bgp_dut_state (self , state = 'Idle' ):
179- state = state .split (',' )
179+ states = state .split (',' )
180180 bgp_state = {}
181181 bgp_state ['v4' ] = bgp_state ['v6' ] = False
182182 for key in self .neigh_bgp .keys ():
183183 if key not in ['v4' , 'v6' ]:
184184 continue
185- self .log .append ('Verifying if the DUT side BGP peer %s is %s' % (self .neigh_bgp [key ], state ))
185+ self .log .append ('Verifying if the DUT side BGP peer %s is %s' % (self .neigh_bgp [key ], states ))
186186 stdout , stderr , return_code = self .cmd (['ssh' , '-oStrictHostKeyChecking=no' , self .dut_ssh , 'show ip bgp neighbor %s' % self .neigh_bgp [key ]])
187187 if return_code == 0 :
188188 for line in stdout .split ('\n ' ):
189189 if 'BGP state' in line :
190190 curr_state = re .findall ('BGP state = (\w+)' , line )[0 ]
191- bgp_state [key ] = (curr_state in state )
191+ bgp_state [key ] = (curr_state in states )
192192 break
193193 else :
194194 self .fails ['dut' ].add ('Retreiving BGP info for peer %s from DUT side failed' % self .neigh_bgp [key ])
@@ -220,17 +220,19 @@ def populate_lag_state(self):
220220
221221 def change_dut_lag_state (self , is_up = True ):
222222 state = ['shutdown' , 'startup' ]
223- self .log .append ('Changing state of %s from DUT side to %s' % (self .vm_dut_map [self .neigh_name ]['dut_portchannel' ], state [is_up ]))
224- stdout , stderr , return_code = self .cmd (['ssh' , '-oStrictHostKeyChecking=no' , self .dut_ssh , 'sudo config interface %s %s' % (state [is_up ], self .vm_dut_map [self .neigh_name ]['dut_portchannel' ])])
223+ dut_portchannel = self .vm_dut_map [self .neigh_name ]['dut_portchannel' ]
224+ if not re .match ('(PortChannel|Ethernet)\d+' , dut_portchannel ): return
225+ self .log .append ('Changing state of %s from DUT side to %s' % (dut_portchannel , state [is_up ]))
226+ stdout , stderr , return_code = self .cmd (['ssh' , '-oStrictHostKeyChecking=no' , self .dut_ssh , 'sudo config interface %s %s' % (state [is_up ], dut_portchannel )])
225227 if return_code != 0 :
226- self .fails ['dut' ].add ('%s: State change not successful from DUT side for %s' % (self .msg_prefix [1 - is_up ], self . vm_dut_map [ self . neigh_name ][ ' dut_portchannel' ] ))
228+ self .fails ['dut' ].add ('%s: State change not successful from DUT side for %s' % (self .msg_prefix [1 - is_up ], dut_portchannel ))
227229 self .fails ['dut' ].add ('%s: Return code: %d' % (self .msg_prefix [1 - is_up ], return_code ))
228230 self .fails ['dut' ].add ('%s: Stderr: %s' % (self .msg_prefix [1 - is_up ], stderr ))
229231 else :
230232 self .log .append ('State change successful on DUT' )
231233
232234 def verify_dut_lag_member_state (self , lag_memb_output , pre_check = True ):
233- fails = False
235+ success = True
234236 for member in self .vm_dut_map [self .neigh_name ]['dut_ports' ]:
235237 if self .lag_members_down is not None and member in self .lag_members_down :
236238 search_str = '%s(D)' % member
@@ -240,9 +242,9 @@ def verify_dut_lag_member_state(self, lag_memb_output, pre_check=True):
240242 if lag_memb_output .find (search_str ) != - 1 :
241243 self .log .append ('Lag member %s state as expected' % member )
242244 else :
243- fails = True
245+ success = False
244246 self .fails ['dut' ].add ('%s: Lag member %s state not as expected' % (self .msg_prefix [pre_check ], member ))
245- return fails
247+ return success
246248
247249 def verify_dut_lag_state (self , pre_check = True ):
248250 pat = re .compile (".*%s\s+LACP\(A\)\(Dw\)\s+(.*)" % self .vm_dut_map [self .neigh_name ]['dut_portchannel' ])
@@ -251,7 +253,7 @@ def verify_dut_lag_state(self, pre_check=True):
251253 for line in stdout .split ('\n ' ):
252254 if self .vm_dut_map [self .neigh_name ]['dut_portchannel' ] in line :
253255 is_match = pat .match (line )
254- if is_match and not self .verify_dut_lag_member_state (is_match .group (1 ), pre_check = pre_check ):
256+ if is_match and self .verify_dut_lag_member_state (is_match .group (1 ), pre_check = pre_check ):
255257 self .log .append ('Lag state is down as expected on the DUT' )
256258 self .log .append ('Pattern check: %s' % line )
257259 else :
0 commit comments