mirror of https://github.com/apache/jclouds.git
Merge pull request #201 from richardcloudsoft/cloudstack-template-live-test
Changes to TemplateClientLiveTest to make it faster and more reliable
This commit is contained in:
commit
7ab9d17c8a
|
@ -44,9 +44,10 @@ import static org.testng.Assert.*;
|
||||||
@Test(groups = "live", singleThreaded = true, testName = "TemplateClientLiveTest")
|
@Test(groups = "live", singleThreaded = true, testName = "TemplateClientLiveTest")
|
||||||
public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
private static final String IMPORT_VHD_URL = "http://www.frontiertown.co.uk/jclouds/openwrt.vhd";
|
private static final String IMPORT_VHD_URL = "http://www.frontiertown.co.uk/jclouds/empty.vhd";
|
||||||
private VirtualMachine vm;
|
private VirtualMachine vm;
|
||||||
private Template template;
|
private Template createdTemplate;
|
||||||
|
private Template registeredTemplate;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListTemplates() throws Exception {
|
public void testListTemplates() throws Exception {
|
||||||
|
@ -110,17 +111,17 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
|
CreateTemplateOptions options = CreateTemplateOptions.Builder.volumeId(volume.getId());
|
||||||
AsyncCreateResponse response = client.getTemplateClient().createTemplate(TemplateMetadata.builder().name(tmplName).osTypeId(vm.getGuestOSId()).displayText("jclouds live testCreateTemplate").build(), options);
|
AsyncCreateResponse response = client.getTemplateClient().createTemplate(TemplateMetadata.builder().name(tmplName).osTypeId(vm.getGuestOSId()).displayText("jclouds live testCreateTemplate").build(), options);
|
||||||
assert jobComplete.apply(response.getJobId()) : vm;
|
assert jobComplete.apply(response.getJobId()) : vm;
|
||||||
template = client.getTemplateClient().getTemplateInZone(response.getId(), vm.getZoneId());
|
createdTemplate = client.getTemplateClient().getTemplateInZone(response.getId(), vm.getZoneId());
|
||||||
|
|
||||||
// Assertions
|
// Assertions
|
||||||
assertNotNull(template);
|
assertNotNull(createdTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testCreateTemplate")
|
@Test(enabled = true, dependsOnMethods = "testRegisterTemplate")
|
||||||
public void testExtractTemplate() throws Exception {
|
public void testExtractTemplate() throws Exception {
|
||||||
// Initiate the extraction and wait for it to complete
|
// Initiate the extraction and wait for it to complete
|
||||||
AsyncCreateResponse response = client.getTemplateClient().extractTemplate(template.getId(), ExtractMode.HTTP_DOWNLOAD, template.getZoneId());
|
AsyncCreateResponse response = client.getTemplateClient().extractTemplate(registeredTemplate.getId(), ExtractMode.HTTP_DOWNLOAD, registeredTemplate.getZoneId());
|
||||||
assert jobComplete.apply(response.getJobId()) : template;
|
assert jobComplete.apply(response.getJobId()) : registeredTemplate;
|
||||||
|
|
||||||
// Get the result
|
// Get the result
|
||||||
AsyncJob<TemplateExtraction> asyncJob = client.getAsyncJobClient().getAsyncJob(response.getJobId());
|
AsyncJob<TemplateExtraction> asyncJob = client.getAsyncJobClient().getAsyncJob(response.getJobId());
|
||||||
|
@ -153,11 +154,11 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
|
|
||||||
// Register a template
|
// Register a template
|
||||||
String tmplName = "jclouds-" + Integer.toHexString(new Random().nextInt());
|
String tmplName = "jclouds-" + Integer.toHexString(new Random().nextInt());
|
||||||
RegisterTemplateOptions options = RegisterTemplateOptions.Builder.bits(32);
|
RegisterTemplateOptions options = RegisterTemplateOptions.Builder.bits(32).isExtractable(true);
|
||||||
TemplateMetadata templateMetadata = TemplateMetadata.builder().name(tmplName).osTypeId(osType.getId()).displayText("jclouds live testRegisterTemplate").build();
|
TemplateMetadata templateMetadata = TemplateMetadata.builder().name(tmplName).osTypeId(osType.getId()).displayText("jclouds live testRegisterTemplate").build();
|
||||||
Set<Template> templates = client.getTemplateClient().registerTemplate(templateMetadata, "VHD", "xen", IMPORT_VHD_URL, zone.getId(), options);
|
Set<Template> templates = client.getTemplateClient().registerTemplate(templateMetadata, "VHD", "XenServer", IMPORT_VHD_URL, zone.getId(), options);
|
||||||
template = Iterables.getOnlyElement(templates, null);
|
registeredTemplate = Iterables.getOnlyElement(templates, null);
|
||||||
assertNotNull(template);
|
assertNotNull(registeredTemplate);
|
||||||
|
|
||||||
// Ensure it is available
|
// Ensure it is available
|
||||||
final long zoneId = zone.getId();
|
final long zoneId = zone.getId();
|
||||||
|
@ -170,10 +171,10 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
return "Download Complete".equals(t2.getStatus());
|
return "Download Complete".equals(t2.getStatus());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
assertTrue(new RetryablePredicate<Template>(templateReadyPredicate, 60000).apply(template));
|
assertTrue(new RetryablePredicate<Template>(templateReadyPredicate, 60000).apply(registeredTemplate));
|
||||||
|
|
||||||
// Create a VM that uses this template
|
// Create a VM that uses this template
|
||||||
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, template.getId(), client, jobComplete, virtualMachineRunning);
|
vm = VirtualMachineClientLiveTest.createVirtualMachineInNetwork(network, registeredTemplate.getId(), client, jobComplete, virtualMachineRunning);
|
||||||
assertNotNull(vm);
|
assertNotNull(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,9 +186,13 @@ public class TemplateClientLiveTest extends BaseCloudStackClientLiveTest {
|
||||||
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId())) : vm;
|
assert jobComplete.apply(client.getVirtualMachineClient().destroyVirtualMachine(vm.getId())) : vm;
|
||||||
assert virtualMachineDestroyed.apply(vm);
|
assert virtualMachineDestroyed.apply(vm);
|
||||||
}
|
}
|
||||||
if (template != null) {
|
if (createdTemplate != null) {
|
||||||
AsyncCreateResponse deleteJob = client.getTemplateClient().deleteTemplate(template.getId());
|
AsyncCreateResponse deleteJob = client.getTemplateClient().deleteTemplate(template.getId());
|
||||||
assertTrue(jobComplete.apply(deleteJob.getJobId()));
|
assertTrue(jobComplete.apply(deleteJob.getJobId()));
|
||||||
|
client.getTemplateClient().deleteTemplate(createdTemplate.getId());
|
||||||
|
}
|
||||||
|
if (registeredTemplate != null) {
|
||||||
|
client.getTemplateClient().deleteTemplate(registeredTemplate.getId());
|
||||||
}
|
}
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue