@@ -148,7 +148,7 @@ def split_ips_by_family(ips):
148148def destroy_network_rules_for_nic (vm_name , vm_ip , vm_mac , vif , sec_ips ):
149149 try :
150150 rules = execute ("""iptables-save -t filter | awk '/ %s / { sub(/-A/, "-D", $1) ; print }'""" % vif ).split ("\n " )
151- for rule in filter ( None , rules ) :
151+ for rule in [ _f for _f in rules if _f ] :
152152 try :
153153 execute ("iptables " + rule )
154154 except :
@@ -158,7 +158,7 @@ def destroy_network_rules_for_nic(vm_name, vm_ip, vm_mac, vif, sec_ips):
158158
159159 try :
160160 dnats = execute ("""iptables-save -t nat | awk '/ %s / { sub(/-A/, "-D", $1) ; print }'""" % vif ).split ("\n " )
161- for dnat in filter ( None , dnats ) :
161+ for dnat in [ _f for _f in dnats if _f ] :
162162 try :
163163 execute ("iptables -t nat " + dnat )
164164 except :
@@ -205,14 +205,14 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
205205 destroy_ebtables_rules (vm_name , vif )
206206
207207 chains = [vmchain_default , vmchain , vmchain_egress ]
208- for chain in filter ( None , chains ) :
208+ for chain in [ _f for _f in chains if _f ] :
209209 try :
210210 execute ("iptables -F " + chain )
211211 execute ('ip6tables -F ' + chain )
212212 except :
213213 logging .debug ("Ignoring failure to flush chain: " + chain )
214214
215- for chain in filter ( None , chains ) :
215+ for chain in [ _f for _f in chains if _f ] :
216216 try :
217217 execute ("iptables -X " + chain )
218218 execute ('ip6tables -X ' + chain )
@@ -229,7 +229,7 @@ def destroy_network_rules_for_vm(vm_name, vif=None):
229229 if vif :
230230 try :
231231 dnats = execute ("""iptables -t nat -S | awk '/%s/ { sub(/-A/, "-D", $1) ; print }'""" % vif ).split ("\n " )
232- for dnat in filter ( None , dnats ) :
232+ for dnat in [ _f for _f in dnats if _f ] :
233233 try :
234234 execute ("iptables -t nat " + dnat )
235235 except :
@@ -247,14 +247,14 @@ def destroy_ebtables_rules(vm_name, vif):
247247 delcmd = "ebtables -t nat -L PREROUTING | grep " + eb_vm_chain
248248 delcmds = []
249249 try :
250- delcmds = filter ( None , execute (delcmd ).split ('\n ' ))
250+ delcmds = [ _f for _f in execute (delcmd ).split ('\n ' ) if _f ]
251251 delcmds = ["-D PREROUTING " + x for x in delcmds ]
252252 except :
253253 pass
254254 postcmds = []
255255 try :
256256 postcmd = "ebtables -t nat -L POSTROUTING | grep " + eb_vm_chain
257- postcmds = filter ( None , execute (postcmd ).split ('\n ' ))
257+ postcmds = [ _f for _f in execute (postcmd ).split ('\n ' ) if _f ]
258258 postcmds = ["-D POSTROUTING " + x for x in postcmds ]
259259 except :
260260 pass
@@ -493,7 +493,7 @@ def ebtables_rules_vmip (vmname, vmmac, ips, action):
493493 if action and action .strip () == "-A" :
494494 action = "-I"
495495
496- for ip in filter ( None , ips ) :
496+ for ip in [ _f for _f in ips if _f ] :
497497 logging .debug ("ip = " + ip )
498498 if ip == 0 or ip == "0" :
499499 continue
@@ -736,15 +736,15 @@ def delete_rules_for_vm_in_bridge_firewall_chain(vmName):
736736 vmchain = iptables_chain_name (vm_name )
737737
738738 delcmd = """iptables-save | awk '/BF(.*)physdev-is-bridged(.*)%s/ { sub(/-A/, "-D", $1) ; print }'""" % vmchain
739- delcmds = filter ( None , execute (delcmd ).split ('\n ' ))
739+ delcmds = [ _f for _f in execute (delcmd ).split ('\n ' ) if _f ]
740740 for cmd in delcmds :
741741 try :
742742 execute ("iptables " + cmd )
743743 except :
744744 logging .exception ("Ignoring failure to delete rules for vm " + vmName )
745745
746746 delcmd = """ip6tables-save | awk '/BF(.*)physdev-is-bridged(.*)%s/ { sub(/-A/, "-D", $1) ; print }'""" % vmchain
747- delcmds = filter ( None , execute (delcmd ).split ('\n ' ))
747+ delcmds = [ _f for _f in execute (delcmd ).split ('\n ' ) if _f ]
748748 for cmd in delcmds :
749749 try :
750750 execute ('ip6tables ' + cmd )
@@ -847,7 +847,7 @@ def network_rules_for_rebooted_vm(vmName):
847847 ipts = []
848848 for cmd in [delcmd , inscmd ]:
849849 logging .debug (cmd )
850- cmds = filter ( None , execute (cmd ).split ('\n ' ))
850+ cmds = [ _f for _f in execute (cmd ).split ('\n ' ) if _f ]
851851 for c in cmds :
852852 ipt = "iptables " + c
853853 ipts .append (ipt )
@@ -882,7 +882,7 @@ def get_rule_logs_for_vms():
882882 except :
883883 logging .exception ("Failed to get rule logs, better luck next time!" )
884884
885- print (";" .join (result ))
885+ print (( ";" .join (result ) ))
886886
887887
888888def cleanup_rules_for_dead_vms ():
@@ -897,7 +897,7 @@ def cleanup_bridge(bridge):
897897
898898 # Delete iptables/bridge rules
899899 rules = execute ("""iptables-save | grep %s | grep '^-A' | sed 's/-A/-D/' """ % bridge_name ).split ("\n " )
900- for rule in filter ( None , rules ) :
900+ for rule in [ _f for _f in rules if _f ] :
901901 try :
902902 command = "iptables " + rule
903903 execute (command )
@@ -945,13 +945,13 @@ def cleanup_rules():
945945 cleanup .append (vm_name )
946946
947947 bridge_tables = execute ("""grep -E '^ebtable_' /proc/modules | cut -f1 -d' ' | sed s/ebtable_//""" ).split ('\n ' )
948- for table in filter ( None , bridge_tables ) :
948+ for table in [ _f for _f in bridge_tables if _f ] :
949949 chainscmd = """ebtables -t %s -L | awk '/chain:/ { gsub(/(^.*chain: |-(in|out|ips).*)/, ""); print $1}' | sort | uniq""" % table
950950 chains = execute (chainscmd ).split ('\n ' )
951951
952952 logging .debug (" ebtables chains in the host: %s " , chains )
953953
954- for chain in filter ( None , chains ) :
954+ for chain in [ _f for _f in chains if _f ] :
955955 if 1 in [chain .startswith (c ) for c in ['r-' , 'i-' , 's-' , 'v-' ]]:
956956 vm_name = chain
957957 vmpresent = False
@@ -1421,7 +1421,7 @@ def verify_ipset_for_vm(vm_name, vm_id, vm_ips, vm_ip6):
14211421 found = True
14221422 break
14231423 if not found :
1424- print ("vm ip %s is not found" % vm_ip )
1424+ print (( "vm ip %s is not found" % vm_ip ) )
14251425 return False
14261426
14271427 rules = []
@@ -1435,7 +1435,7 @@ def verify_ipset_for_vm(vm_name, vm_id, vm_ips, vm_ip6):
14351435 found = True
14361436 break
14371437 if not found :
1438- print ("vm ipv6 %s is not found" % vm_ip6 )
1438+ print (( "vm ipv6 %s is not found" % vm_ip6 ) )
14391439 return False
14401440
14411441 return True
@@ -1574,7 +1574,7 @@ def verify_expected_rules_exist(expected_rules, rules):
15741574 found = True
15751575 break
15761576 if not found :
1577- print ("Rule '%s' is not found" % expected_rule )
1577+ print (( "Rule '%s' is not found" % expected_rule ) )
15781578 return False
15791579 return True
15801580
@@ -1585,7 +1585,7 @@ def verify_expected_rules_in_order(expected_rules, rules):
15851585 if i < len (expected_rules ) and rule == expected_rules [i ]:
15861586 i += 1
15871587 if i != len (expected_rules ):
1588- print ("Cannot find rule '%s'" % expected_rules [i ])
1588+ print (( "Cannot find rule '%s'" % expected_rules [i ]) )
15891589 return False
15901590 return True
15911591
0 commit comments