Source:
public void runTestCreatesUser(MachineProvisioningLocation<SshMachineLocation> loc) throws Exception { String newUsername = Identifiers.makeRandomId(16); SshMachineLocation machine = loc.obtain(ImmutableMap.of()); try { app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(CreateUserPolicy.class) .configure(CreateUserPolicy.GRANT_SUDO, true) .configure(CreateUserPolicy.RESET_LOGIN_USER, true) .configure(CreateUserPolicy.VM_USERNAME, newUsername))); TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren()); app.start(ImmutableList.of(machine)); String creds = EntityTestUtils.assertAttributeEventuallyNonNull(entity, CreateUserPolicy.VM_USER_CREDENTIALS); Pattern pattern = Pattern.compile("(.*) : (.*) @ (.*):(.*)"); Matcher matcher = pattern.matcher(creds); assertTrue(matcher.matches()); String username = matcher.group(1).trim(); String password = matcher.group(2).trim(); String hostname = matcher.group(3).trim(); String port = matcher.group(4).trim(); assertEquals(newUsername, username); assertEquals(hostname, machine.getAddress().getHostName()); assertEquals(port, ""+machine.getPort()); SshMachineLocation machine2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure(SshTool.PROP_USER, newUsername) .configure(SshMachineLocation.PASSWORD, password) .configure("address", hostname) .configure(SshMachineLocation.SSH_PORT, Integer.parseInt(port))); LOG.info("Checking ssh'able for auto-generated user: machine="+machine+"; creds="+creds); assertTrue(machine2.isSshable(), "machine="+machine+"; creds="+creds); } catch (Exception e) { throw e; } finally { LOG.info("Deleting auto-generated user "+newUsername); machine.execScript("delete-user-"+newUsername, ImmutableList.of("sudo userdel -f "+newUsername)); loc.release(machine); } }

Target:
public void runTestCreatesUser(MachineProvisioningLocation<SshMachineLocation> loc) throws Exception { String newUsername = Identifiers.makeRandomId(16); SshMachineLocation machine = loc.obtain(ImmutableMap.of()); try { app.createAndManageChild(EntitySpec.create(TestEntity.class) .policy(PolicySpec.create(CreateUserPolicy.class) .configure(CreateUserPolicy.GRANT_SUDO, true) .configure(CreateUserPolicy.VM_USERNAME, newUsername))); TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren()); app.start(ImmutableList.of(machine)); String creds = EntityTestUtils.assertAttributeEventuallyNonNull(entity, CreateUserPolicy.VM_USER_CREDENTIALS); Pattern pattern = Pattern.compile("(.*) : (.*) @ (.*):(.*)"); Matcher matcher = pattern.matcher(creds); assertTrue(matcher.matches()); String username = matcher.group(1).trim(); String password = matcher.group(2).trim(); String hostname = matcher.group(3).trim(); String port = matcher.group(4).trim(); assertEquals(newUsername, username); assertEquals(hostname, machine.getAddress().getHostName()); assertEquals(port, ""+machine.getPort()); SshMachineLocation machine2 = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class) .configure(SshTool.PROP_USER, newUsername) .configure(SshMachineLocation.PASSWORD, password) .configure("address", hostname) .configure(SshMachineLocation.SSH_PORT, Integer.parseInt(port))); LOG.info("Checking ssh'able for auto-generated user: machine="+machine+"; creds="+creds); assertTrue(machine2.isSshable(), "machine="+machine+"; creds="+creds); } catch (Exception e) { throw e; } finally { LOG.info("Deleting auto-generated user "+newUsername); machine.execScript("delete-user-"+newUsername, ImmutableList.of("sudo userdel -f "+newUsername)); loc.release(machine); } }