Skip to content

Commit 64a7a1c

Browse files
shwstpprweizhouapache
authored andcommitted
fix
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent 9fe7062 commit 64a7a1c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

server/src/main/java/com/cloud/network/as/AutoScaleManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,8 @@ protected String getTrimmedHostNameForWindows(String name) {
19911991
protected Pair<String, String> getNextVmHostAndDisplayName(AutoScaleVmGroupVO asGroup, VirtualMachineTemplate template) {
19921992
template.getGuestOSId();
19931993
GuestOSVO guestOSVO = guestOSDao.findById(template.getGuestOSId());
1994-
boolean isWindows = guestOSVO != null && guestOSVO.getName().toLowerCase().contains("windows");
1994+
String osName = guestOSVO != null ? StringUtils.firstNonBlank(guestOSVO.getName(), guestOSVO.getDisplayName()) : "";
1995+
boolean isWindows = osName.toLowerCase().contains("windows");
19951996
String vmHostNameSuffix = "-" + asGroup.getNextVmSeq() + "-" +
19961997
RandomStringUtils.random(VM_HOSTNAME_RANDOM_SUFFIX_LENGTH, 0, 0, true, false, (char[])null, new SecureRandom()).toLowerCase();
19971998
// Truncate vm group name because max length of vm name is 63

server/src/test/java/com/cloud/network/as/AutoScaleManagerImplTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,20 +2515,31 @@ public void getNextVmHostAndDisplayNameGeneratesCorrectHostAndDisplayNameForLinu
25152515
Assert.assertEquals(result.first(), result.second());
25162516
}
25172517

2518-
@Test
2519-
public void getNextVmHostAndDisplayNameGeneratesCorrectHostAndDisplayNameForWindowsTemplate() {
2520-
GuestOSVO guestOS = Mockito.mock(GuestOSVO.class);
2518+
private void runGetNextVmHostAndDisplayNameGeneratesCorrectHostAndDisplayNameForWindowsTemplate() {
25212519
when(asVmGroupMock.getName()).thenReturn(vmGroupName);
25222520
when(asVmGroupMock.getNextVmSeq()).thenReturn(1L);
25232521
when(templateMock.getGuestOSId()).thenReturn(1L);
2524-
when(guestOS.getName()).thenReturn("Windows Server");
2525-
when(guestOSDao.findById(1L)).thenReturn(guestOS);
25262522
Pair<String, String> result = autoScaleManagerImplSpy.getNextVmHostAndDisplayName(asVmGroupMock, templateMock);
25272523
String vmHostNamePattern = AutoScaleManagerImpl.VM_HOSTNAME_PREFIX + vmGroupName +
25282524
"-" + asVmGroupMock.getNextVmSeq() + "-[a-z]{6}";
25292525
Assert.assertTrue(result.second().matches(vmHostNamePattern));
25302526
Assert.assertEquals(15, result.first().length());
25312527
Assert.assertTrue(result.second().endsWith(result.first()));
2528+
2529+
}
2530+
2531+
@Test
2532+
public void getNextVmHostAndDisplayNameGeneratesCorrectHostAndDisplayNameForWindowsTemplateUsingGuestOsName() {
2533+
GuestOSVO guestOS = Mockito.mock(GuestOSVO.class);
2534+
when(guestOS.getName()).thenReturn("Windows Server");
2535+
when(guestOSDao.findById(1L)).thenReturn(guestOS);
2536+
}
2537+
2538+
@Test
2539+
public void getNextVmHostAndDisplayNameGeneratesCorrectHostAndDisplayNameForWindowsTemplateUsingGuestOsDisplayName() {
2540+
GuestOSVO guestOS = Mockito.mock(GuestOSVO.class);
2541+
when(guestOS.getDisplayName()).thenReturn("Windows Server");
2542+
when(guestOSDao.findById(1L)).thenReturn(guestOS);
25322543
}
25332544

25342545
@Test

0 commit comments

Comments
 (0)