Skip to content

Commit

Permalink
when delete l3network, iprange, virtual router will not be deleted
Browse files Browse the repository at this point in the history
if the l3 network is not guest network, or public network, managment network

fix ZSTAC-10692
  • Loading branch information
ruansteve committed Mar 31, 2018
1 parent 2302ab9 commit 9cb7700
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 1 deletion.
1 change: 1 addition & 0 deletions conf/springConfigXml/VirtualRouter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<zstack:extension interface="org.zstack.header.query.AddExpandedQueryExtensionPoint" />
<zstack:extension interface="org.zstack.network.service.eip.FilterVmNicsForEipInVirtualRouterExtensionPoint" />
<zstack:extension interface="org.zstack.network.service.lb.GetCandidateVmNicsForLoadBalancerExtensionPoint"/>
<zstack:extension interface="org.zstack.appliancevm.ApvmCascadeFilterExtensionPoint"/>
</zstack:plugin>
</bean>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

public class VirtualRouterManagerImpl extends AbstractService implements VirtualRouterManager,
PrepareDbInitialValueExtensionPoint, L2NetworkCreateExtensionPoint,
GlobalApiMessageInterceptor, AddExpandedQueryExtensionPoint, GetCandidateVmNicsForLoadBalancerExtensionPoint, FilterVmNicsForEipInVirtualRouterExtensionPoint {
GlobalApiMessageInterceptor, AddExpandedQueryExtensionPoint, GetCandidateVmNicsForLoadBalancerExtensionPoint, FilterVmNicsForEipInVirtualRouterExtensionPoint, ApvmCascadeFilterExtensionPoint {
private final static CLogger logger = Utils.getLogger(VirtualRouterManagerImpl.class);

private final static List<String> supportedL2NetworkTypes = new ArrayList<String>();
Expand Down Expand Up @@ -1417,4 +1417,41 @@ protected List<VmNicInventory> scripts() {
}
}.execute();
}

private List<ApplianceVmVO> applianceVmsToBeDeleted(List<ApplianceVmVO> applianceVmVOS, List<String> deletedUuids) {
List<ApplianceVmVO> vos = new ArrayList<>();
for (ApplianceVmVO vo : applianceVmVOS) {
VirtualRouterVmInventory vrInv = VirtualRouterVmInventory.valueOf(dbf.findByUuid(vo.getUuid(), VirtualRouterVmVO.class));

List<String> l3Uuids = new ArrayList<>();
l3Uuids.addAll(vrInv.getGuestL3Networks());
l3Uuids.add(vrInv.getPublicNetworkUuid());
l3Uuids.add(vrInv.getManagementNetworkUuid());
for(String uuid: l3Uuids) {
if (deletedUuids.contains(uuid)) {
vos.add(vo);
break;
}
}
}
return vos;
}

