resolve zstack-14792
@@ -7,13 +7,19 @@ import org.zstack.header.Constants
import org.zstack.kvm.KVMAgentCommands
import org.zstack.kvm.KVMSecurityGroupBackend
import org.zstack.network.securitygroup.APIAddSecurityGroupRuleMsg
+import org.zstack.network.securitygroup.APIChangeSecurityGroupStateMsg
import org.zstack.network.securitygroup.SecurityGroupMembersTO
import org.zstack.network.securitygroup.SecurityGroupRuleProtocolType
+import org.zstack.network.securitygroup.SecurityGroupRuleState
import org.zstack.network.securitygroup.SecurityGroupRuleTO
import org.zstack.network.securitygroup.SecurityGroupRuleType
+import org.zstack.network.securitygroup.SecurityGroupRuleVO
+import org.zstack.network.securitygroup.SecurityGroupRuleVO_
+import org.zstack.network.securitygroup.SecurityGroupVO
import org.zstack.network.securitygroup.VmNicSecurityGroupRefVO
import org.zstack.network.securitygroup.VmNicSecurityGroupRefVO_
import org.zstack.sdk.AddSecurityGroupRuleAction
+import org.zstack.sdk.ChangeSecurityGroupStateAction
import org.zstack.sdk.HostInventory
import org.zstack.sdk.SecurityGroupInventory
import org.zstack.sdk.VmInstanceInventory
@@ -89,6 +95,7 @@ class AddRulesRemoteGroupsCase extends SubCase{
testDeleteSecurityGroup(sg3.uuid, [host1.uuid, host2.uuid, host3.uuid])
testAddDuplicateRule(sg1.uuid, sg2.uuid)
+ testChangeState(sg1.uuid)
}
}
@@ -215,6 +222,56 @@ class AddRulesRemoteGroupsCase extends SubCase{
}
}
+ void testChangeState(String sgUuid){
+
+ changeSecurityGroupState {
+ uuid = sgUuid
+ stateEvent = "disable"
+ }
+
+ boolean called = false
+ KVMAgentCommands.ApplySecurityGroupRuleCmd cmd
+ APIAddSecurityGroupRuleMsg.SecurityGroupRuleAO rulex = returnRandomRule()
+ env.simulator(KVMSecurityGroupBackend.SECURITY_GROUP_APPLY_RULE_PATH ){ HttpEntity<String> e ->
+ called = true
+ cmd = JSONObjectUtil.toObject(e.getBody(), KVMAgentCommands.ApplySecurityGroupRuleCmd.class)
+ return new KVMAgentCommands.ApplySecurityGroupRuleResponse()
+ }
+
+ addSecurityGroupRule {
+ rules = [rulex]
+ securityGroupUuid = sgUuid
+ }
+
+ retryInSecs {
+ assert !called
+ }
+ List<SecurityGroupRuleVO> rules = Q.New(SecurityGroupRuleVO.class).eq(SecurityGroupRuleVO_.securityGroupUuid, sgUuid).list()
+ assert rules.get(0).state == SecurityGroupRuleState.Disabled
+
+ changeSecurityGroupState {
+ uuid = sgUuid
+ stateEvent = "enable"
+ }
+
+
+ called = false
+ APIAddSecurityGroupRuleMsg.SecurityGroupRuleAO rulexx = returnRandomRule()
+
+ addSecurityGroupRule {
+ delegate.rules = [rulexx]
+ securityGroupUuid = sgUuid
+ }
+
+ retryInSecs {
+ assert called
+ assert cmd != null
+ assert sgUuid == cmd.getRuleTOs().get(0).getRules().get(0).securityGroupUuid
+ rules = Q.New(SecurityGroupRuleVO.class).eq(SecurityGroupRuleVO_.securityGroupUuid, sgUuid).list()
+ assert rules.get(0).state == SecurityGroupRuleState.Enabled
+ }
+ }
+
private void addRule(String sgUuid, int ruleCounts, int existedRuleCount){
addRule(sgUuid, ruleCounts, null, existedRuleCount)
}
