InstallChefGems script is now in jclouds/scriptbuilder

Moved the InstallChefGems statement to jclouds/scriptbuilder to
implement there the Chef Solo support, since Solo does not require a
connection to a Chef server.

Fixes #28
This commit is contained in:
Ignasi Barrera 2012-11-06 16:56:47 +01:00
parent 59c1db6bf6
commit d9a0035d58
7 changed files with 34 additions and 131 deletions

View File

@ -70,6 +70,13 @@
<artifactId>jclouds-scriptbuilder</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jclouds</groupId>
<artifactId>jclouds-scriptbuilder</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<!-- for transient chef provider -->
<dependency>
<groupId>org.jclouds</groupId>

View File

@ -28,9 +28,9 @@ import org.jclouds.chef.ChefAsyncApi;
import org.jclouds.chef.domain.Client;
import org.jclouds.chef.functions.ClientForGroup;
import org.jclouds.chef.functions.RunListForGroup;
import org.jclouds.chef.statements.InstallChefGems;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.statements.chef.InstallChefGems;
import com.google.common.collect.MapMaker;
import com.google.common.reflect.TypeToken;

View File

@ -1,50 +0,0 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.chef.statements;
import com.google.common.base.Throwables;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.util.Strings2;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.Collections;
/**
* @author Adrian Cole
*/
@Singleton
public class InstallChefGems implements Statement {
@Override
public String render(OsFamily family) {
try {
return Strings2.toStringAndClose(getClass().getResourceAsStream("install-chef-gems.sh"));
} catch (IOException e) {
Throwables.propagate(e);
return null;
}
}
@Override
public Iterable<String> functionDependencies(OsFamily family) {
return Collections.emptyList();
}
}

View File

@ -34,7 +34,6 @@ import org.jclouds.chef.ChefAsyncApi;
import org.jclouds.chef.domain.Client;
import org.jclouds.chef.functions.ClientForGroup;
import org.jclouds.chef.functions.RunListForGroup;
import org.jclouds.chef.statements.InstallChefGems;
import org.jclouds.chef.test.TransientChefApi;
import org.jclouds.chef.test.TransientChefAsyncApi;
import org.jclouds.concurrent.MoreExecutors;
@ -47,6 +46,7 @@ import org.jclouds.rest.annotations.Credential;
import org.jclouds.rest.config.BinderUtils;
import org.jclouds.rest.config.RestModule;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.statements.chef.InstallChefGems;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

View File

@ -1,29 +0,0 @@
if [ ! -f /usr/bin/chef-client ]; then
if which dpkg &> /dev/null; then
apt-get-update
apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
elif which rpm &> /dev/null; then
# Disable chef from the base repo (http://tickets.opscode.com/browse/CHEF-2906)
sed -i "s/\[base\]/\0\n\exclude=ruby*/g" /etc/yum.repos.d/CentOS-Base.repo
# Make sure to install an appropriate ruby version
yum erase -y ruby ruby-libs
rpm -Uvh http://rbel.co/rbel5
yum install -y ruby ruby-devel make gcc gcc-c++ kernel-devel automake autoconf wget
else
abort "we only support apt-get and yum right now... please contribute"
fi
(
mkdir -p /tmp/bootchef
cd /tmp/bootchef
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar zxf rubygems-1.3.7.tgz
cd rubygems-1.3.7
ruby setup.rb --no-format-executable
rm -fr /tmp/bootchef
)
if which rpm &> /dev/null; then
#Install gems provided by libruby-extras deb package (based on https://launchpad.net/ubuntu/precise/+package/libruby-extras)
/usr/bin/gem install cmdparse daemons log4r mmap ncurses --no-rdoc --no-ri --verbose
fi
/usr/bin/gem install ohai chef --no-rdoc --no-ri --verbose
fi

View File

