Skip to content

Commit b727001

Browse files
author
Alena Prokharchyk
committed
CLOUDSTACK-4315: VPC - when fail to add nic to the VR, a) remove the nic b) remove the reference to nic from router_network_ref table. Before the fix b) was missing, and it caused NPEs when tried to apply the rules on the routers not having nic in the network
Conflicts: server/src/com/cloud/network/element/VirtualRouterElement.java server/src/com/cloud/vm/VirtualMachineManagerImpl.java
1 parent bea095f commit b727001

4 files changed

Lines changed: 24 additions & 37 deletions

File tree

‎server/src/com/cloud/network/element/VirtualRouterElement.java‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
2929
import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
3030
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
31+
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3132

3233
import org.apache.log4j.Logger;
3334

34-
import com.cloud.agent.api.PvlanSetupCommand;
3535
import com.cloud.agent.api.to.LoadBalancerTO;
3636
import com.cloud.configuration.ConfigurationManager;
3737
import com.cloud.dc.DataCenter;
@@ -50,7 +50,6 @@
5050
import com.cloud.network.NetworkMigrationResponder;
5151
import com.cloud.network.NetworkModel;
5252
import com.cloud.network.Networks;
53-
import com.cloud.network.Networks.BroadcastDomainType;
5453
import com.cloud.network.Networks.TrafficType;
5554
import com.cloud.network.PhysicalNetworkServiceProvider;
5655
import com.cloud.network.PublicIpAddress;
@@ -87,7 +86,6 @@
8786
import com.cloud.utils.exception.CloudRuntimeException;
8887
import com.cloud.vm.DomainRouterVO;
8988
import com.cloud.vm.NicProfile;
90-
import com.cloud.vm.NicVO;
9189
import com.cloud.vm.ReservationContext;
9290
import com.cloud.vm.UserVmManager;
9391
import com.cloud.vm.UserVmVO;
@@ -100,22 +98,6 @@
10098

10199
import com.google.gson.Gson;
102100

103-
import org.apache.cloudstack.api.command.admin.router.ConfigureVirtualRouterElementCmd;
104-
import org.apache.cloudstack.api.command.admin.router.CreateVirtualRouterElementCmd;
105-
import org.apache.cloudstack.api.command.admin.router.ListVirtualRouterElementsCmd;
106-
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
107-
108-
import org.apache.log4j.Logger;
109-
110-
import javax.ejb.Local;
111-
import javax.inject.Inject;
112-
113-
import java.util.ArrayList;
114-
import java.util.HashMap;
115-
import java.util.List;
116-
import java.util.Map;
117-
import java.util.Set;
118-
119101
@Local(value = {NetworkElement.class, FirewallServiceProvider.class,
120102
DhcpServiceProvider.class, UserDataServiceProvider.class,
121103
StaticNatServiceProvider.class, LoadBalancingServiceProvider.class,
@@ -390,7 +372,7 @@ public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) thro
390372

391373
List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
392374
if (routers == null || routers.isEmpty()) {
393-
s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " +
375+
s_logger.debug("Virtual router elemnt doesn't need to apply lb rules on the backend; virtual " +
394376
"router doesn't exist in the network " + network.getId());
395377
return true;
396378
}

‎server/src/com/cloud/network/element/VpcVirtualRouterElement.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ public boolean applyACLItemsToPrivateGw(PrivateGateway gateway,List<? extends Ne
464464
} else {
465465
return true;
466466
}
467-
468467
}
469468

470469

‎server/src/com/cloud/network/router/VpcVirtualNetworkApplianceManagerImpl.java‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -287,23 +287,27 @@ public boolean removeVpcRouterFromGuestNetwork(VirtualRouter router, Network net
287287
return false;
288288
}
289289

290-
//Check if router is a part of the Guest network
291-
if (!_networkModel.isVmPartOfNetwork(router.getId(), network.getId())) {
292-
s_logger.debug("Router " + router + " is not a part of the Guest network " + network);
293-
return true;
294-
}
295-
296-
boolean result = setupVpcGuestNetwork(network, router, false, _networkModel.getNicProfile(router, network.getId(), null));
297-
if (!result) {
298-
s_logger.warn("Failed to destroy guest network config " + network + " on router " + router);
299-
return false;
300-
}
301-
302-
result = result && _itMgr.removeVmFromNetwork(router, network, null);
303-
304-
if (result) {
290+
boolean result = true;
291+
try {
292+
//Check if router is a part of the Guest network
293+
if (!_networkModel.isVmPartOfNetwork(router.getId(), network.getId())) {
294+
s_logger.debug("Router " + router + " is not a part of the Guest network " + network);
295+
return result;
296+
}
297+
298+
result = setupVpcGuestNetwork(network, router, false, _networkModel.getNicProfile(router, network.getId(), null));
299+
if (!result) {
300+
s_logger.warn("Failed to destroy guest network config " + network + " on router " + router);
301+
return false;
302+
}
303+
304+
result = result && _itMgr.removeVmFromNetwork(router, network, null);
305+
} finally {
306+
if (result) {
305307
_routerDao.removeRouterFromGuestNetwork(router.getId(), network.getId());
306308
}
309+
}
310+
307311
return result;
308312
}
309313

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,9 @@ public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile
27992799
return null;
28002800
}
28012801
} finally {
2802-
if (!result) {
2802+
if (!result){
2803+
s_logger.debug("Removing nic " + nic + " from vm " + vmProfile.getVirtualMachine()
2804+
+ " as nic plug failed on the backend");
28032805
_networkMgr.removeNic(vmProfile, _nicsDao.findById(nic.getId()));
28042806
}
28052807
}

0 commit comments

Comments
 (0)