@Override
public List<ApplianceVmVO> filterApplianceVmCascade(List<ApplianceVmVO> applianceVmVOS, String parentIssuer, List<String> parentIssuerUuids) {

if (parentIssuer.equals(L3NetworkVO.class.getSimpleName())) {
return applianceVmsToBeDeleted(applianceVmVOS, parentIssuerUuids);
} else if (parentIssuer.equals(IpRangeVO.class.getSimpleName())) {
final List<String> iprL3Uuids = CollectionUtils.transformToList((List<String>) parentIssuerUuids, new Function<String, String>() {
@Override
public String call(String arg) {
return Q.New(IpRangeVO.class).eq(IpRangeVO_.uuid, arg).select(IpRangeVO_.l3NetworkUuid).findValue();
}
});
return applianceVmsToBeDeleted(applianceVmVOS, iprL3Uuids);
} else {
return applianceVmVOS;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.zstack.test.integration.networkservice.provider.virtualrouter

import org.zstack.core.db.DatabaseFacade
import org.zstack.core.db.Q
import org.zstack.header.vm.VmNicVO
import org.zstack.network.service.virtualrouter.VirtualRouterVmVO
import org.zstack.sdk.IpRangeInventory
import org.zstack.sdk.L2NetworkInventory
import org.zstack.sdk.L3NetworkInventory
import org.zstack.sdk.VmInstanceInventory
import org.zstack.test.integration.networkservice.provider.NetworkServiceProviderTest
import org.zstack.testlib.EnvSpec
import org.zstack.testlib.SubCase

/**
* Created by shixin on 03/30/2018.
*/
class VirtualRouterDeletePublicNetworkCase extends SubCase {

EnvSpec env
DatabaseFacade dbf

@Override
void setup() {
useSpring(NetworkServiceProviderTest.springSpec)
}

@Override
void environment() {
env = VirtualRouterNetworkServiceEnv.oneVmOneHostVyosOnEipEnv()
}

@Override
void test() {
env.create {
testDeleteAdditionalPublicNetwork()
}
}

void testDeleteAdditionalPublicNetwork() {
def l2 = env.inventoryByName("l2") as L2NetworkInventory
def pub = env.inventoryByName("pubL3") as L3NetworkInventory

L3NetworkInventory l3_1 = createL3Network {
delegate.category = "Public"
delegate.l2NetworkUuid = l2.uuid
delegate.name = "pubL3-2"
}

addIpRange {
delegate.name = "TestIpRange"
delegate.l3NetworkUuid = l3_1.uuid
delegate.startIp = "11.168.200.10"
delegate.endIp = "11.168.200.253"
delegate.gateway = "11.168.200.1"
delegate.netmask = "255.255.255.0"
}

VirtualRouterVmVO vr = Q.New(VirtualRouterVmVO.class).find()

VmInstanceInventory inv = attachL3NetworkToVm {
delegate.l3NetworkUuid = l3_1.getUuid()
delegate.vmInstanceUuid = vr.uuid
}

deleteL3Network {
uuid = l3_1.uuid
}

vr = Q.New(VirtualRouterVmVO.class).find()
assert vr != null
assert vr.getPublicNetworkUuid() == pub.uuid
assert vr.getManagementNetworkUuid() == pub.uuid
for (VmNicVO nic : vr.getVmNics()) {
assert nic.l3NetworkUuid != l3_1.uuid
}
}

@Override
void clean() {
env.delete()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package org.zstack.test.integration.networkservice.provider.virtualrouter

import org.zstack.core.db.DatabaseFacade
import org.zstack.core.db.Q
import org.zstack.header.vm.VmNicVO
import org.zstack.network.service.virtualrouter.VirtualRouterVmVO
import org.zstack.sdk.IpRangeInventory
import org.zstack.sdk.L2NetworkInventory
import org.zstack.sdk.L3NetworkInventory
import org.zstack.sdk.VmInstanceInventory
import org.zstack.test.integration.networkservice.provider.NetworkServiceProviderTest
import org.zstack.testlib.EnvSpec
import org.zstack.testlib.SubCase

/**
* Created by shixin on 03/30/2018.
*/
class VirtualRouterDeletePublicNetworkIpRangeCase extends SubCase {

EnvSpec env
DatabaseFacade dbf

@Override
void setup() {
useSpring(NetworkServiceProviderTest.springSpec)
}

@Override
void environment() {
env = VirtualRouterNetworkServiceEnv.oneVmOneHostVyosOnEipEnv()
}

@Override
void test() {
env.create {
testDeleteAdditionalPublicIpRange()
}
}

void testDeleteAdditionalPublicIpRange() {
def l2 = env.inventoryByName("l2") as L2NetworkInventory
def pub = env.inventoryByName("pubL3") as L3NetworkInventory

L3NetworkInventory l3_1 = createL3Network {
delegate.category = "Public"
delegate.l2NetworkUuid = l2.uuid
delegate.name = "pubL3-2"
}

IpRangeInventory iprInv = addIpRange {
delegate.name = "TestIpRange"
delegate.l3NetworkUuid = l3_1.uuid
delegate.startIp = "11.168.200.10"
delegate.endIp = "11.168.200.253"
delegate.gateway = "11.168.200.1"
delegate.netmask = "255.255.255.0"
}

VirtualRouterVmVO vr = Q.New(VirtualRouterVmVO.class).find()
assert vr != null
assert vr.getPublicNetworkUuid() == pub.uuid
assert vr.getManagementNetworkUuid() == pub.uuid

VmInstanceInventory inv = attachL3NetworkToVm {
delegate.l3NetworkUuid = l3_1.getUuid()
delegate.vmInstanceUuid = vr.uuid
}

deleteIpRange {
uuid = iprInv.uuid
}

vr = Q.New(VirtualRouterVmVO.class).find()
assert vr != null
assert vr.getPublicNetworkUuid() == pub.uuid
assert vr.getManagementNetworkUuid() == pub.uuid
}

@Override
void clean() {
env.delete()
}
}

0 comments on commit 9cb7700

Please sign in to comment.