@ -31,13 +31,14 @@ import java.util.List;
import org.jclouds.chef.ChefAsyncApi;
import org.jclouds.chef.config.ChefParserModule;
import org.jclouds.chef.statements.InstallChefGems;
import org.jclouds.crypto.PemsTest;
import org.jclouds.json.Json;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.ApiVersion;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.ShellToken;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.statements.chef.InstallChefGems;
import org.testng.annotations.Test;
import com.google.common.base.Charsets;
@ -57,60 +58,63 @@ import com.google.inject.Injector;
@Test(groups = "unit", testName = "GroupToBootScriptTest")
public class GroupToBootScriptTest {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure()
{
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
}
}, new ChefParserModule(), new GsonModule());
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefAsyncApi.VERSION);
}
}, new ChefParserModule(), new GsonModule());
Json json = injector.getInstance(Json.class);
Statement installChefGems = new InstallChefGems();
Optional<String> validatorName = Optional.<String> of("chef-validator");
Optional<PrivateKey> validatorCredential = Optional.<PrivateKey> of(createMock(PrivateKey.class));
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveValidatorName() {
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json,
ImmutableMap.<String, List<String>> of(), installChefGems, Optional.<String> absent(), validatorCredential);
ImmutableMap.<String, List<String>> of(), installChefGems, Optional.<String> absent(), validatorCredential);
fn.apply("foo");
}
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveValidatorCredential() {
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json,
ImmutableMap.<String, List<String>> of(), installChefGems, validatorName, Optional.<PrivateKey> absent());
ImmutableMap.<String, List<String>> of(), installChefGems, validatorName, Optional.<PrivateKey> absent());
fn.apply("foo");
}
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveRunScripts() {
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json,
ImmutableMap.<String, List<String>> of(), installChefGems, validatorName, validatorCredential);
ImmutableMap.<String, List<String>> of(), installChefGems, validatorName, validatorCredential);
fn.apply("foo");
}
@Test(expectedExceptions = IllegalStateException.class)
public void testMustHaveRunScriptsValue() {
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json,
ImmutableMap.<String, List<String>> of("foo", ImmutableList.<String> of()), installChefGems, validatorName,
validatorCredential);
ImmutableMap.<String, List<String>> of("foo", ImmutableList.<String> of()), installChefGems, validatorName,
validatorCredential);
fn.apply("foo");
}
public void testOneRecipe() throws IOException {
GroupToBootScript fn = new GroupToBootScript(Suppliers.ofInstance(URI.create("http://localhost:4000")), json,
ImmutableMap.<String, List<String>> of("foo", ImmutableList.<String> of("recipe[apache2]")), installChefGems,
validatorName, validatorCredential);
ImmutableMap.<String, List<String>> of("foo", ImmutableList.<String> of("recipe[apache2]")),
installChefGems, validatorName, validatorCredential);
PrivateKey validatorKey = validatorCredential.get();
expect(validatorKey.getEncoded()).andReturn(PemsTest.PRIVATE_KEY.getBytes());
replay(validatorKey);
assertEquals(fn.apply("foo").render(OsFamily.UNIX), CharStreams.toString(Resources.newReaderSupplier(Resources
.getResource("one-recipe.sh"), Charsets.UTF_8)));
assertEquals(
fn.apply("foo").render(OsFamily.UNIX),
Resources.toString(Resources.getResource("test_install_ruby." + ShellToken.SH.to(OsFamily.UNIX)),
Charsets.UTF_8)
+ "installChefGems || return 1\n"
+ Resources.toString(Resources.getResource("one-recipe.sh"), Charsets.UTF_8));
verify(validatorKey);
}
}

View File

@ -1,32 +1,3 @@
if [ ! -f /usr/bin/chef-client ]; then
if which dpkg &> /dev/null; then
apt-get-update
apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
elif which rpm &> /dev/null; then
# Disable chef from the base repo (http://tickets.opscode.com/browse/CHEF-2906)
sed -i "s/\[base\]/\0\n\exclude=ruby*/g" /etc/yum.repos.d/CentOS-Base.repo
# Make sure to install an appropriate ruby version
yum erase -y ruby ruby-libs
rpm -Uvh http://rbel.co/rbel5
yum install -y ruby ruby-devel make gcc gcc-c++ kernel-devel automake autoconf wget
else
abort "we only support apt-get and yum right now... please contribute"
fi
(
mkdir -p /tmp/bootchef
cd /tmp/bootchef
wget http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
tar zxf rubygems-1.3.7.tgz
cd rubygems-1.3.7
ruby setup.rb --no-format-executable
rm -fr /tmp/bootchef
)
if which rpm &> /dev/null; then
#Install gems provided by libruby-extras deb package (based on https://launchpad.net/ubuntu/precise/+package/libruby-extras)
/usr/bin/gem install cmdparse daemons log4r mmap ncurses --no-rdoc --no-ri --verbose
fi
/usr/bin/gem install ohai chef --no-rdoc --no-ri --verbose
fi
mkdir -p /etc/chef
cat >> /etc/chef/client.rb <<-'END_OF_JCLOUDS_FILE'
require 'rubygems'