mirror of https://github.com/apache/jclouds.git
Always take into account the configured template builder spec when building a template in live tests
This commit is contained in:
parent
52477d5e93
commit
449c6d8d84
|
@ -71,7 +71,7 @@ public class FirewallApiLiveTest extends BaseCloudStackApiLiveTest {
|
|||
}
|
||||
}));
|
||||
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
|
||||
vm = VirtualMachineApiLiveTest.createVirtualMachineInNetwork(network,
|
||||
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()),
|
||||
|
|
|
@ -86,7 +86,7 @@ public class LoadBalancerApiLiveTest extends BaseCloudStackApiLiveTest {
|
|||
public void testCreateVm() {
|
||||
if (networksDisabled)
|
||||
return;
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
vm = VirtualMachineApiLiveTest.createVirtualMachineInNetwork(network,
|
||||
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()),
|
||||
client, jobComplete, virtualMachineRunning);
|
||||
|
|
|
@ -174,7 +174,7 @@ public class SecurityGroupApiLiveTest extends BaseCloudStackApiLiveTest {
|
|||
@Test(dependsOnMethods = "testCreateIngress")
|
||||
public void testCreateVMInSecurityGroup() throws Exception {
|
||||
skipIfSecurityGroupsNotSupported();
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
vm = VirtualMachineApiLiveTest.createVirtualMachineWithSecurityGroupInZone(zone.getId(),
|
||||
defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), group.getId(), client,
|
||||
jobComplete, virtualMachineRunning);
|
||||
|
@ -204,7 +204,7 @@ public class SecurityGroupApiLiveTest extends BaseCloudStackApiLiveTest {
|
|||
@Test
|
||||
public void testCreateVMWithoutSecurityGroupAssignsDefault() throws Exception {
|
||||
skipIfSecurityGroupsNotSupported();
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
VirtualMachine newVm = VirtualMachineApiLiveTest.createVirtualMachineWithOptionsInZone(DeployVirtualMachineOptions.NONE,
|
||||
zone.getId(), defaultTemplateOrPreferredInZone(defaultTemplate, client, zone.getId()), client,
|
||||
jobComplete, virtualMachineRunning);
|
||||
|
|
|
@ -110,7 +110,7 @@ public class TemplateApiLiveTest extends BaseCloudStackApiLiveTest {
|
|||
assertNotNull(network);
|
||||
|
||||
// Create a VM and stop it
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
vmForCreation = VirtualMachineApiLiveTest.createVirtualMachineInNetwork(network, defaultTemplate, client, jobComplete, virtualMachineRunning);
|
||||
assertTrue(jobComplete.apply(client.getVirtualMachineApi().stopVirtualMachine(vmForCreation.getId())), vmForCreation.toString());
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ public class VirtualMachineApiLiveTest extends BaseCloudStackApiLiveTest {
|
|||
|
||||
@Test
|
||||
public void testCreateVirtualMachine() throws Exception {
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
vm = createVirtualMachine(client, defaultTemplate, jobComplete, virtualMachineRunning);
|
||||
if (vm.getPassword() != null) {
|
||||
conditionallyCheckSSH();
|
||||
|
@ -190,7 +190,7 @@ public class VirtualMachineApiLiveTest extends BaseCloudStackApiLiveTest {
|
|||
public void testCreateVirtualMachineWithSpecificIp() throws Exception {
|
||||
skipIfNotGlobalAdmin();
|
||||
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
Network network = null;
|
||||
|
||||
try {
|
||||
|
|
|
@ -58,7 +58,7 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATApiLiveTest {
|
|||
prefix += "nat";
|
||||
try {
|
||||
network = find(client.getNetworkApi().listNetworks(), NetworkPredicates.supportsStaticNAT());
|
||||
String defaultTemplate = template != null ? template.getImageId() : null;
|
||||
String defaultTemplate = templateBuilderSpec != null ? templateBuilderSpec.getImageId() : null;
|
||||
vm = VirtualMachineApiLiveTest.createVirtualMachineInNetwork(network,
|
||||
defaultTemplateOrPreferredInZone(defaultTemplate, client, network.getZoneId()), client, jobComplete,
|
||||
virtualMachineRunning);
|
||||
|
|
|
@ -218,7 +218,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
template.getOptions().blockOnPort(22, 120);
|
||||
try {
|
||||
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
|
||||
|
@ -274,7 +274,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
try {
|
||||
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
|
||||
NodeMetadata node = getOnlyElement(nodes);
|
||||
|
@ -333,7 +333,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
|
||||
@Test(enabled = true, dependsOnMethods = { "testImagesCache" })
|
||||
public void testTemplateMatch() throws Exception {
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
Template toMatch = client.templateBuilder().imageId(template.getImage().getId()).build();
|
||||
assertEquals(toMatch.getImage(), template.getImage());
|
||||
}
|
||||
|
@ -374,7 +374,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
|
||||
@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript")
|
||||
public void testCreateTwoNodesWithOneSpecifiedName() throws Exception {
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
template.getOptions().nodeNames(ImmutableSet.of("first-node"));
|
||||
Set<? extends NodeMetadata> nodes;
|
||||
try {
|
||||
|
@ -399,7 +399,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
}
|
||||
|
||||
protected Template refreshTemplate() {
|
||||
return template = addRunScriptToTemplate(buildTemplate(client.templateBuilder()));
|
||||
return template = addRunScriptToTemplate(buildTemplate(templateBuilder()));
|
||||
}
|
||||
|
||||
protected Template addRunScriptToTemplate(Template template) {
|
||||
|
@ -437,7 +437,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
|
||||
if (existingLocationIsAssignable) {
|
||||
getAnonymousLogger().info("creating another node based on existing nodes' location: " + existingLocation);
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
template = addRunScriptToTemplate(client.templateBuilder().fromTemplate(template)
|
||||
.locationId(existingLocation.getId()).build());
|
||||
} else {
|
||||
|
@ -472,7 +472,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
final int groupNum = i;
|
||||
final String group = "twin" + groupNum;
|
||||
groups.add(group);
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300 + groupNum);
|
||||
ListenableFuture<NodeMetadata> future = userExecutor.submit(new Callable<NodeMetadata>() {
|
||||
public NodeMetadata call() throws Exception {
|
||||
|
@ -524,6 +524,14 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
}
|
||||
}
|
||||
|
||||
protected TemplateBuilder templateBuilder() {
|
||||
TemplateBuilder templateBuilder = client.templateBuilder();
|
||||
if (templateBuilderSpec != null) {
|
||||
templateBuilder = templateBuilder.from(templateBuilderSpec);
|
||||
}
|
||||
return templateBuilder;
|
||||
}
|
||||
|
||||
protected Template buildTemplate(TemplateBuilder templateBuilder) {
|
||||
return templateBuilder.build();
|
||||
}
|
||||
|
@ -731,7 +739,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
ImmutableSet<String> tags = ImmutableSet.of(group);
|
||||
Stopwatch watch = Stopwatch.createStarted();
|
||||
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags);
|
||||
|
||||
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template));
|
||||
|
@ -834,7 +842,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||
|
||||
}
|
||||
// no inbound ports
|
||||
template = buildTemplate(client.templateBuilder());
|
||||
template = buildTemplate(templateBuilder());
|
||||
template.getOptions().blockUntilRunning(false).inboundPorts();
|
||||
try {
|
||||
long time = currentTimeMillis();
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.google.inject.util.Modules;
|
|||
|
||||
public abstract class BaseGenericComputeServiceContextLiveTest<W extends ComputeServiceContext> extends BaseViewLiveTest<W> {
|
||||
|
||||
protected TemplateBuilderSpec template;
|
||||
protected TemplateBuilderSpec templateBuilderSpec;
|
||||
protected LoginCredentials loginCredentials = LoginCredentials.builder().user("root").build();
|
||||
|
||||
// isolate tests from eachother, as default credentialStore is static
|
||||
|
@ -47,15 +47,15 @@ public abstract class BaseGenericComputeServiceContextLiveTest<W extends Compute
|
|||
Properties overrides = super.setupProperties();
|
||||
String spec = setIfTestSystemPropertyPresent(overrides, provider + ".template");
|
||||
if (spec != null) {
|
||||
template = TemplateBuilderSpec.parse(spec);
|
||||
if (template.getLoginUser() != null) {
|
||||
Iterable<String> userPass = Splitter.on(':').split(template.getLoginUser());
|
||||
templateBuilderSpec = TemplateBuilderSpec.parse(spec);
|
||||
if (templateBuilderSpec.getLoginUser() != null) {
|
||||
Iterable<String> userPass = Splitter.on(':').split(templateBuilderSpec.getLoginUser());
|
||||
Builder loginCredentialsBuilder = LoginCredentials.builder();
|
||||
loginCredentialsBuilder.user(Iterables.get(userPass, 0));
|
||||
if (Iterables.size(userPass) == 2)
|
||||
loginCredentialsBuilder.password(Iterables.get(userPass, 1));
|
||||
if (template.getAuthenticateSudo() != null)
|
||||
loginCredentialsBuilder.authenticateSudo(template.getAuthenticateSudo());
|
||||
if (templateBuilderSpec.getAuthenticateSudo() != null)
|
||||
loginCredentialsBuilder.authenticateSudo(templateBuilderSpec.getAuthenticateSudo());
|
||||
loginCredentials = loginCredentialsBuilder.build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,9 +191,11 @@ public abstract class BaseTemplateBuilderLiveTest extends BaseComputeServiceCont
|
|||
ComputeServiceContext context = null;
|
||||
try {
|
||||
Properties overrides = setupProperties();
|
||||
String login = template != null && template.getLoginUser() != null ? template.getLoginUser() : "foo:bar";
|
||||
String login = templateBuilderSpec != null && templateBuilderSpec.getLoginUser() != null ? templateBuilderSpec
|
||||
.getLoginUser() : "foo:bar";
|
||||
overrides.setProperty(propertyKey + ".image.login-user", login);
|
||||
boolean auth = template != null && template.getAuthenticateSudo() != null ? template.getAuthenticateSudo() : true;
|
||||
boolean auth = templateBuilderSpec != null && templateBuilderSpec.getAuthenticateSudo() != null ? templateBuilderSpec
|
||||
.getAuthenticateSudo() : true;
|
||||
overrides.setProperty(propertyKey + ".image.authenticate-sudo", auth + "");
|
||||
|
||||
context = createView(overrides, ImmutableSet.<Module>of(credentialStoreModule));
|
||||
|
|
Loading…
Reference in New Issue