Skip to content

Commit 8e4e56f

Browse files
committed
CLOUDSTACK-3409: Do not clean up security group rules for Instances in the "paused" state.
When 'security_group.py cleanup_rules' is called by the KVM Agent it will clean up all Instances not in the "running" state according to libvirt. However, when a snapshot is created of a Instance it will go to the "paused" state while the snapshot is created. This leads to Security Rules being removed when a Instance is being snapshotted and the cleanup process is initiated.
1 parent d65f47c commit 8e4e56f

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

scripts/vm/network/security_group.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -621,18 +621,18 @@ def cleanup_rules():
621621
if 1 in [ chain.startswith(c) for c in ['r-', 'i-', 's-', 'v-'] ]:
622622
vm_name = chain
623623

624-
cmd = "virsh list |grep " + vm_name
624+
cmd = "virsh list |grep " + vm_name + "|awk '{print $3}'"
625625
try:
626-
result = execute(cmd)
626+
result = execute(cmd).strip()
627627
except:
628628
result = None
629629

630630
if result == None or len(result) == 0:
631-
logging.debug("chain " + chain + " does not correspond to a vm, cleaning up")
631+
logging.debug("chain " + chain + " does not correspond to a vm, cleaning up iptable rules")
632632
cleanup.append(vm_name)
633633
continue
634-
if result.find("running") == -1:
635-
logging.debug("vm " + vm_name + " is not running, cleaning up")
634+
if not (result == "running" or result == "paused"):
635+
logging.debug("vm " + vm_name + " is not running or paused, cleaning up iptable rules")
636636
cleanup.append(vm_name)
637637

638638
chainscmd = "ebtables-save |grep :i |awk '{print $1}' |sed -e 's/\-in//g' |sed -e 's/\-out//g' |sed -e 's/^://g'"
@@ -641,18 +641,18 @@ def cleanup_rules():
641641
if 1 in [ chain.startswith(c) for c in ['r-', 'i-', 's-', 'v-'] ]:
642642
vm_name = chain
643643

644-
cmd = "virsh list |grep " + vm_name
644+
cmd = "virsh list |grep " + vm_name + "|awk '{print $3}'"
645645
try:
646-
result = execute(cmd)
646+
result = execute(cmd).strip()
647647
except:
648648
result = None
649649

650650
if result == None or len(result) == 0:
651-
logging.debug("chain " + chain + " does not correspond to a vm, cleaning up")
651+
logging.debug("chain " + chain + " does not correspond to a vm, cleaning up ebtable rules")
652652
cleanup.append(vm_name)
653653
continue
654-
if result.find("running") == -1:
655-
logging.debug("vm " + vm_name + " is not running, cleaning up")
654+
if not (result == "running" or result == "paused"):
655+
logging.debug("vm " + vm_name + " is not running or paused, cleaning up ebtable rules")
656656
cleanup.append(vm_name)
657657

658658
for vmname in cleanup:

0 commit comments

Comments
 (0)