Skip to content

Commit 935113f

Browse files
committed
Removed unnecessary code from getGuestOsType in CitrixResourceBase
1 parent 94a1448 commit 935113f

File tree

11 files changed

+171
-22
lines changed

11 files changed

+171
-22
lines changed

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import java.util.UUID;
4545
import java.util.concurrent.TimeoutException;
4646

47-
import javax.ejb.Local;
4847
import javax.naming.ConfigurationException;
4948
import javax.xml.parsers.DocumentBuilderFactory;
5049
import javax.xml.parsers.ParserConfigurationException;
@@ -164,7 +163,6 @@
164163
* before you do any changes in this code here.
165164
*
166165
*/
167-
@Local(value = ServerResource.class)
168166
public abstract class CitrixResourceBase implements ServerResource, HypervisorResource, VirtualRouterDeployer {
169167

170168
public enum SRType {
@@ -1232,7 +1230,7 @@ public VIF createVif(final Connection conn, final String vmName, final VM vm, fi
12321230
}
12331231

12341232
public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmSpec, final Host host) throws XenAPIException, XmlRpcException {
1235-
final String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD);
1233+
final String guestOsTypeName = getGuestOsType(vmSpec.getPlatformEmulator());
12361234
final Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName);
12371235
if (templates == null || templates.isEmpty()) {
12381236
throw new CloudRuntimeException("Cannot find template " + guestOsTypeName + " on XenServer host");
@@ -1337,7 +1335,7 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS
13371335
final TemplateObjectTO iso = (TemplateObjectTO) disk.getData();
13381336
final String osType = iso.getGuestOsType();
13391337
if (osType != null) {
1340-
final String isoGuestOsName = getGuestOsType(osType, vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD);
1338+
final String isoGuestOsName = getGuestOsType(vmSpec.getPlatformEmulator());
13411339
if (!isoGuestOsName.equals(guestOsTypeName)) {
13421340
vmSpec.setBootloader(BootloaderType.PyGrub);
13431341
}
@@ -2019,8 +2017,8 @@ public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final
20192017
return null;
20202018
}
20212019

2022-
protected String getGuestOsType(final String stdType, String platformEmulator, final boolean bootFromCD) {
2023-
if (platformEmulator == null) {
2020+
protected String getGuestOsType(String platformEmulator) {
2021+
if (org.apache.commons.lang.StringUtils.isBlank(platformEmulator)) {
20242022
s_logger.debug("no guest OS type, start it as HVM guest");
20252023
platformEmulator = "Other install media";
20262024
}

plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/XcpOssResource.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717

1818
package com.cloud.hypervisor.xenserver.resource;
1919

20-
import javax.ejb.Local;
21-
2220
import org.apache.xmlrpc.XmlRpcException;
2321

24-
import com.cloud.resource.ServerResource;
2522
import com.xensource.xenapi.Connection;
2623
import com.xensource.xenapi.Types.XenAPIException;
2724
import com.xensource.xenapi.VM;
2825

29-
@Local(value = ServerResource.class)
3026
public class XcpOssResource extends CitrixResourceBase {
3127

3228
private static final long mem_32m = 33554432L;
@@ -36,18 +32,6 @@ protected String getPatchFilePath() {
3632
return "scripts/vm/hypervisor/xenserver/xcposs/patch";
3733
}
3834

39-
@Override
40-
protected String getGuestOsType(final String stdType,
41-
final String platformEmulator, final boolean bootFromCD) {
42-
if (stdType.equalsIgnoreCase("Debian GNU/Linux 6(64-bit)")) {
43-
return "Debian Squeeze 6.0 (64-bit)";
44-
} else if (stdType.equalsIgnoreCase("CentOS 5.6 (64-bit)")) {
45-
return "CentOS 5 (64-bit)";
46-
} else {
47-
return super.getGuestOsType(stdType, platformEmulator, bootFromCD);
48-
}
49-
}
50-
5135
@Override
5236
protected void setMemory(final Connection conn, final VM vm, long minMemsize, final long maxMemsize) throws XmlRpcException, XenAPIException {
5337
vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize);

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/CitrixResourceBaseTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,35 @@ public void testGetPathFilesListReturned(CitrixResourceBase citrixResourceBase)
4949
String receivedPath = files.get(0).getAbsolutePath();
5050
Assert.assertEquals(receivedPath, pathExpected);
5151
}
52+
53+
public void testGetGuestOsTypeNull(CitrixResourceBase citrixResourceBase) {
54+
String platformEmulator = null;
55+
56+
String expected = "Other install media";
57+
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
58+
Assert.assertEquals(expected, guestOsType);
59+
}
60+
61+
public void testGetGuestOsTypeEmpty(CitrixResourceBase citrixResourceBase) {
62+
String platformEmulator = "";
63+
64+
String expected = "Other install media";
65+
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
66+
Assert.assertEquals(expected, guestOsType);
67+
}
68+
69+
public void testGetGuestOsTypeBlank(CitrixResourceBase citrixResourceBase) {
70+
String platformEmulator = " ";
71+
72+
String expected = "Other install media";
73+
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
74+
Assert.assertEquals(expected, guestOsType);
75+
}
76+
77+
public void testGetGuestOsTypeOther(CitrixResourceBase citrixResourceBase) {
78+
String platformEmulator = "My Own Linux Distribution Y.M (64-bit)";
79+
80+
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
81+
Assert.assertEquals(platformEmulator, guestOsType);
82+
}
5283
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XcpOssResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,21 @@ public void testGetFiles(){
4747
public void testGetFilesListReturned(){
4848
testGetPathFilesListReturned(xcpOssResource);
4949
}
50+
51+
@Test
52+
public void testGetOsTypeNull() {
53+
testGetGuestOsTypeNull(xcpOssResource);
54+
}
55+
@Test
56+
public void testGetOsTypeEmpty() {
57+
testGetGuestOsTypeEmpty(xcpOssResource);
58+
}
59+
@Test
60+
public void testGetOsTypeBlank() {
61+
testGetGuestOsTypeBlank(xcpOssResource);
62+
}
63+
@Test
64+
public void testGetOsTypeOther() {
65+
testGetGuestOsTypeOther(xcpOssResource);
66+
}
5067
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XcpServerResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,21 @@ public void testGetFilesExeption(){
4848
public void testGetFilesListReturned(){
4949
testGetPathFilesListReturned(xcpServerResource);
5050
}
51+
52+
@Test
53+
public void testGetOsTypeNull() {
54+
testGetGuestOsTypeNull(xcpServerResource);
55+
}
56+
@Test
57+
public void testGetOsTypeEmpty() {
58+
testGetGuestOsTypeEmpty(xcpServerResource);
59+
}
60+
@Test
61+
public void testGetOsTypeBlank() {
62+
testGetGuestOsTypeBlank(xcpServerResource);
63+
}
64+
@Test
65+
public void testGetOsTypeOther() {
66+
testGetGuestOsTypeOther(xcpServerResource);
67+
}
5168
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer56FP1ResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,21 @@ public void testGetFiles(){
4545
public void testGetFilesListReturned(){
4646
testGetPathFilesListReturned(xenServer56FP1Resource);
4747
}
48+
49+
@Test
50+
public void testGetOsTypeNull() {
51+
testGetGuestOsTypeNull(xenServer56FP1Resource);
52+
}
53+
@Test
54+
public void testGetOsTypeEmpty() {
55+
testGetGuestOsTypeEmpty(xenServer56FP1Resource);
56+
}
57+
@Test
58+
public void testGetOsTypeBlank() {
59+
testGetGuestOsTypeBlank(xenServer56FP1Resource);
60+
}
61+
@Test
62+
public void testGetOsTypeOther() {
63+
testGetGuestOsTypeOther(xenServer56FP1Resource);
64+
}
4865
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer56ResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,21 @@ public void testGetFiles(){
4646
public void testGetFilesListReturned(){
4747
testGetPathFilesListReturned(xenServer56Resource);
4848
}
49+
50+
@Test
51+
public void testGetOsTypeNull() {
52+
testGetGuestOsTypeNull(xenServer56Resource);
53+
}
54+
@Test
55+
public void testGetOsTypeEmpty() {
56+
testGetGuestOsTypeEmpty(xenServer56Resource);
57+
}
58+
@Test
59+
public void testGetOsTypeBlank() {
60+
testGetGuestOsTypeBlank(xenServer56Resource);
61+
}
62+
@Test
63+
public void testGetOsTypeOther() {
64+
testGetGuestOsTypeOther(xenServer56Resource);
65+
}
4966
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer56SP2ResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,21 @@ public void testGetFiles(){
4545
public void testGetFilesListReturned(){
4646
testGetPathFilesListReturned(xenServer56SP2Resource);
4747
}
48+
49+
@Test
50+
public void testGetOsTypeNull() {
51+
testGetGuestOsTypeNull(xenServer56SP2Resource);
52+
}
53+
@Test
54+
public void testGetOsTypeEmpty() {
55+
testGetGuestOsTypeEmpty(xenServer56SP2Resource);
56+
}
57+
@Test
58+
public void testGetOsTypeBlank() {
59+
testGetGuestOsTypeBlank(xenServer56SP2Resource);
60+
}
61+
@Test
62+
public void testGetOsTypeOther() {
63+
testGetGuestOsTypeOther(xenServer56SP2Resource);
64+
}
4865
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer600ResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,21 @@ public void testGetFiles(){
4545
public void testGetFilesListReturned(){
4646
testGetPathFilesListReturned(xenServer600Resource);
4747
}
48+
49+
@Test
50+
public void testGetOsTypeNull() {
51+
testGetGuestOsTypeNull(xenServer600Resource);
52+
}
53+
@Test
54+
public void testGetOsTypeEmpty() {
55+
testGetGuestOsTypeEmpty(xenServer600Resource);
56+
}
57+
@Test
58+
public void testGetOsTypeBlank() {
59+
testGetGuestOsTypeBlank(xenServer600Resource);
60+
}
61+
@Test
62+
public void testGetOsTypeOther() {
63+
testGetGuestOsTypeOther(xenServer600Resource);
64+
}
4865
}

plugins/hypervisors/xenserver/test/com/cloud/hypervisor/xenserver/resource/XenServer625ResourceTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,21 @@ public void testGetFiles(){
4545
public void testGetFilesListReturned(){
4646
testGetPathFilesListReturned(xenServer625Resource);
4747
}
48+
49+
@Test
50+
public void testGetOsTypeNull() {
51+
testGetGuestOsTypeNull(xenServer625Resource);
52+
}
53+
@Test
54+
public void testGetOsTypeEmpty() {
55+
testGetGuestOsTypeEmpty(xenServer625Resource);
56+
}
57+
@Test
58+
public void testGetOsTypeBlank() {
59+
testGetGuestOsTypeBlank(xenServer625Resource);
60+
}
61+
@Test
62+
public void testGetOsTypeOther() {
63+
testGetGuestOsTypeOther(xenServer625Resource);
64+
}
4865
}

0 commit comments

Comments
 (0)