Skip to content

Commit 57f6b16

Browse files
committed
bug 8719: fixed NPE happening during HA process - get control nic infrormation in finalizeCommandsOnStart() method instead of setting it in caller methods
status 8719: resolved fixed
1 parent 54b3fff commit 57f6b16

4 files changed

Lines changed: 69 additions & 51 deletions

File tree

‎server/src/com/cloud/consoleproxy/ConsoleProxyManagerImpl.java‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,6 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<ConsoleProxyV
13881388
externalDhcp = true;
13891389
}
13901390

1391-
NicProfile controlNic = null;
1392-
NicProfile managementNic = null;
13931391
for (NicProfile nic : profile.getNics()) {
13941392
int deviceId = nic.getDeviceId();
13951393
if(nic.getIp4Address() == null) {
@@ -1410,31 +1408,19 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<ConsoleProxyV
14101408

14111409
if (nic.getTrafficType() == TrafficType.Management) {
14121410
buf.append(" localgw=").append(dest.getPod().getGateway());
1413-
managementNic = nic;
1414-
} else if (nic.getTrafficType() == TrafficType.Control) {
1415-
if(nic.getIp4Address() != null) {
1416-
controlNic = nic;
1417-
}
1418-
}
1411+
}
14191412
}
14201413

14211414
/*External DHCP mode*/
14221415
if(externalDhcp) {
14231416
buf.append(" bootproto=dhcp");
14241417
}
14251418

1426-
if(controlNic == null) {
1427-
assert(managementNic != null);
1428-
controlNic = managementNic;
1429-
}
1430-
14311419
String bootArgs = buf.toString();
14321420
if (s_logger.isDebugEnabled()) {
14331421
s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
14341422
}
14351423

1436-
profile.setParameter(VirtualMachineProfile.Param.ControlNic, controlNic);
1437-
14381424
return true;
14391425
}
14401426

@@ -1462,7 +1448,22 @@ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<ConsolePr
14621448

14631449
@Override
14641450
public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<ConsoleProxyVO> profile) {
1465-
NicProfile controlNic = (NicProfile)profile.getParameter(VirtualMachineProfile.Param.ControlNic);
1451+
1452+
NicProfile managementNic = null;
1453+
NicProfile controlNic = null;
1454+
for (NicProfile nic : profile.getNics()) {
1455+
if (nic.getTrafficType() == TrafficType.Management) {
1456+
managementNic = nic;
1457+
} else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) {
1458+
controlNic = nic;
1459+
}
1460+
}
1461+
1462+
if (controlNic == null) {
1463+
assert (managementNic != null);
1464+
controlNic = managementNic;
1465+
}
1466+
14661467
CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20);
14671468
cmds.addCommand("checkSsh", check);
14681469

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,6 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<DomainRouterV
934934
throw new CloudRuntimeException("Didn't start a control port");
935935
}
936936

937-
profile.setParameter(VirtualMachineProfile.Param.ControlNic, controlNic);
938-
939937
return true;
940938
}
941939

@@ -964,9 +962,21 @@ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<DomainRou
964962

965963
@Override
966964
public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<DomainRouterVO> profile) {
967-
DomainRouterVO router = profile.getVirtualMachine();
968-
NicProfile controlNic = (NicProfile) profile.getParameter(VirtualMachineProfile.Param.ControlNic);
969-
cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20));
965+
DomainRouterVO router = profile.getVirtualMachine();
966+
967+
NicProfile controlNic = null;
968+
for (NicProfile nic : profile.getNics()) {
969+
if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) {
970+
controlNic = nic;
971+
}
972+
}
973+
974+
if (controlNic == null) {
975+
s_logger.error("Control network doesn't exist for the router " + router);
976+
return false;
977+
}
978+
979+
cmds.addCommand("checkSsh", new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20));
970980

971981
//restart network if restartNetwork = false is not specified in profile parameters
972982
boolean restartNetwork = true;

‎server/src/com/cloud/storage/secondary/SecondaryStorageManagerImpl.java‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,6 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<SecondaryStor
984984
buf.append(" instance=SecStorage");
985985
buf.append(" sslcopy=").append(Boolean.toString(_useSSlCopy));
986986

