Issue 191: more progress on compute integration

This commit is contained in:
Adrian Cole 2010-08-31 17:03:51 -07:00
parent 6a4c93840d
commit be23e73207
4 changed files with 233 additions and 163 deletions

View File

@ -1,22 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
$HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious, LLC $HeadURL$ $Revision$ $Date$ Copyright (C) 2010 Cloud Conscious,
<info@cloudconscious.com> LLC <info@cloudconscious.com>
==================================================================== ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or
contributor license agreements. See the NOTICE file distributed with more contributor license agreements. See the NOTICE file
this work for additional information regarding copyright ownership. distributed with this work for additional information regarding
The ASF licenses this file to you under the Apache License, Version copyright ownership. The ASF licenses this file to you under the
2.0 (the "License"); you may not use this file except in compliance Apache License, Version 2.0 (the "License"); you may not use
with the License. You may obtain a copy of the License at 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.html Unless required by http://www.apache.org/licenses/LICENSE-2.0.html Unless required
applicable law or agreed to in writing, software distributed under the by applicable law or agreed to in writing, software distributed
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR under the License is distributed on an "AS IS" BASIS, WITHOUT
CONDITIONS OF ANY KIND, either express or implied. See the License for WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
the specific language governing permissions and limitations under the See the License for the specific language governing permissions
License. and limitations under the License.
==================================================================== ====================================================================
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@ -33,12 +34,17 @@
<name>jclouds chef compute integration</name> <name>jclouds chef compute integration</name>
<description>provisions nodes with jclouds and kick's off chef to configure and integrate</description> <description>provisions nodes with jclouds and kick's off chef to configure and integrate</description>
<properties> <properties>
<!-- for example: ec2, trmk-ecloud, bluelock-vclouddirector, cloudservers, etc --> <!--
for example: ec2, trmk-ecloud, bluelock-vclouddirector,
cloudservers, etc
-->
<jclouds.compute.provider>YOUR_PREFERRED_PROVIDER</jclouds.compute.provider> <jclouds.compute.provider>YOUR_PREFERRED_PROVIDER</jclouds.compute.provider>
<!-- leave blank unless you have a different url to override --> <!-- leave blank unless you have a different url to override -->
<jclouds.compute.endpoint></jclouds.compute.endpoint> <jclouds.compute.endpoint></jclouds.compute.endpoint>
<jclouds.compute.identity>YOUR_ACCOUNT</jclouds.compute.identity> <jclouds.compute.identity>YOUR_ACCOUNT</jclouds.compute.identity>
<jclouds.compute.credential>YOUR_CREDENTIAL</jclouds.compute.credential> <jclouds.compute.credential>YOUR_CREDENTIAL</jclouds.compute.credential>
<!-- tag for nodes used in the tests -->
<jclouds.compute.tag>jcloudschef</jclouds.compute.tag>
<jclouds.chef.identity>YOUR_USER</jclouds.chef.identity> <jclouds.chef.identity>YOUR_USER</jclouds.chef.identity>
<jclouds.chef.credential.pem>${user.home}/.chef/${jclouds.chef.identity}.pem</jclouds.chef.credential.pem> <jclouds.chef.credential.pem>${user.home}/.chef/${jclouds.chef.identity}.pem</jclouds.chef.credential.pem>
<jclouds.opscodeplatform.org>YOUR_ORG</jclouds.opscodeplatform.org> <jclouds.opscodeplatform.org>YOUR_ORG</jclouds.opscodeplatform.org>
@ -145,8 +151,12 @@
<value>${jclouds.compute.credential}</value> <value>${jclouds.compute.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.chef.identity</name> <name>jclouds.compute.tag</name>
<value>${jclouds.chef.identity}</value> <value>${jclouds.compute.tag}</value>
</property>
<property>
<name>jclouds.compute.credential</name>
<value>${jclouds.compute.credential}</value>
</property> </property>
<property> <property>
<name>jclouds.chef.credential.pem</name> <name>jclouds.chef.credential.pem</name>

View File

@ -0,0 +1,14 @@
if [ ! -f /usr/bin/chef-client ]; then
apt-get update
apt-get install -y ruby ruby1.8-dev build-essential wget libruby-extras libruby1.8-extras
mkdir -p /tmp/bootchef
(
cd /tmp/bootchef
curl http://rubyforge.org/frs/download.php/69365/rubygems-1.3.6.tgz| tar -xzf -
cd rubygems-1.3.6
ruby setup.rb
cp /usr/bin/gem1.8 /usr/bin/gem
)
rm -rf /tmp/bootchef
gem install chef ohai --no-rdoc --no-ri --verbose
fi

View File

@ -0,0 +1,5 @@
(
cat <<'EOP'
@herefile@
EOP
) > @destination@

View File

@ -20,15 +20,19 @@
package org.jclouds.chef.compute; package org.jclouds.chef.compute;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Sets.newHashSet;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import org.jclouds.chef.ChefContext; import org.jclouds.chef.ChefContext;
import org.jclouds.chef.ChefContextFactory; import org.jclouds.chef.ChefContextFactory;
import org.jclouds.chef.ChefService;
import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.ComputeServiceContextFactory; import org.jclouds.compute.ComputeServiceContextFactory;
import org.jclouds.crypto.Pems;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
@ -48,9 +52,13 @@ public class ChefComputeServiceLiveTest {
private ComputeServiceContext computeContext; private ComputeServiceContext computeContext;
private ChefContext chefContext; private ChefContext chefContext;
private String tag;
private String clientName;
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })
public void setupCompute() { public void setupCompute() {
tag = System.getProperty("jclouds.compute.tag") != null ? System.getProperty("jclouds.compute.tag")
: "jcloudschef";
String computeProvider = checkNotNull(System.getProperty("jclouds.compute.provider"), "jclouds.compute.provider"); String computeProvider = checkNotNull(System.getProperty("jclouds.compute.provider"), "jclouds.compute.provider");
String computeEndpoint = System.getProperty("jclouds.compute.endpoint"); String computeEndpoint = System.getProperty("jclouds.compute.endpoint");
Properties props = new Properties(); Properties props = new Properties();
@ -77,11 +85,41 @@ public class ChefComputeServiceLiveTest {
} }
@Test @Test
public void test() { public void test() throws IOException {
clientName = findNextClientName(chefContext, tag + "-%d");
String clientKey = Pems.pem(chefContext.getApi().createClient(clientName).getPrivateKey());
// herefile /etc/chef/client.rb
// log_level :info
// log_location STDOUT
// chef_server_url "@chef_server_url@"
// herefile /etc/chef/client.pem
// clientKey
// herefile /etc/chef/first-boot.json
// { "run_list": [ "recipe[apache]" ] }
// then run /usr/bin/chef-client -j /etc/chef/first-boot.json
System.out.println("created new client: " + clientName);
computeContext.getComputeService().listNodes(); computeContext.getComputeService().listNodes();
chefContext.getChefService().listNodesDetails(); chefContext.getChefService().listNodesDetails();
} }
private String findNextClientName(ChefContext context, String pattern) {
Set<String> nodes = context.getApi().listClients();
String nodeName;
Set<String> names = newHashSet(nodes);
int index = 0;
while (true) {
nodeName = String.format(pattern, index++);
if (!names.contains(nodeName))
break;
}
return nodeName;
}
@AfterGroups(groups = { "live" }) @AfterGroups(groups = { "live" })
public void teardownCompute() { public void teardownCompute() {
if (computeContext != null) if (computeContext != null)
@ -90,7 +128,10 @@ public class ChefComputeServiceLiveTest {
@AfterGroups(groups = { "live" }) @AfterGroups(groups = { "live" })
public void teardownChef() { public void teardownChef() {
if (chefContext != null) if (chefContext != null) {
if (clientName != null && chefContext.getApi().clientExists(clientName))
chefContext.getApi().deleteClient(clientName);
chefContext.close(); chefContext.close();
} }
}
} }