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 _role;
|
||||
Map<String, Object> _params;
|
||||
StorageLayer _storage;
|
||||
protected StorageLayer _storage;
|
||||
boolean _inSystemVM = 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.Proxy;
|
||||
import com.cloud.agent.api.to.DataStoreTO;
|
||||
import com.cloud.agent.api.to.NfsTO;
|
||||
import com.cloud.agent.api.to.S3TO;
|
||||
import com.cloud.exception.InternalErrorException;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
@ -245,6 +246,10 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
|
||||
this.threadPool = threadPool;
|
||||
}
|
||||
|
||||
public void setStorageLayer(StorageLayer storage){
|
||||
this._storage = storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get notified of change of job status. Executed in context of downloader
|
||||
* thread
|
||||
@ -656,8 +661,16 @@ public class DownloadManagerImpl extends ManagerBase implements DownloadManager
|
||||
return new DownloadAnswer("Invalid Name", VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
|
||||
}
|
||||
|
||||
String installPathPrefix = cmd.getInstallPath();
|
||||
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 password = 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.Command;
|
||||
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.NfsTO;
|
||||
import com.cloud.agent.api.to.S3TO;
|
||||
import com.cloud.agent.api.to.SwiftTO;
|
||||
import com.cloud.storage.JavaStorageLayer;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.storage.resource.NfsSecondaryStorageResource;
|
||||
import com.cloud.storage.template.DownloadManagerImpl;
|
||||
@ -35,7 +37,17 @@ public class MockLocalNfsSecondaryStorageResource extends
|
||||
|
||||
public MockLocalNfsSecondaryStorageResource(){
|
||||
_dlMgr = new DownloadManagerImpl();
|
||||
|
||||
_storage = new JavaStorageLayer();
|
||||
((DownloadManagerImpl)_dlMgr).setThreadPool(Executors.newFixedThreadPool(10));
|
||||
((DownloadManagerImpl)_dlMgr).setStorageLayer(_storage);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRootDir(ssCommand cmd) {
|
||||
return "/mnt";
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.UUID;
|
||||
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.DataStore;
|
||||
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.TemplateDataFactory;
|
||||
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.framework.async.AsyncCallFuture;
|
||||
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.ImageStoreVO;
|
||||
import org.mockito.Mockito;
|
||||
@ -34,7 +38,7 @@ import com.cloud.storage.download.DownloadMonitorImpl;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
|
||||
@ContextConfiguration(locations={"classpath:/storageContext.xml"})
|
||||
|
||||
|
||||
public class TemplateTest extends CloudStackTestNGBase {
|
||||
@Inject
|
||||
DataCenterDao dcDao;
|
||||
@ -55,7 +59,7 @@ public class TemplateTest extends CloudStackTestNGBase {
|
||||
DownloadMonitorImpl downloadMonitor;
|
||||
long dcId;
|
||||
long templateId;
|
||||
|
||||
|
||||
@Test(priority = -1)
|
||||
public void setUp() {
|
||||
ComponentContext.initComponentsLifeCycle();
|
||||
@ -64,17 +68,17 @@ public class TemplateTest extends CloudStackTestNGBase {
|
||||
null, null, NetworkType.Basic, null, null, true, true, null, null);
|
||||
dc = dcDao.persist(dc);
|
||||
dcId = dc.getId();
|
||||
|
||||
|
||||
imageStore = new ImageStoreVO();
|
||||
imageStore.setName("test");
|
||||
imageStore.setDataCenterId(dcId);
|
||||
imageStore.setProviderName("CloudStack ImageStore Provider");
|
||||
imageStore.setProviderName(DataStoreProvider.NFS_IMAGE);
|
||||
imageStore.setRole(DataStoreRole.Image);
|
||||
imageStore.setUrl(this.getSecondaryStorage());
|
||||
imageStore.setUuid(UUID.randomUUID().toString());
|
||||
imageStore.setProtocol("nfs");
|
||||
imageStore = imageStoreDao.persist(imageStore);
|
||||
|
||||
|
||||
VMTemplateVO image = new VMTemplateVO();
|
||||
image.setTemplateType(TemplateType.USER);
|
||||
image.setUrl(this.getTemplateUrl());
|
||||
@ -93,30 +97,36 @@ public class TemplateTest extends CloudStackTestNGBase {
|
||||
image.setCrossZones(true);
|
||||
image.setExtractable(true);
|
||||
|
||||
|
||||
|
||||
//image.setImageDataStoreId(storeId);
|
||||
image = templateDao.persist(image);
|
||||
templateId = image.getId();
|
||||
|
||||
Mockito.when(epSelector.select(Mockito.any(DataObject.class))).thenReturn(new LocalHostEndpoint());
|
||||
//Mockito.when(downloadMonitor.isTemplateUpdateable(Mockito.anyLong(), Mockito.anyLong())).thenReturn(true);
|
||||
|
||||
// inject mockito
|
||||
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
|
||||
public void registerTemplate() {
|
||||
TemplateInfo template = templateFactory.getTemplate(templateId);
|
||||
DataStore store = dataStoreMgr.getImageStore(dcId);
|
||||
AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
|
||||
templateSvr.createTemplateAsync(template, store, future);
|
||||
try {
|
||||
future.get();
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
TemplateApiResult result = future.get();
|
||||
assertTrue(result.isSuccess(), "failed to register template: " + result.getResult());
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
assertTrue(false, e.getMessage());
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
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="devcloud-local-storage-uuid" value="cd10cac1-4772-92e5-5da6-c2bc16b1ce1b"/>
|
||||
<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-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");
|
||||
return;
|
||||
}
|
||||
|
||||
long numToIncrement = (delta.length == 0) ? 1 : delta[0].longValue();
|
||||
|
||||
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 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 NOT_DOWNLOADED=Status.NOT_DOWNLOADED.toString();
|
||||
|
||||
@ -198,8 +198,9 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase implements Te
|
||||
TemplateInfo template = context.template;
|
||||
VMTemplateVO tmplt = this._tmpltDao.findById(template.getId());
|
||||
long accountId = tmplt.getAccountId();
|
||||
_resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage,
|
||||
template.getSize());
|
||||
if (template.getSize() != null) {
|
||||
_resourceLimitMgr.incrementResourceCount(accountId, ResourceType.secondary_storage, template.getSize());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user