This closes #628
Conflicts:
locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
- different tests added in the same place; simple to have both tests
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit:
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/8880bcd0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/8880bcd0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/8880bcd0
Branch: refs/heads/master
Commit: 8880bcd00c1d6bd94334264fb91775afd807849f
Parents: 0c44ebc 9c4516f
Author: Alex Heneveld <[email protected]>
Authored: Fri May 8 18:00:00 2015 +0100
Committer: Alex Heneveld <[email protected]>
Committed: Fri May 8 18:00:00 2015 +0100
----------------------------------------------------------------------
.../location/jclouds/JcloudsLocation.java | 3 +-
.../location/jclouds/JcloudsLocationTest.java | 49 ++++++++++++++++++++
2 files changed, 51 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8880bcd0/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8880bcd0/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
----------------------------------------------------------------------
diff --cc
locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
index d08338d,c2a78c3..bb1ef6b
---
a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
+++
b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTest.java
@@@ -28,8 -28,10 +28,14 @@@ import java.util.concurrent.atomic.Atom
import javax.annotation.Nullable;
import org.jclouds.compute.ComputeService;
+ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.Template;
++<<<<<<< HEAD
+import org.mockito.Mockito;
++=======
+ import org.jclouds.scriptbuilder.domain.OsFamily;
+ import org.jclouds.scriptbuilder.domain.StatementList;
++>>>>>>> apache-gh/pr/628
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
@@@ -568,25 -562,41 +580,62 @@@ public class JcloudsLocationTest implem
Assert.assertEquals(geo.longitude, -77.47314d, 0.00001);
}
- // TODO more tests, where flags come in from resolver, named locations,
etc
+ @Test
+ public void testInvokesCustomizerCallbacks() throws Exception {
+ JcloudsLocationCustomizer customizer =
Mockito.mock(JcloudsLocationCustomizer.class);
+//
Mockito.when(customizer.customize(Mockito.any(JcloudsLocation.class),
Mockito.any(ComputeService.class),
Mockito.any(JcloudsSshMachineLocation.class)));
+ ConfigBag allConfig = ConfigBag.newInstance()
+ .configure(CLOUD_PROVIDER, "aws-ec2")
+ .configure(ACCESS_IDENTITY, "bogus")
+ .configure(ACCESS_CREDENTIAL, "bogus")
+ .configure(JcloudsLocationConfig.JCLOUDS_LOCATION_CUSTOMIZERS,
ImmutableList.of(customizer))
+ .configure(JcloudsLocation.MACHINE_CREATE_ATTEMPTS, 1);
+ FakeLocalhostWithParentJcloudsLocation ll =
managementContext.getLocationManager().createLocation(LocationSpec.create(FakeLocalhostWithParentJcloudsLocation.class).configure(allConfig.getAllConfig()));
+ JcloudsSshMachineLocation l = ll.obtain();
+ Mockito.verify(customizer, Mockito.times(1)).customize(ll, null, l);
+ Mockito.verify(customizer, Mockito.never()).preRelease(l);
+ Mockito.verify(customizer, Mockito.never()).postRelease(l);
+
+ ll.release(l);
+ Mockito.verify(customizer, Mockito.times(1)).preRelease(l);
+ Mockito.verify(customizer, Mockito.times(1)).postRelease(l);
+ }
+ // now test creating users
+
+ protected String getCreateUserStatementsFor(Map<?,?> config) {
+ BailOutJcloudsLocation jl =
newSampleBailOutJcloudsLocationForTesting(MutableMap.<Object,Object>builder()
+ .put(JcloudsLocationConfig.LOGIN_USER,
"root").put(JcloudsLocationConfig.LOGIN_USER_PASSWORD, "m0ck")
+ .put(JcloudsLocationConfig.USER,
"bob").put(JcloudsLocationConfig.LOGIN_USER_PASSWORD, "b0b")
+ .putAll(config).build());
+
+ UserCreation creation = jl.createUserStatements(null,
jl.config().getBag());
+ return new StatementList(creation.statements).render(OsFamily.UNIX);
+ }
+
+ @Test
+ public void testDisablesRoot() {
+ String statements = getCreateUserStatementsFor(ImmutableMap.of());
+ Assert.assertTrue(statements.contains("PermitRootLogin"),
"Error:\n"+statements);
+
Assert.assertTrue(statements.matches("(?s).*sudoers.*useradd.*bob.*wheel.*"),
"Error:\n"+statements);
+ }
+
+ @Test
+ public void testDisableRootFalse() {
+ String statements =
getCreateUserStatementsFor(ImmutableMap.of(JcloudsLocationConfig.DISABLE_ROOT_AND_PASSWORD_SSH,
false));
+ Assert.assertFalse(statements.contains("PermitRootLogin"),
"Error:\n"+statements);
+
Assert.assertTrue(statements.matches("(?s).*sudoers.*useradd.*bob.*wheel.*"),
"Error:\n"+statements);
+ }
+
+ @Test
+ public void testDisableRootAndSudoFalse() {
+ String statements = getCreateUserStatementsFor(ImmutableMap.of(
+ JcloudsLocationConfig.DISABLE_ROOT_AND_PASSWORD_SSH, false,
+ JcloudsLocationConfig.GRANT_USER_SUDO, false));
+ Assert.assertFalse(statements.contains("PermitRootLogin"),
"Error:\n"+statements);
+
Assert.assertFalse(statements.matches("(?s).*sudoers.*useradd.*bob.*wheel.*"),
"Error:\n"+statements);
+ }
+
++ // TODO more tests, where flags come in from resolver, named locations,
etc
++
}