Issue 1070:TemplateBuilderSpec with loginUser=user:password doesn't use that for login credentials

This commit is contained in:
Adrian Cole 2012-08-22 12:05:33 -07:00
parent 0cbef26eae
commit 0d805574ed
3 changed files with 58 additions and 1 deletions

View File

@ -1086,7 +1086,7 @@ public class TemplateBuilderImpl implements TemplateBuilder {
@Override
public TemplateBuilder from(TemplateBuilderSpec spec) {
return spec.copyTo(this, options != null ? options : optionsProvider.get());
return spec.copyTo(this, options != null ? options : (options = optionsProvider.get()));
}
@Override

View File

@ -777,4 +777,60 @@ public class TemplateBuilderImplTest {
assertEquals(template.getLocation().getId(), "us-east-2");
}
@Test
public void testFromSpecWithLoginUser() {
final Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet
.<Location> of(region));
final Supplier<Set<? extends Image>> images = Suppliers.<Set<? extends Image>> ofInstance(ImmutableSet
.<Image> of(
new ImageBuilder()
.id("us-east-2/ami-ffff")
.providerId("ami-ffff")
.name("Ubuntu 11.04 x64")
.description("Ubuntu 11.04 x64")
.location(region2)
.status(Status.AVAILABLE)
.operatingSystem(
OperatingSystem.builder().name("Ubuntu 11.04 x64").description("Ubuntu 11.04 x64")
.is64Bit(true).version("11.04").family(OsFamily.UBUNTU).build()).build()));
final Supplier<Set<? extends Hardware>> hardwares = Suppliers.<Set<? extends Hardware>> ofInstance(ImmutableSet
.<Hardware> of(
new HardwareBuilder()
.ids("m1.small").ram(512)
.processors(ImmutableList.of(new Processor(1, 1.0)))
.volumes(ImmutableList.<Volume> of(new VolumeImpl((float) 5, true, true))).build()));
final Provider<TemplateOptions> optionsProvider = new Provider<TemplateOptions>() {
@Override
public TemplateOptions get() {
return new TemplateOptions();
}
};
Provider<TemplateBuilder> templateBuilderProvider = new Provider<TemplateBuilder>() {
@Override
public TemplateBuilder get() {
return createTemplateBuilder(null, locations, images, hardwares, region, optionsProvider, this);
}
};
TemplateBuilder templateBuilder = templateBuilderProvider.get().from("hardwareId=m1.small,imageId=us-east-2/ami-ffff,loginUser=user:Password01,authenticateSudo=true");
assertEquals(templateBuilder.toString(), "{imageId=us-east-2/ami-ffff, hardwareId=m1.small}");
Template template = templateBuilder.build();
assertEquals(template.getLocation().getId(), "us-east-2");
assertEquals(template.getOptions().getLoginUser(), "user");
assertEquals(template.getOptions().getLoginPassword(), "Password01");
assertEquals(template.getOptions().getLoginPrivateKey(), null);
assertEquals(template.getOptions().shouldAuthenticateSudo(), Boolean.TRUE);
}
}

View File

@ -82,6 +82,7 @@ public class NinefoldComputeTemplateBuilderLiveTest extends BaseTemplateBuilderL
assertEquals(getCores(defaultTemplate.getHardware()), 1.0d);
assertEquals(defaultTemplate.getOptions().getLoginUser(), "user");
assertEquals(defaultTemplate.getOptions().getLoginPassword(), "Password01");
assertEquals(defaultTemplate.getOptions().getLoginPrivateKey(), null);
assertEquals(defaultTemplate.getOptions().shouldAuthenticateSudo(), Boolean.TRUE);
} else {
assertEquals(defaultTemplate.getImage(), this.view.getComputeService().templateBuilder().from(template)