@Override public String render(OsFamily family) { if (family == OsFamily.WINDOWS) { throw new UnsupportedOperationException("windows not yet implemented"); } Statement statement = version.isPresent() ? exec(String.format("gem install chef -v '%s' --no-rdoc --no-ri", version.get())) : exec("gem install chef --no-rdoc --no-ri"); return statement.render(family); }
@Override public String render(OsFamily family) { if (family == OsFamily.WINDOWS) { throw new UnsupportedOperationException("windows not yet implemented"); } Statement statement = version.isPresent() ? exec(String.format("gem install chef -v '%s' --no-rdoc --no-ri", version.get())) : exec("gem install chef --no-rdoc --no-ri"); return statement.render(family); }
public String render(OsFamily family) { String linesToPrepend = Joiner.on('\n').withKeyValueSeparator(" ").join(params); Statement prependSshdConfig = exec(String.format( "exec 3<> %1$s && awk -v TEXT=\"%2$s\n\" 'BEGIN {print TEXT}{print}' %1$s >&3", sshdConfig, linesToPrepend)); Statement reloadSshdConfig = exec("hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload"); return newStatementList(prependSshdConfig, reloadSshdConfig).render(family); }
/** * This script will be executed as the root user upon system startup. This * script gets a prologue, so no #!/bin/bash required, path set up, etc * */ public TemplateOptions runScript(String script) { return runScript(Statements.exec(script)); }
/** * This script will be executed as the root user upon system startup. This * script gets a prologue, so no #!/bin/bash required, path set up, etc * */ public TemplateOptions runScript(String script) { return runScript(Statements.exec(script)); }
@VisibleForTesting void createSoloConfiguration(ImmutableList.Builder<Statement> statements) { statements.add(exec("{md} " + fileCachePath)); for (String path : cookbookPath) { statements.add(exec("{md} " + path)); } String cookbookPathJoined = Joiner.on(',').join(transform(cookbookPath, quote())); statements.add(createOrOverwriteFile( fileCachePath + "/solo.rb", ImmutableSet.of("file_cache_path \"" + fileCachePath + "\"", // "cookbook_path [" + cookbookPathJoined + "]", "role_path \"" + rolePath + "\"", "data_bag_path \"" + databagPath + "\""))); }
public String render(OsFamily family) { String linesToPrepend = Joiner.on('\n').withKeyValueSeparator(" ").join(params); Statement prependSshdConfig = exec(String.format( "exec 3<> %1$s && awk -v TEXT=\"%2$s\n\" 'BEGIN {print TEXT}{print}' %1$s >&3", sshdConfig, linesToPrepend)); Statement reloadSshdConfig = exec("hash service 2>&- && service ssh reload 2>&- || /etc/init.d/ssh* reload"); return newStatementList(prependSshdConfig, reloadSshdConfig).render(family); }
@VisibleForTesting void createRolesIfNecessary(ImmutableList.Builder<Statement> statements) { // The roles directory must contain one file for each role definition if (roles.isPresent() && !roles.get().isEmpty()) { statements.add(exec("{md} " + rolePath)); for (Role role : roles.get()) { statements.add(createOrOverwriteFile(rolePath + "/" + role.getName() + ".json", ImmutableSet.of(role.toJsonString()))); } } }
@VisibleForTesting void createRolesIfNecessary(ImmutableList.Builder<Statement> statements) { // The roles directory must contain one file for each role definition if (roles.isPresent() && !roles.get().isEmpty()) { statements.add(exec("{md} " + rolePath)); for (Role role : roles.get()) { statements.add(createOrOverwriteFile(rolePath + "/" + role.getName() + ".json", ImmutableSet.of(role.toJsonString()))); } } }
@VisibleForTesting void createRolesIfNecessary(ImmutableList.Builder<Statement> statements) { // The roles directory must contain one file for each role definition if (roles.isPresent() && !roles.get().isEmpty()) { statements.add(exec("{md} " + rolePath)); for (Role role : roles.get()) { statements.add(createOrOverwriteFile(rolePath + "/" + role.getName() + ".json", ImmutableSet.of(role.toJsonString()))); } } }
public String render(OsFamily family) { checkNotNull(family, "family"); if (family == OsFamily.WINDOWS) throw new UnsupportedOperationException("windows not yet implemented"); Builder<Statement> statements = ImmutableList.builder(); statements.add(createOrOverwriteFile(sudoers, ImmutableSet.of("root ALL = (ALL) ALL", "%wheel ALL = (ALL) NOPASSWD:ALL"))); statements.add(exec("chmod 0440 " + sudoers)); return new StatementList(statements.build()).render(family); }
public void testWhenNotAdminAccess() { AdminAccess.Configuration configuration = createMock(AdminAccess.Configuration.class); InitAdminAccess initAdminAccess = new InitAdminAccess(configuration); replay(configuration); initAdminAccess.visit(Statements.exec("echo hello")); initAdminAccess.visit(Statements.newStatementList(Statements.exec("echo hello"))); verify(configuration); }
public void testWhenNotAdminAccess() { Statement statement = Statements.exec("echo hello"); assertEquals(CredentialsFromAdminAccess.INSTANCE.apply(statement), null); Statement statementList = Statements.newStatementList(statement); assertEquals(CredentialsFromAdminAccess.INSTANCE.apply(statementList), null); }
public void testCreateDatabagsIfNecessaryWithOneDatabagAndCustomPath() { ImmutableList.Builder<Statement> statements = ImmutableList.builder(); DataBag databag = DataBag.builder().name("foo").item("item", "{\"foo\":\"bar\"}").build(); ChefSolo solo = ChefSolo.builder().dataBagPath("/tmp/databags").defineDataBag(databag).build(); solo.createDatabagsIfNecessary(statements); ImmutableList<Statement> statementList = statements.build(); Statement expected = createOrOverwriteFile("/tmp/databags/foo/item.json", ImmutableSet.of("{\"foo\":\"bar\"}")); assertEquals(statementList.size(), 3); assertEquals(statementList.get(0), exec("{md} /tmp/databags")); assertEquals(statementList.get(1), exec("{md} /tmp/databags/" + databag.getName())); assertEquals(statementList.get(2).render(OsFamily.UNIX), expected.render(OsFamily.UNIX)); }
public Boolean call() { Statement statement = Statements.newStatementList(exec("hostname")); // NB this assumes passwordless sudo ! ExecResponse response = computeService.runScriptOnNode(nodeRef.getId(), statement, overrideLoginCredentials(expectedCredentialsRef).runAsRoot(false)); return response.getExitStatus() == 0; }}) .limitTimeTo(delayMs, MILLISECONDS)
public void simpleTest() { RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"), wrapInInitScript(false).runAsRoot(false)); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect(sshClient.exec("echo $USER\n" + "echo $USER\n")).andReturn(new ExecResponse("tester\ntester\n", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); }
@Test(expectedExceptions = IllegalStateException.class) public void testWithoutInitThrowsIllegalStateException() { Statement command = exec("doFoo"); NodeMetadata node = new NodeMetadataBuilder().ids("id").status(Status.RUNNING).credentials( LoginCredentials.builder().user("tester").password("notalot").build()).build(); SshClient sshClient = createMock(SshClient.class); replay(sshClient); RunScriptOnNodeAsInitScriptUsingSsh testMe = new RunScriptOnNodeAsInitScriptUsingSsh(Functions .forMap(ImmutableMap.of(node, sshClient)), eventBus, InitScriptConfigurationForTasks.create() .appendIncrementingNumberToAnonymousTaskNames(), node, command, new RunScriptOptions()); testMe.call(); }
public static Statement install() { return new StatementList( AdminAccess.builder().adminUsername("web").build(), InstallJDK.fromOpenJDK(), authorizePortInIpTables(), extractTargzAndFlattenIntoDirectory(JETTY_URL, JETTY_HOME), exec("chown -R web " + JETTY_HOME)); }