Skip to content

Commit a5568b8

Browse files
committed
Last review comments addressed
1 parent 02c21d2 commit a5568b8

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

server/src/main/java/com/cloud/vm/UserVmManagerImpl.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,14 @@ public class UserVmManagerImpl extends ManagerBase implements UserVmManager, Vir
650650
HypervisorType.Simulator
651651
));
652652

653+
protected static final List<HypervisorType> ROOT_DISK_SIZE_OVERRIDE_SUPPORTING_HYPERVISORS = Arrays.asList(
654+
HypervisorType.KVM,
655+
HypervisorType.XenServer,
656+
HypervisorType.VMware,
657+
HypervisorType.Simulator,
658+
HypervisorType.Custom
659+
);
660+
653661
private static final List<HypervisorType> HYPERVISORS_THAT_CAN_DO_STORAGE_MIGRATION_ON_NON_USER_VMS = Arrays.asList(HypervisorType.KVM, HypervisorType.VMware);
654662

655663
@Override
@@ -4327,8 +4335,7 @@ protected long configureCustomRootDiskSize(Map<String, String> customParameters,
43274335
* @throws InvalidParameterValueException if the hypervisor does not support rootdisksize override
43284336
*/
43294337
protected void verifyIfHypervisorSupportsRootdiskSizeOverride(HypervisorType hypervisorType) {
4330-
if (!(hypervisorType == HypervisorType.KVM || hypervisorType == HypervisorType.XenServer ||hypervisorType == HypervisorType.VMware ||
4331-
hypervisorType == HypervisorType.Simulator || hypervisorType == HypervisorType.Custom)) {
4338+
if (!ROOT_DISK_SIZE_OVERRIDE_SUPPORTING_HYPERVISORS.contains(hypervisorType)) {
43324339
throw new InvalidParameterValueException("Hypervisor " + hypervisorType + " does not support rootdisksize override");
43334340
}
43344341
}
@@ -5056,11 +5063,7 @@ public boolean finalizeStart(VirtualMachineProfile profile, long hostId, Command
50565063
}
50575064
}
50585065

5059-
if (returnedVncPassword != null && !originalVncPassword.equals(returnedVncPassword)) {
5060-
UserVmVO userVm = _vmDao.findById(profile.getId());
5061-
userVm.setVncPassword(returnedVncPassword);
5062-
_vmDao.update(userVm.getId(), userVm);
5063-
}
5066+
updateVncPasswordIfItHasChanged(originalVncPassword, returnedVncPassword, profile);
50645067

50655068
// get system ip and create static nat rule for the vm
50665069
try {
@@ -5096,6 +5099,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
50965099
return true;
50975100
}
50985101

5102+
protected void updateVncPasswordIfItHasChanged(String originalVncPassword, String returnedVncPassword, VirtualMachineProfile profile) {
5103+
if (returnedVncPassword != null && !originalVncPassword.equals(returnedVncPassword)) {
5104+
UserVmVO userVm = _vmDao.findById(profile.getId());
5105+
userVm.setVncPassword(returnedVncPassword);
5106+
_vmDao.update(userVm.getId(), userVm);
5107+
}
5108+
}
5109+
50995110
@Override
51005111
public void finalizeExpunge(VirtualMachine vm) {
51015112
}

server/src/test/java/com/cloud/vm/UserVmManagerImplTest.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ public class UserVmManagerImplTest {
221221
@Mock
222222
UserDataManager userDataManager;
223223

224+
@Mock
225+
VirtualMachineProfile virtualMachineProfile;
226+
224227
private static final long vmId = 1l;
225228
private static final long zoneId = 2L;
226229
private static final long accountId = 3L;
@@ -248,6 +251,8 @@ public void beforeTest() {
248251
customParameters.put(VmDetailConstants.ROOT_DISK_SIZE, "123");
249252
lenient().doNothing().when(resourceLimitMgr).incrementResourceCount(anyLong(), any(Resource.ResourceType.class));
250253
lenient().doNothing().when(resourceLimitMgr).decrementResourceCount(anyLong(), any(Resource.ResourceType.class), anyLong());
254+
255+
Mockito.when(virtualMachineProfile.getId()).thenReturn(vmId);
251256
}
252257

253258
@After
@@ -564,11 +569,7 @@ public void verifyIfHypervisorSupportRootdiskSizeOverrideTest() {
564569
int expectedExceptionCounter = hypervisorTypeArray.length - 5;
565570

566571
for(int i = 0; i < hypervisorTypeArray.length; i++) {
567-
if (Hypervisor.HypervisorType.KVM == hypervisorTypeArray[i]
568-
|| Hypervisor.HypervisorType.XenServer == hypervisorTypeArray[i]
569-
|| Hypervisor.HypervisorType.VMware == hypervisorTypeArray[i]
570-
|| Hypervisor.HypervisorType.Custom == hypervisorTypeArray[i]
571-
|| Hypervisor.HypervisorType.Simulator == hypervisorTypeArray[i]) {
572+
if (UserVmManagerImpl.ROOT_DISK_SIZE_OVERRIDE_SUPPORTING_HYPERVISORS.contains(hypervisorTypeArray[i])) {
572573
userVmManagerImpl.verifyIfHypervisorSupportsRootdiskSizeOverride(hypervisorTypeArray[i]);
573574
} else {
574575
try {
@@ -1042,4 +1043,21 @@ public void testChooseVmMigrationDestinationUsingVolumePoolMapValid() {
10421043
Pair<VMInstanceVO, Host> pair = mockObjectsForChooseVmMigrationDestinationUsingVolumePoolMapTest(false, destinationHost);
10431044
Assert.assertEquals(destinationHost, userVmManagerImpl.chooseVmMigrationDestinationUsingVolumePoolMap(pair.first(), pair.second(), null));
10441045
}
1046+
1047+
@Test
1048+
public void testUpdateVncPasswordIfItHasChanged() {
1049+
String vncPassword = "12345678";
1050+
userVmManagerImpl.updateVncPasswordIfItHasChanged(vncPassword, vncPassword, virtualMachineProfile);
1051+
Mockito.verify(userVmDao, Mockito.never()).update(vmId, userVmVoMock);
1052+
}
1053+
1054+
@Test
1055+
public void testUpdateVncPasswordIfItHasChangedNewPassword() {
1056+
String vncPassword = "12345678";
1057+
String newPassword = "87654321";
1058+
Mockito.when(userVmVoMock.getId()).thenReturn(vmId);
1059+
userVmManagerImpl.updateVncPasswordIfItHasChanged(vncPassword, newPassword, virtualMachineProfile);
1060+
Mockito.verify(userVmDao).findById(vmId);
1061+
Mockito.verify(userVmDao).update(vmId, userVmVoMock);
1062+
}
10451063
}

0 commit comments

Comments
 (0)