Skip to content

Commit ac820f0

Browse files
committed
securitygroup: Ubuntu 20.04 fix systemvm cannot start up (apache#4303)
* security_group.py: fix SyntaxWarning: "is" with a literal. 2020-04-27 09:43:54,172 DEBUG [kvm.resource.LibvirtComputingResource] (Agent-Handler-2:null) (logid:c33ba330) /usr/share/cloudstack-common/scripts/vm/network/security_group.py:513: SyntaxWarning: "is" with a literal. Did you mean "=="? if rules is None or rules is "": /usr/share/cloudstack-common/scripts/vm/network/security_group.py:522: SyntaxWarning: "is" with a literal. Did you mean "=="? if rules is None or rules is "": /usr/share/cloudstack-common/scripts/vm/network/security_group.py:823: SyntaxWarning: "is" with a literal. Did you mean "=="? if brName is None or brName is "": * Ubuntu 20.04: Fix systemvm cannot start up in Ubuntu 16.04: root@node13:~# bridge -o link show 2: eth0 state UP : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloudbr0 state forwarding priority 32 cost 100 5: vnet0 state UNKNOWN : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloud0 state forwarding priority 32 cost 100 6: vnet1 state UNKNOWN : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloudbr0 state forwarding priority 32 cost 100 7: vnet2 state UNKNOWN : <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloudbr0 state forwarding priority 32 cost 100 root@node13:~# bridge -o link show | awk '/master cloudbr0 / && !/^[0-9]+: vnet/ {print $2}' | head -1 eth0 root@node13:~# bridge -o link show | awk '/master cloudbr0 / && !/^[0-9]+: vnet/ {print $2}' | head -1 |cut -d ":" -f1 eth0 in Ubuntu 20.04: root@node62:~# bridge -o link show 2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloudbr0 state forwarding priority 32 cost 100 10: vnet3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloud0 state forwarding priority 32 cost 100 11: vnet4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloudbr0 state forwarding priority 32 cost 100 12: vnet5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master cloudbr0 state forwarding priority 32 cost 100 root@node62:~# bridge -o link show | awk '/master cloudbr0 / && !/^[0-9]+: vnet/ {print $2}' | head -1 ens3: root@node62:~# bridge -o link show | awk '/master cloudbr0 / && !/^[0-9]+: vnet/ {print $2}' | head -1 |cut -d ':' -f1 ens3 * security_group.py: use 'if not' instead
1 parent be56d57 commit ac820f0

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

scripts/vm/network/security_group.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def destroy_network_rules_for_nic(vm_name, vm_ip, vm_mac, vif, sec_ips):
185185
logging.debug("Ignoring failure to delete ebtable rules for vm: " + vm_name)
186186

187187
def get_bridge_physdev(brname):
188-
physdev = execute("bridge -o link show | awk '/master %s / && !/^[0-9]+: vnet/ {print $2}' | head -1" % brname)
188+
physdev = execute("bridge -o link show | awk '/master %s / && !/^[0-9]+: vnet/ {print $2}' | head -1 | cut -d ':' -f1" % brname)
189189
return physdev.strip()
190190

191191

@@ -510,7 +510,7 @@ def check_default_network_rules(vm_name, vm_id, vm_ip, vm_ip6, vm_mac, vif, brna
510510
rules = execute("iptables-save |grep -w %s |grep -w %s |grep -w %s" % (brfw, vif, vmchain_default))
511511
except:
512512
rules = None
513-
if rules is None or rules is "":
513+
if not rules:
514514
logging.debug("iptables rules do not exist, programming default rules for %s %s" % (vm_name,vif))
515515
default_network_rules(vm_name, vm_id, vm_ip, vm_ip6, vm_mac, vif, brname, sec_ips, is_first_nic)
516516
else:
@@ -519,7 +519,7 @@ def check_default_network_rules(vm_name, vm_id, vm_ip, vm_ip6, vm_mac, vif, brna
519519
rules = execute("ebtables -t nat -L PREROUTING | grep %s |grep -w %s" % (vmchain_in, vif))
520520
except:
521521
rules = None
522-
if rules is None or rules is "":
522+
if not rules:
523523
logging.debug("ebtables rules do not exist, programming default ebtables rules for %s %s" % (vm_name,vif))
524524
default_ebtables_rules(vm_name, vm_ip, vm_mac, vif, is_first_nic)
525525
ips = sec_ips.split(';')
@@ -820,7 +820,7 @@ def network_rules_for_rebooted_vm(vmName):
820820
delete_rules_for_vm_in_bridge_firewall_chain(vm_name)
821821

822822
brName = execute("iptables-save | awk -F '-j ' '/FORWARD -o(.*)physdev-is-bridged(.*)BF/ {print $2}'").strip()
823-
if brName is None or brName is "":
823+
if not brName:
824824
brName = "cloudbr0"
825825
else:
826826
brName = execute("iptables-save |grep physdev-is-bridged |grep FORWARD |grep BF |grep '\-o' |awk '{print $4}' | head -1").strip()
@@ -1368,13 +1368,13 @@ def verify_network_rules(vm_name, vm_id, vm_ip, vm_ip6, vm_mac, vif, brname, sec
13681368

13691369
if brname is None:
13701370
brname = execute("virsh domiflist %s |grep -w '%s' |tr -s ' '|cut -d ' ' -f3" % (vm_name, vm_mac)).strip()
1371-
if brname is None or brname == "":
1371+
if not brname:
13721372
print("Cannot find bridge")
13731373
sys.exit(1)
13741374

13751375
if vif is None:
13761376
vif = execute("virsh domiflist %s |grep -w '%s' |tr -s ' '|cut -d ' ' -f1" % (vm_name, vm_mac)).strip()
1377-
if vif is None or vif == "":
1377+
if not vif:
13781378
print("Cannot find vif")
13791379
sys.exit(1)
13801380

0 commit comments

Comments
 (0)