mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fix unit test to test NFS template download flow.
This commit is contained in:
parent
0d78209b73
commit
f5d5526d41
@ -140,7 +140,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
|||||||
String _guid;
|
String _guid;
|
||||||
String _role;
|
String _role;
|
||||||
Map<String, Object> _params;
|
Map<String, Object> _params;
|
||||||
StorageLayer _storage;
|
protected StorageLayer _storage;
|
||||||
boolean _inSystemVM = false;
|
boolean _inSystemVM = false;
|
||||||
boolean _sslCopy = false;
|
boolean _sslCopy = false;
|
||||||
|
|
||||||
|
|||||||
@ -62,6 +62,7 @@ import com.cloud.agent.api.Answer;
|
|||||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||||
import com.cloud.agent.api.storage.Proxy;
|
import com.cloud.agent.api.storage.Proxy;
|
||||||
import com.cloud.agent.api.to.DataStoreTO;
|
import com.cloud.agent.api.to.DataStoreTO;
|
||||||
|
import com.cloud.agent.api.to.NfsTO;
|
||||||
import com.cloud.agent.api.to.S3TO;
|
import com.cloud.agent.api.to.S3TO;
|
||||||
import com.cloud.exception.InternalErrorException;
|
import com.cloud.exception.InternalErrorException;
|
||||||
import com.cloud.storage.Storage.ImageFormat;
|
import com.cloud.storage.Storage.ImageFormat;
|
||||||
@ -245,6 +246,10 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
|
|||||||
this.threadPool = threadPool;
|
this.threadPool = threadPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setStorageLayer(StorageLayer storage){
|
||||||
|
this._storage = storage;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get notified of change of job status. Executed in context of downloader
|
* Get notified of change of job status. Executed in context of downloader
|
||||||
* thread
|
* thread
|
||||||
@ -656,8 +661,16 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
|
|||||||
return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
|
return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
String installPathPrefix = cmd.getInstallPath();
|
|
||||||
DataStoreTO dstore = cmd.getDataStore();
|
DataStoreTO dstore = cmd.getDataStore();
|
||||||
|
String installPathPrefix = cmd.getInstallPath();
|
||||||
|
// for NFS, we need to get mounted path
|
||||||
|
if (dstore instanceof NfsTO) {
|
||||||
|
if (ResourceType.TEMPLATE == resourceType) {
|
||||||
|
installPathPrefix = resource.getRootDir(cmd) + File.separator + installPathPrefix;
|
||||||
|
} else {
|
||||||
|
installPathPrefix = resource.getRootDir(cmd) + File.separator + installPathPrefix;
|
||||||
|
}
|
||||||
|
}
|
||||||
String user = null;
|
String user = null;
|
||||||
String password = null;
|
String password = null;
|
||||||
if (cmd.getAuth() != null) {
|
if (cmd.getAuth() != null) {
|
||||||
|
|||||||
@ -18,10 +18,12 @@ import com.amazonaws.services.s3.model.S3ObjectSummary;
|
|||||||
import com.cloud.agent.api.Answer;
|
import com.cloud.agent.api.Answer;
|
||||||
import com.cloud.agent.api.Command;
|
import com.cloud.agent.api.Command;
|
||||||
import com.cloud.agent.api.storage.DownloadAnswer;
|
import com.cloud.agent.api.storage.DownloadAnswer;
|
||||||
|
import com.cloud.agent.api.storage.ssCommand;
|
||||||
import com.cloud.agent.api.to.DataStoreTO;
|
import com.cloud.agent.api.to.DataStoreTO;
|
||||||
import com.cloud.agent.api.to.NfsTO;
|
import com.cloud.agent.api.to.NfsTO;
|
||||||
import com.cloud.agent.api.to.S3TO;
|
import com.cloud.agent.api.to.S3TO;
|
||||||
import com.cloud.agent.api.to.SwiftTO;
|
import com.cloud.agent.api.to.SwiftTO;
|
||||||
|
import com.cloud.storage.JavaStorageLayer;
|
||||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||||
import com.cloud.storage.resource.NfsSecondaryStorageResource;
|
import com.cloud.storage.resource.NfsSecondaryStorageResource;
|
||||||
import com.cloud.storage.template.DownloadManagerImpl;
|
import com.cloud.storage.template.DownloadManagerImpl;
|
||||||
@ -35,7 +37,17 @@ public class MockLocalNfsSecondaryStorageResource extends
|
|||||||
|
|
||||||
public MockLocalNfsSecondaryStorageResource(){
|
public MockLocalNfsSecondaryStorageResource(){
|
||||||
_dlMgr = new DownloadManagerImpl();
|
_dlMgr = new DownloadManagerImpl();
|
||||||
|
|
||||||
|
_storage = new JavaStorageLayer();
|
||||||
((DownloadManagerImpl)_dlMgr).setThreadPool(Executors.newFixedThreadPool(10));
|
((DownloadManagerImpl)_dlMgr).setThreadPool(Executors.newFixedThreadPool(10));
|
||||||
|
((DownloadManagerImpl)_dlMgr).setStorageLayer(_storage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRootDir(ssCommand cmd) {
|
||||||
|
return "/mnt";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package org.apache.cloudstack.storage.test;
|
package org.apache.cloudstack.storage.test;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
@ -8,6 +10,7 @@ import javax.inject.Inject;
|
|||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||||
|
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
|
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
|
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
|
||||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
|
||||||
@ -15,6 +18,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService;
|
|||||||
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult;
|
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateService.TemplateApiResult;
|
||||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
||||||
import org.apache.cloudstack.storage.LocalHostEndpoint;
|
import org.apache.cloudstack.storage.LocalHostEndpoint;
|
||||||
|
import org.apache.cloudstack.storage.MockLocalNfsSecondaryStorageResource;
|
||||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
import org.apache.cloudstack.storage.datastore.db.ImageStoreDao;
|
||||||
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@ -68,7 +72,7 @@ public class TemplateTest extends CloudStackTestNGBase {
|
|||||||
imageStore = new ImageStoreVO();
|
imageStore = new ImageStoreVO();
|
||||||
imageStore.setName("test");
|
imageStore.setName("test");
|
||||||
imageStore.setDataCenterId(dcId);
|
imageStore.setDataCenterId(dcId);
|
||||||
imageStore.setProviderName("CloudStack ImageStore Provider");
|
imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
|
||||||
imageStore.setRole(DataStoreRole.Image);
|
imageStore.setRole(DataStoreRole.Image);
|
||||||
imageStore.setUrl(this.getSecondaryStorage());
|
imageStore.setUrl(this.getSecondaryStorage());
|
||||||
imageStore.setUuid(UUID.randomUUID().toString());
|
imageStore.setUuid(UUID.randomUUID().toString());
|
||||||
@ -98,8 +102,11 @@ public class TemplateTest extends CloudStackTestNGBase {
|
|||||||
image = templateDao.persist(image);
|
image = templateDao.persist(image);
|
||||||
templateId = image.getId();
|
templateId = image.getId();
|
||||||
|
|
||||||
Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(new LocalHostEndpoint());
|
// inject mockito
|
||||||
//Mockito.when(downloadMonitor.isTemplateUpdateable(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
|
LocalHostEndpoint ep = new LocalHostEndpoint();
|
||||||
|
ep.setResource(new MockLocalNfsSecondaryStorageResource());
|
||||||
|
Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(ep);
|
||||||
|
Mockito.when(epSelector.select(Mockito.any(DataStore.class))).thenReturn(ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -109,13 +116,16 @@ public class TemplateTest extends CloudStackTestNGBase {
|
|||||||
AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
|
AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
|
||||||
templateSvr.createTemplateAsync(template, store, future);
|
templateSvr.createTemplateAsync(template, store, future);
|
||||||
try {
|
try {
|
||||||
future.get();
|
TemplateApiResult result = future.get();
|
||||||
|
assertTrue(result.isSuccess(), "failed to register template: " + result.getResult());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
assertTrue(false, e.getMessage());
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
assertTrue(false, e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -27,7 +27,8 @@
|
|||||||
<parameter name="primary-storage-want-to-add" value="nfs://192.168.56.2/opt/storage/primarynfs"/>
|
<parameter name="primary-storage-want-to-add" value="nfs://192.168.56.2/opt/storage/primarynfs"/>
|
||||||
<parameter name="devcloud-local-storage-uuid" value="cd10cac1-4772-92e5-5da6-c2bc16b1ce1b"/>
|
<parameter name="devcloud-local-storage-uuid" value="cd10cac1-4772-92e5-5da6-c2bc16b1ce1b"/>
|
||||||
<parameter name="devcloud-host-uuid" value="759ee4c9-a15a-297b-67c6-ac267d8aa429"/>
|
<parameter name="devcloud-host-uuid" value="759ee4c9-a15a-297b-67c6-ac267d8aa429"/>
|
||||||
<parameter name="devcloud-secondary-storage" value="nfs://192.168.56.10/opt/storage/secondary"/>
|
<!-- <parameter name="devcloud-secondary-storage" value="nfs://192.168.56.10/opt/storage/secondary"/> -->
|
||||||
|
<parameter name="devcloud-secondary-storage" value="nfs://nfs2.lab.vmops.com:/export/home/edison/secondary" />
|
||||||
|
|
||||||
<parameter name="s3-accesskey" value="OYAZXCAFUC1DAFOXNJWI"/>
|
<parameter name="s3-accesskey" value="OYAZXCAFUC1DAFOXNJWI"/>
|
||||||
<parameter name="s3-secretkey" value="YHpRtzNDwl12DtrQmwRvdpnf2xK2AeVM30rXxQ=="/>
|
<parameter name="s3-secretkey" value="YHpRtzNDwl12DtrQmwRvdpnf2xK2AeVM30rXxQ=="/>
|
||||||
|
|||||||
@ -227,6 +227,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
|||||||
s_logger.trace("Not incrementing resource count for system accounts, returning");
|
s_logger.trace("Not incrementing resource count for system accounts, returning");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long numToIncrement = (delta.length == 0) ? 1 : delta[0].longValue();
|
long numToIncrement = (delta.length == 0) ? 1 : delta[0].longValue();
|
||||||
|
|
||||||
if (!updateResourceCountForAccount(accountId, type, true, numToIncrement)) {
|
if (!updateResourceCountForAccount(accountId, type, true, numToIncrement)) {
|
||||||
|
|||||||
@ -99,7 +99,7 @@ public class DownloadListener implements Listener {
|
|||||||
|
|
||||||
public static final Logger s_logger = Logger.getLogger(DownloadListener.class.getName());
|
public static final Logger s_logger = Logger.getLogger(DownloadListener.class.getName());
|
||||||
public static final int SMALL_DELAY = 100;
|
public static final int SMALL_DELAY = 100;
|
||||||
public static final long STATUS_POLL_INTERVAL = 10000L;
|
public static final long STATUS_POLL_INTERVAL = 300000L; //10000L;
|
||||||
|
|
||||||
public static final String DOWNLOADED=Status.DOWNLOADED.toString();
|
public static final String DOWNLOADED=Status.DOWNLOADED.toString();
|
||||||
public static final String NOT_DOWNLOADED=Status.NOT_DOWNLOADED.toString();
|
public static final String NOT_DOWNLOADED=Status.NOT_DOWNLOADED.toString();
|
||||||
|
|||||||
@ -198,8 +198,9 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase implements Te
|
|||||||
TemplateInfo template = context.template;
|
TemplateInfo template = context.template;
|
||||||
VMTemplateVO tmplt = this._tmpltDao.findById(template.getId());
|
VMTemplateVO tmplt = this._tmpltDao.findById(template.getId());
|
||||||
long accountId = tmplt.getAccountId();
|
long accountId = tmplt.getAccountId();
|
||||||
_resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage,
|
if (template.getSize() != null) {
|
||||||
template.getSize());
|
_resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage, template.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user