Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import java.util.UUID;
import java.util.concurrent.TimeoutException;

import javax.ejb.Local;
import javax.naming.ConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -164,7 +163,6 @@
* before you do any changes in this code here.
*
*/
@Local(value = ServerResource.class)
public abstract class CitrixResourceBase implements ServerResource, HypervisorResource, VirtualRouterDeployer {

public enum SRType {
Expand Down Expand Up @@ -1232,7 +1230,7 @@ public VIF createVif(final Connection conn, final String vmName, final VM vm, fi
}

public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmSpec, final Host host) throws XenAPIException, XmlRpcException {
final String guestOsTypeName = getGuestOsType(vmSpec.getOs(), vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD);
final String guestOsTypeName = getGuestOsType(vmSpec.getPlatformEmulator());
final Set<VM> templates = VM.getByNameLabel(conn, guestOsTypeName);
if (templates == null || templates.isEmpty()) {
throw new CloudRuntimeException("Cannot find template " + guestOsTypeName + " on XenServer host");
Expand Down Expand Up @@ -1337,7 +1335,7 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS
final TemplateObjectTO iso = (TemplateObjectTO) disk.getData();
final String osType = iso.getGuestOsType();
if (osType != null) {
final String isoGuestOsName = getGuestOsType(osType, vmSpec.getPlatformEmulator(), vmSpec.getBootloader() == BootloaderType.CD);
final String isoGuestOsName = getGuestOsType(vmSpec.getPlatformEmulator());
if (!isoGuestOsName.equals(guestOsTypeName)) {
vmSpec.setBootloader(BootloaderType.PyGrub);
}
Expand Down Expand Up @@ -2019,8 +2017,8 @@ public HashMap<String, HashMap<String, VgpuTypesInfo>> getGPUGroupDetails(final
return null;
}

protected String getGuestOsType(final String stdType, String platformEmulator, final boolean bootFromCD) {
if (platformEmulator == null) {
protected String getGuestOsType(String platformEmulator) {
if (org.apache.commons.lang.StringUtils.isBlank(platformEmulator)) {
s_logger.debug("no guest OS type, start it as HVM guest");
platformEmulator = "Other install media";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,12 @@

package com.cloud.hypervisor.xenserver.resource;

import javax.ejb.Local;

import org.apache.xmlrpc.XmlRpcException;

import com.cloud.resource.ServerResource;
import com.xensource.xenapi.Connection;
import com.xensource.xenapi.Types.XenAPIException;
import com.xensource.xenapi.VM;

@Local(value = ServerResource.class)
public class XcpOssResource extends CitrixResourceBase {

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

@Override
protected String getGuestOsType(final String stdType,
final String platformEmulator, final boolean bootFromCD) {
if (stdType.equalsIgnoreCase("Debian GNU/Linux 6(64-bit)")) {
return "Debian Squeeze 6.0 (64-bit)";
} else if (stdType.equalsIgnoreCase("CentOS 5.6 (64-bit)")) {
return "CentOS 5 (64-bit)";
} else {
return super.getGuestOsType(stdType, platformEmulator, bootFromCD);
}
}

@Override
protected void setMemory(final Connection conn, final VM vm, long minMemsize, final long maxMemsize) throws XmlRpcException, XenAPIException {
vm.setMemoryLimits(conn, mem_32m, maxMemsize, minMemsize, maxMemsize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@
import java.util.List;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;

import com.cloud.utils.script.Script;

public abstract class CitrixResourceBaseTest {
public class CitrixResourceBaseTest {

public void testGetPathFilesExeption(CitrixResourceBase citrixResourceBase) {
protected CitrixResourceBase citrixResourceBase = new CitrixResourceBase() {
@Override
protected String getPatchFilePath() {
return null;
}
};

public void testGetPathFilesExeption() {
String patch = citrixResourceBase.getPatchFilePath();

PowerMockito.mockStatic(Script.class);
Expand All @@ -36,7 +44,7 @@ public void testGetPathFilesExeption(CitrixResourceBase citrixResourceBase) {

}

public void testGetPathFilesListReturned(CitrixResourceBase citrixResourceBase) {
public void testGetPathFilesListReturned() {
String patch = citrixResourceBase.getPatchFilePath();

PowerMockito.mockStatic(Script.class);
Expand All @@ -49,4 +57,39 @@ public void testGetPathFilesListReturned(CitrixResourceBase citrixResourceBase)
String receivedPath = files.get(0).getAbsolutePath();
Assert.assertEquals(receivedPath, pathExpected);
}

@Test
public void testGetGuestOsTypeNull() {
String platformEmulator = null;

String expected = "Other install media";
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
Assert.assertEquals(expected, guestOsType);
}

@Test
public void testGetGuestOsTypeEmpty() {
String platformEmulator = "";

String expected = "Other install media";
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
Assert.assertEquals(expected, guestOsType);
}

@Test
public void testGetGuestOsTypeBlank() {
String platformEmulator = " ";

String expected = "Other install media";
String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
Assert.assertEquals(expected, guestOsType);
}

@Test
public void testGetGuestOsTypeOther() {
String platformEmulator = "My Own Linux Distribution Y.M (64-bit)";

String guestOsType = citrixResourceBase.getGuestOsType(platformEmulator);
Assert.assertEquals(platformEmulator, guestOsType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
Expand All @@ -26,11 +27,14 @@
@RunWith(PowerMockRunner.class)
public class XcpOssResourceTest extends CitrixResourceBaseTest{

private XcpOssResource xcpOssResource = new XcpOssResource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XcpOssResource();
}

@Test
public void testPatchFilePath() {
String patchFilePath = xcpOssResource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xcposs/patch";

Assert.assertEquals(patch, patchFilePath);
Expand All @@ -39,12 +43,12 @@ public void testPatchFilePath() {
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xcpOssResource);
testGetPathFilesExeption();
}

@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xcpOssResource);
testGetPathFilesListReturned();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
Expand All @@ -27,11 +28,14 @@
@RunWith(PowerMockRunner.class)
public class XcpServerResourceTest extends CitrixResourceBaseTest{

private XcpServerResource xcpServerResource = new XcpServerResource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XcpServerResource();
}

@Test
public void testPatchFilePath() {
String patchFilePath = xcpServerResource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xcpserver/patch";

Assert.assertEquals(patch, patchFilePath);
Expand All @@ -40,12 +44,12 @@ public void testPatchFilePath() {
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFilesExeption(){
testGetPathFilesExeption(xcpServerResource);
testGetPathFilesExeption();
}

@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xcpServerResource);
testGetPathFilesListReturned();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,40 @@
package com.cloud.hypervisor.xenserver.resource;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.script.Script;

@RunWith(PowerMockRunner.class)
public class XenServer56FP1ResourceTest extends CitrixResourceBaseTest{

private XenServer56FP1Resource xenServer56FP1Resource = new XenServer56FP1Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer56FP1Resource();
}

@Test
public void testPatchFilePath() {
String patchFilePath = xenServer56FP1Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";

Assert.assertEquals(patch, patchFilePath);
}

@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer56FP1Resource);
testGetPathFilesExeption();
}

@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer56FP1Resource);
testGetPathFilesListReturned();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
Expand All @@ -26,11 +27,14 @@
@RunWith(PowerMockRunner.class)
public class XenServer56ResourceTest extends CitrixResourceBaseTest {

private XenServer56Resource xenServer56Resource = new XenServer56Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer56Resource();
}

@Test
public void testPatchFilePath() {
String patchFilePath = xenServer56Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56/patch";

Assert.assertEquals(patch, patchFilePath);
Expand All @@ -39,11 +43,12 @@ public void testPatchFilePath() {
@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer56Resource);
testGetPathFilesExeption();
}

@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer56Resource);
testGetPathFilesListReturned();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.cloud.hypervisor.xenserver.resource;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
Expand All @@ -26,23 +27,28 @@
@RunWith(PowerMockRunner.class)
public class XenServer56SP2ResourceTest extends CitrixResourceBaseTest{

private XenServer56SP2Resource xenServer56SP2Resource = new XenServer56SP2Resource();
@Before
public void beforeTest() {
super.citrixResourceBase = new XenServer56SP2Resource();
}

@Test
public void testPatchFilePath() {
String patchFilePath = xenServer56SP2Resource.getPatchFilePath();
String patchFilePath = citrixResourceBase.getPatchFilePath();
String patch = "scripts/vm/hypervisor/xenserver/xenserver56fp1/patch";

Assert.assertEquals(patch, patchFilePath);
}

@Test(expected = CloudRuntimeException.class)
@PrepareForTest(Script.class )
public void testGetFiles(){
testGetPathFilesExeption(xenServer56SP2Resource);
testGetPathFilesExeption();
}

@Test
@PrepareForTest(Script.class )
public void testGetFilesListReturned(){
testGetPathFilesListReturned(xenServer56SP2Resource);
testGetPathFilesListReturned();
}
}
Loading