987-
NicProfile controlNic = null;
988-
NicProfile managementNic = null;
989-
990987
boolean externalDhcp = false;
991988
String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled");
992989
if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) {
@@ -1009,12 +1006,7 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<SecondaryStor
10091006
}
10101007
if (nic.getTrafficType() == TrafficType.Management) {
10111008
buf.append(" localgw=").append(dest.getPod().getGateway());
1012-
managementNic = nic;
10131009
buf.append(" private.network.device=").append("eth").append(deviceId);
1014-
} else if (nic.getTrafficType() == TrafficType.Control) {
1015-
if (nic.getIp4Address() != null) {
1016-
controlNic = nic;
1017-
}
10181010
} else if (nic.getTrafficType() == TrafficType.Public) {
10191011
buf.append(" public.network.device=").append("eth").append(deviceId);
10201012
}
@@ -1025,11 +1017,6 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<SecondaryStor
10251017
buf.append(" bootproto=dhcp");
10261018
}
10271019

1028-
if (controlNic == null) {
1029-
assert (managementNic != null);
1030-
controlNic = managementNic;
1031-
}
1032-
10331020
DataCenterVO dc = _dcDao.findById(profile.getVirtualMachine().getDataCenterId());
10341021
buf.append(" dns1=").append(dc.getInternalDns1());
10351022
if (dc.getInternalDns2() != null) {
@@ -1041,8 +1028,6 @@ public boolean finalizeVirtualMachineProfile(VirtualMachineProfile<SecondaryStor
10411028
s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
10421029
}
10431030

1044-
profile.setParameter(VirtualMachineProfile.Param.ControlNic, controlNic);
1045-
10461031
return true;
10471032
}
10481033

@@ -1072,7 +1057,22 @@ public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile<Secondary
10721057

10731058
@Override
10741059
public boolean finalizeCommandsOnStart(Commands cmds, VirtualMachineProfile<SecondaryStorageVmVO> profile) {
1075-
NicProfile controlNic = (NicProfile) profile.getParameter(VirtualMachineProfile.Param.ControlNic);
1060+
1061+
NicProfile managementNic = null;
1062+
NicProfile controlNic = null;
1063+
for (NicProfile nic : profile.getNics()) {
1064+
if (nic.getTrafficType() == TrafficType.Management) {
1065+
managementNic = nic;
1066+
} else if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) {
1067+
controlNic = nic;
1068+
}
1069+
}
1070+
1071+
if (controlNic == null) {
1072+
assert (managementNic != null);
1073+
controlNic = managementNic;
1074+
}
1075+
10761076
CheckSshCommand check = new CheckSshCommand(profile.getInstanceName(), controlNic.getIp4Address(), 3922, 5, 20);
10771077
cmds.addCommand("checkSsh", check);
10781078

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,26 +1331,33 @@ protected Command compareState(VMInstanceVO vm, final AgentVmInfo info, final bo
13311331

13321332
Commands cmds = new Commands(OnError.Revert);
13331333
s_logger.debug("Finalizing commands that need to be send to complete Start process for the vm " + vm);
1334-
vmGuru.finalizeCommandsOnStart(cmds, profile);
13351334

1336-
if (cmds.size() != 0) {
1337-
try {
1338-
_agentMgr.send(vm.getHostId(), cmds);
1339-
} catch (OperationTimedoutException e){
1340-
s_logger.error("Exception during update for running vm: " + vm, e);
1341-
return null;
1342-
} catch (ResourceUnavailableException e) {
1343-
s_logger.error("Exception during update for running vm: " + vm, e);
1335+
1336+
if (vmGuru.finalizeCommandsOnStart(cmds, profile)) {
1337+
if (cmds.size() != 0) {
1338+
try {
1339+
_agentMgr.send(vm.getHostId(), cmds);
1340+
} catch (OperationTimedoutException e){
1341+
s_logger.error("Exception during update for running vm: " + vm, e);
1342+
return null;
1343+
} catch (ResourceUnavailableException e) {
1344+
s_logger.error("Exception during update for running vm: " + vm, e);
1345+
return null;
1346+
}
1347+
}
1348+
1349+
if (vmGuru.finalizeStart(profile, vm.getHostId(), cmds, null)) {
1350+
stateTransitTo(vm, Event.AgentReportRunning, vm.getHostId());
1351+
} else {
1352+
s_logger.error("Exception during update for running vm: " + vm);
13441353
return null;
13451354
}
1346-
}
1347-
1348-
if (vmGuru.finalizeStart(profile, vm.getHostId(), cmds, null)) {
1349-
stateTransitTo(vm, Event.AgentReportRunning, vm.getHostId());
13501355
} else {
1351-
s_logger.error("Exception during update for running vm: " + vm);
1356+
s_logger.error("Unable to finalize commands on start for vm: " + vm);
13521357
return null;
13531358
}
1359+
1360+
13541361
}
13551362
} else if (serverState == State.Stopping) {
13561363
s_logger.debug("Scheduling a stop command for " + vm);

0 commit comments

Comments
 (0)