whirr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianc...@apache.org
Subject svn commit: r1172926 [2/2] - in /whirr/trunk: ./ cli/ core/src/main/java/org/apache/whirr/ core/src/main/java/org/apache/whirr/actions/ core/src/main/java/org/apache/whirr/service/ core/src/test/java/org/apache/whirr/ core/src/test/java/org/apache/whir...
Date Tue, 20 Sep 2011 00:44:24 GMT
Added: whirr/trunk/services/puppet/src/main/resources/functions/install_puppet.sh
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/main/resources/functions/install_puppet.sh?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/main/resources/functions/install_puppet.sh (added)
+++ whirr/trunk/services/puppet/src/main/resources/functions/install_puppet.sh Tue Sep 20
00:44:22 2011
@@ -0,0 +1,67 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF 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.
+#
+
+function install_puppet() {
+	if ! which git &> /dev/null ; then
+		install_git_forced
+	fi
+	if ! which puppet &> /dev/null ; then
+		install_puppet_forced
+	fi
+}
+
+function install_git_forced() {	
+	if which dpkg &> /dev/null; then
+    	install_git_deb
+	elif which yum &> /dev/null; then
+    	install_git_rpm
+    else
+    	echo "WARNING: could not install git, no appropriate package manager"
+	fi
+}
+
+function install_git_rpm() {
+	if [ `uname -m` == 'x86_64' ]; then
+        rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
+    else
+        rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
+    fi
+    yum -y install git
+}
+
+function install_git_deb() {
+    apt-get update -qq
+    apt-get -y install git-core
+}
+
+function install_puppet_forced() {
+	# this script assumes ruby and ruby gems are already installed
+	
+	# Setup the default module/fact path locations so we can populate them
+	# elsewhere
+	mkdir -p /etc/puppet/modules
+	mkdir -p /etc/puppet/manifests
+	mkdir -p /usr/share/puppet/modules
+	mkdir -p /var/lib/puppet/lib/facter
+
+	# install the puppet and facter gems
+	sudo gem install facter --no-rdoc --no-ri --bindir /usr/bin/
+	sudo gem install puppet --no-rdoc --no-ri --bindir /usr/bin/
+	
+	sudo useradd puppet
+		
+}

Added: whirr/trunk/services/puppet/src/main/resources/functions/install_ruby.sh
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/main/resources/functions/install_ruby.sh?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/main/resources/functions/install_ruby.sh (added)
+++ whirr/trunk/services/puppet/src/main/resources/functions/install_ruby.sh Tue Sep 20 00:44:22
2011
@@ -0,0 +1,50 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF 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.
+#
+
+function install_ruby() {
+  if ! which ruby &> /dev/null; then
+    if which dpkg &> /dev/null; then
+      install_ruby_deb
+      add_to_path
+    elif which yum &> /dev/null; then
+      install_ruby_rpm
+      add_to_path
+    else
+      echo "ERROR: could not install ruby, no appropriate package manager" 
+      return 1
+    fi
+  fi
+}
+
+function install_ruby_rpm() {
+  if [ `uname -m` == 'x86_64' ]; then
+    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
+  else
+    rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm
+  fi
+  yum -y install ruby ruby-rdoc rubygems
+}
+
+function install_ruby_deb() {
+  apt-get install -y ruby ruby-dev rubygems libopenssl-ruby rdoc ri irb build-essential wget
ssl-cert
+}
+
+function add_to_path() {
+  # add the gems executable directory to the path
+  echo "export PATH=$PATH:"`gem environment | grep "EXECUTABLE DIRECTORY" | sed 's|- EXECUTABLE
DIRECTORY: ||' | sed -e 's/^[ \t]*//'`"" >> /etc/profile
+  echo "export PATH=$PATH:"`gem environment | grep "EXECUTABLE DIRECTORY" | sed 's|- EXECUTABLE
DIRECTORY: ||' | sed -e 's/^[ \t]*//'`"" >> /etc/bash.bashrc
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/ManifestTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/ManifestTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/ManifestTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/ManifestTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class ManifestTest {
+
+  private static final String NGINX_PUPPET = "class { 'nginx':\n}";
+  private static final String POSTGRES_PUPPET = "class { 'postgresql::server':\n}";
+  private static final String NTP_PUPPET = "class { 'ntp':\n  servers => \"10.0.0.1\",\n}";
+
+  // private static final String PUPPET_COMMAND =
+  // "echo 'class { 'ntp::client':\n  servers => [\"10.0.0.1\"],\n}' >> /tmp/test.pp\nsudo
-i puppet apply /tmp/test.pp\n";
+  
+  @Test
+  public void testPuppetConversion() {
+
+   Manifest nginx = new Manifest("nginx", null);
+
+   assertEquals("Puppet representation is incorrect.", NGINX_PUPPET,
+      nginx.toString());
+  }
+
+  @Test
+  public void testPuppetConversionWithSpecificClass() {
+
+   Manifest postgresql = new Manifest("postgresql", "server");
+
+   assertEquals("PUPPET representation is incorrect.", POSTGRES_PUPPET,
+      postgresql.toString());
+
+  }
+
+  @Test
+  public void testPuppetConversionWithAttribs() {
+
+   Manifest ntp = new Manifest("ntp");
+   ntp.attribs.put("servers", "\"10.0.0.1\"");
+
+   assertEquals("Puppet representation is incorrect.", NTP_PUPPET,
+      ntp.toString());
+
+  }
+}
+

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/PuppetClusterActionHandlerFactoryTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/PuppetClusterActionHandlerFactoryTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/PuppetClusterActionHandlerFactoryTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/PuppetClusterActionHandlerFactoryTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,39 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.apache.whirr.HandlerMapFactory;
+import org.junit.Test;
+
+public class PuppetClusterActionHandlerFactoryTest {
+
+  @Test
+  public void testPuppetFactoryIsRegisteredAndWorksWithModules() {
+    assertEquals(HandlerMapFactory.create().get("puppet:nginx"), new PuppetClusterActionHandler("nginx"));
+  }
+
+  @Test
+  public void testPuppetFactoryIsRegisteredAndWorksWithManifests() {
+    assertEquals(HandlerMapFactory.create().get("puppet:postgresql::server"), new PuppetClusterActionHandler(
+          "postgresql::server"));
+  }
+
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/InstallAllModulesStatementFromPropertiesTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/InstallAllModulesStatementFromPropertiesTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/InstallAllModulesStatementFromPropertiesTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/InstallAllModulesStatementFromPropertiesTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.functions;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.whirr.service.puppet.functions.StatementToInstallModule.PrepareRemoteFileUrl;
+import org.jclouds.scriptbuilder.domain.OsFamily;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class InstallAllModulesStatementFromPropertiesTest {
+  InstallAllModulesStatementFromProperties getStatement = new InstallAllModulesStatementFromProperties(
+        new StatementToInstallModule(new PrepareRemoteFileUrl() {
+
+          @Override
+          public String apply(String rawUrl) throws IOException {
+            return rawUrl;
+          }
+
+        }));
+
+  @Test
+  public void testWhenMultiple() {
+
+    assertEquals("git clone git://github.com/puppetlabs/puppetlabs-nginx.git /etc/puppet/modules/nginx\n"
+          + "git clone git://github.com/puppetlabs/puppetlabs-http.git /etc/puppet/modules/http\n",
getStatement
+          .apply(
+                ImmutableMap.of("puppet.nginx.module", "git://github.com/puppetlabs/puppetlabs-nginx.git",
+                      "puppet.http.module", "git://github.com/puppetlabs/puppetlabs-http.git")).render(
+                OsFamily.UNIX));
+  }
+
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/KeyToModuleNameOrNullTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/KeyToModuleNameOrNullTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/KeyToModuleNameOrNullTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/KeyToModuleNameOrNullTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.functions;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class KeyToModuleNameOrNullTest {
+
+   @Test
+   public void testSimple() {
+      assertEquals("nginx", KeyToModuleNameOrNull.INSTANCE.apply("puppet.nginx.module"));
+      assertEquals(null, KeyToModuleNameOrNull.INSTANCE.apply("puppet.nginx.module.branch"));
+      assertEquals(null, KeyToModuleNameOrNull.INSTANCE.apply("nginx.server"));
+   }
+
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/ModulePropertiesFromConfigurationTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/ModulePropertiesFromConfigurationTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/ModulePropertiesFromConfigurationTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/ModulePropertiesFromConfigurationTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.functions;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class ModulePropertiesFromConfigurationTest {
+
+  @Test
+  public void testWhenMatches() {
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("puppet.nginx.module", "git://github.com/puppetlabs/puppetlabs-nginx.git");
+    conf.setProperty("puppet.nginx.module.branch", "notmaster");
+    conf.setProperty("puppet.foox.module", null);
+    conf.setProperty("puppet.module", "foo");
+    assertEquals(ImmutableMap.of("puppet.nginx.module.branch", "notmaster", "puppet.nginx.module",
+          "git://github.com/puppetlabs/puppetlabs-nginx.git"), ModulePropertiesFromConfiguration.INSTANCE
+          .apply(conf));
+  }
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/RolesManagedByPuppetTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/RolesManagedByPuppetTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/RolesManagedByPuppetTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/RolesManagedByPuppetTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.functions;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+public class RolesManagedByPuppetTest {
+
+  @Test
+  public void test() {
+    assertEquals(ImmutableSet.of("http").toString(), RolesManagedByPuppet.INSTANCE.apply(
+          ImmutableSet.of("hadoop", "puppet:http")).toString());
+  }
+
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/StatementToInstallModuleTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/StatementToInstallModuleTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/StatementToInstallModuleTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/functions/StatementToInstallModuleTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.functions;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.whirr.service.puppet.functions.StatementToInstallModule.PrepareRemoteFileUrl;
+import org.jclouds.scriptbuilder.domain.OsFamily;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+public class StatementToInstallModuleTest {
+  StatementToInstallModule getStatement = new StatementToInstallModule(new PrepareRemoteFileUrl()
{
+
+    @Override
+    public String apply(String rawUrl) throws IOException {
+      return rawUrl;
+    }
+
+  });
+
+  @Test
+  public void testWhenRemote() {
+
+    assertEquals("install_tarball remote://path/to/tgz /etc/puppet/modules/nginx || return
1\n", getStatement.apply(
+         ImmutableMap.of("puppet.nginx.module", "remote://path/to/tgz"))
+          .render(OsFamily.UNIX));
+  }
+
+  @Test
+  public void testWhenFile() {
+
+    assertEquals("install_tarball file://path/to/tgz /etc/puppet/modules/nginx || return
1\n", getStatement.apply(
+         ImmutableMap.of("puppet.nginx.module", "file://path/to/tgz"))
+          .render(OsFamily.UNIX));
+  }
+
+  @Test
+  public void testWhenGit() {
+
+    assertEquals("git clone git://github.com/puppetlabs/puppetlabs-nginx.git /etc/puppet/modules/nginx\n",
+          getStatement.apply(ImmutableMap.of("puppet.nginx.module",
+                      "git://github.com/puppetlabs/puppetlabs-nginx.git")).render(OsFamily.UNIX));
+  }
+  
+  @Test
+  public void testWhenGitAndBranch() {
+
+    assertEquals("git clone -b notmaster git://github.com/puppetlabs/puppetlabs-nginx.git
/etc/puppet/modules/nginx\n",
+          getStatement.apply(ImmutableMap.of("puppet.nginx.module.branch", "notmaster", "puppet.nginx.module",
+                      "git://github.com/puppetlabs/puppetlabs-nginx.git")).render(OsFamily.UNIX));
+  }
+}
+

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/integration/PuppetServiceTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/integration/PuppetServiceTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/integration/PuppetServiceTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/integration/PuppetServiceTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.integration;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.whirr.Cluster;
+import org.apache.whirr.ClusterController;
+import org.apache.whirr.ClusterSpec;
+import org.apache.whirr.Cluster.Instance;
+import org.jclouds.net.IPSocket;
+import org.jclouds.predicates.InetSocketAddressConnect;
+import org.jclouds.predicates.RetryablePredicate;
+import org.jclouds.util.Strings2;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Install an http service on the remote machine with puppet!
+ */
+public class PuppetServiceTest {
+
+  private ClusterSpec clusterSpec;
+  private ClusterController controller;
+  private Cluster cluster;
+  private RetryablePredicate<IPSocket> socketTester;
+
+  @Before
+  public void setUp() throws Exception {
+    CompositeConfiguration config = new CompositeConfiguration();
+    if (System.getProperty("config") != null) {
+      config.addConfiguration(new PropertiesConfiguration(System.getProperty("config")));
+    }
+    config.addConfiguration(new PropertiesConfiguration("whirr-puppet-test.properties"));
+
+    clusterSpec = ClusterSpec.withTemporaryKeys(config);
+    controller = new ClusterController();
+    cluster = controller.launchCluster(clusterSpec);
+    socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(),
60, 1, TimeUnit.SECONDS);
+
+  }
+
+  @Test
+  public void testHttpAvailable() throws Exception {
+
+    // check that the http server started
+    for (Instance instance : cluster.getInstances()) {
+      // first, check the socket
+      IPSocket socket = new IPSocket(instance.getPublicAddress().getHostAddress(), 80);
+      assert socketTester.apply(socket) : instance;
+      
+      // then, try a GET
+      URI httpUrl = URI.create("http://" + instance.getPublicAddress().getHostAddress());
+      Strings2.toStringAndClose(httpUrl.toURL().openStream());
+    }
+
+  }
+
+  @After
+  public void tearDown() throws IOException, InterruptedException {
+    if (controller != null) {
+      controller.destroyCluster(clusterSpec);
+    }
+  }
+
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/predicates/PuppetPredicatesTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/predicates/PuppetPredicatesTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/predicates/PuppetPredicatesTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/predicates/PuppetPredicatesTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.predicates;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+public class PuppetPredicatesTest {
+
+  @Test
+  public void testFirst() {
+    assert PuppetPredicates.isFirstPuppetRoleIn(ImmutableSet.of("puppet:foo", "bar", "puppet:bird")).apply("foo");
+  }
+
+  @Test
+  public void testLast() {
+    assert PuppetPredicates.isLastPuppetRoleIn(ImmutableSet.of("puppet:foo", "bar", "puppet:bird")).apply("bird");
+  }
+
+  @Test
+  public void testIsRole() {
+    assert !PuppetPredicates.isPuppetRole().apply("bar");
+    assert PuppetPredicates.isPuppetRole().apply("puppet:foo");
+  }
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/CreateSitePpAndApplyRolesTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/CreateSitePpAndApplyRolesTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/CreateSitePpAndApplyRolesTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/CreateSitePpAndApplyRolesTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.statements;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.jclouds.scriptbuilder.domain.OsFamily;
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.io.CharStreams;
+import com.google.common.io.Resources;
+
+public class CreateSitePpAndApplyRolesTest {
+
+  @Test
+  public void testWithAttribs() throws IOException {
+    Configuration conf = new PropertiesConfiguration();
+    conf.setProperty("puppet.nginx.module", "git://github.com/puppetlabs/puppetlabs-nginx.git");
+    conf.setProperty("nginx.server.hostname", "foohost");
+
+    CreateSitePpAndApplyRoles nginx = new CreateSitePpAndApplyRoles(ImmutableSet.of("nginx::server"),
conf);
+
+    assertEquals(CharStreams.toString(Resources.newReaderSupplier(Resources.getResource("nginx-with-attribs.txt"),
+          Charsets.UTF_8)), nginx.render(OsFamily.UNIX));
+  }
+
+}

Added: whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/InstallModuleFromGitTest.java
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/InstallModuleFromGitTest.java?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/InstallModuleFromGitTest.java
(added)
+++ whirr/trunk/services/puppet/src/test/java/org/apache/whirr/service/puppet/statements/InstallModuleFromGitTest.java
Tue Sep 20 00:44:22 2011
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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.apache.whirr.service.puppet.statements;
+
+import static junit.framework.Assert.assertEquals;
+
+import java.net.URI;
+
+import org.jclouds.scriptbuilder.domain.OsFamily;
+import org.junit.Test;
+
+public class InstallModuleFromGitTest {
+
+  @Test
+  public void testWhenModuleAndURIValid() {
+
+    InstallModuleFromGit nginx = new InstallModuleFromGit("nginx", URI
+          .create("git://github.com/puppetlabs/puppetlabs-nginx.git"));
+
+    assertEquals("git clone git://github.com/puppetlabs/puppetlabs-nginx.git /etc/puppet/modules/nginx\n",
nginx
+          .render(OsFamily.UNIX));
+  }
+
+  @Test
+  public void testWhenModuleAndURIAndBranchValid() {
+
+    InstallModuleFromGit nginx = new InstallModuleFromGit("nginx", URI
+          .create("git://github.com/puppetlabs/puppetlabs-nginx.git"), "WHIRR-385");
+
+    assertEquals("git clone -b WHIRR-385 git://github.com/puppetlabs/puppetlabs-nginx.git
/etc/puppet/modules/nginx\n", nginx
+          .render(OsFamily.UNIX));
+  }
+}
+

Added: whirr/trunk/services/puppet/src/test/resources/log4j.xml
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/resources/log4j.xml?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/resources/log4j.xml (added)
+++ whirr/trunk/services/puppet/src/test/resources/log4j.xml Tue Sep 20 00:44:22 2011
@@ -0,0 +1,196 @@
+<?xml version="1.0" encoding="UTF-8"?>
+    <!--
+   Licensed to the Apache Software Foundation (ASF) under one
+   or more contributor license agreements.  See the NOTICE file
+   distributed with this work for additional information
+   regarding copyright ownership.  The ASF 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.
+    -->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+    <!--
+        For more configuration infromation and examples see the Apache
+        Log4j website: http://logging.apache.org/log4j/
+    -->
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
+    debug="false">
+    
+    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+        <param name="Threshold" value="INFO" />
+        <layout class="org.apache.log4j.PatternLayout"> 
+            <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/> 
+        </layout> 
+    </appender>
+
+    <!-- A time/date based rolling appender -->
+    <appender name="WIREFILE" class="org.apache.log4j.DailyRollingFileAppender">
+        <param name="File" value="target/test-data/jclouds-wire.log" />
+        <param name="Append" value="true" />
+
+        <!-- Rollover at midnight each day -->
+        <param name="DatePattern" value="'.'yyyy-MM-dd" />
+
+        <param name="Threshold" value="TRACE" />
+
+        <layout class="org.apache.log4j.PatternLayout">
+            <!-- The default pattern: Date Priority [Category] Message\n -->
+            <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
+
+            <!--
+                The full pattern: Date MS Priority [Category]
+                (Thread:NDC) Message\n <param name="ConversionPattern"
+                value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+            -->
+        </layout>
+    </appender>
+
+    <!-- A time/date based rolling appender -->
+    <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
+        <param name="File" value="target/test-data/jclouds.log" />
+        <param name="Append" value="true" />
+
+        <!-- Rollover at midnight each day -->
+        <param name="DatePattern" value="'.'yyyy-MM-dd" />
+
+        <param name="Threshold" value="TRACE" />
+
+        <layout class="org.apache.log4j.PatternLayout">
+            <!-- The default pattern: Date Priority [Category] Message\n -->
+            <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
+
+            <!--
+                The full pattern: Date MS Priority [Category]
+                (Thread:NDC) Message\n <param name="ConversionPattern"
+                value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+            -->
+        </layout>
+    </appender>
+
+    <!-- A time/date based rolling appender -->
+    <appender name="BLOBSTOREFILE" class="org.apache.log4j.DailyRollingFileAppender">
+        <param name="File" value="target/test-data/jclouds-blobstore.log" />
+        <param name="Append" value="true" />
+        <param name="DatePattern" value="'.'yyyy-MM-dd" />
+        <param name="Threshold" value="TRACE" />
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
+        </layout>
+    </appender>
+    
+
+    <!-- A time/date based rolling appender -->
+    <appender name="COMPUTEFILE" class="org.apache.log4j.DailyRollingFileAppender">
+        <param name="File" value="target/test-data/jclouds-compute.log" />
+        <param name="Append" value="true" />
+
+        <!-- Rollover at midnight each day -->
+        <param name="DatePattern" value="'.'yyyy-MM-dd" />
+
+        <param name="Threshold" value="TRACE" />
+
+        <layout class="org.apache.log4j.PatternLayout">
+            <!-- The default pattern: Date Priority [Category] Message\n -->
+            <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
+
+            <!--
+                The full pattern: Date MS Priority [Category]
+                (Thread:NDC) Message\n <param name="ConversionPattern"
+                value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+            -->
+        </layout>
+    </appender>
+    
+    <!-- A time/date based rolling appender -->
+    <appender name="WHIRRFILE" class="org.apache.log4j.DailyRollingFileAppender">
+        <param name="File" value="target/test-data/whirr.log" />
+        <param name="Append" value="true" />
+
+        <!-- Rollover at midnight each day -->
+        <param name="DatePattern" value="'.'yyyy-MM-dd" />
+
+        <param name="Threshold" value="TRACE" />
+
+        <layout class="org.apache.log4j.PatternLayout">
+            <!-- The default pattern: Date Priority [Category] Message\n -->
+            <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
+
+            <!--
+                The full pattern: Date MS Priority [Category]
+                (Thread:NDC) Message\n <param name="ConversionPattern"
+                value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
+            -->
+        </layout>
+    </appender>
+
+    <appender name="ASYNCCOMPUTE" class="org.apache.log4j.AsyncAppender">
+        <appender-ref ref="COMPUTEFILE" />
+    </appender>
+    <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
+        <appender-ref ref="FILE" />
+    </appender>
+
+    <appender name="ASYNCWIRE" class="org.apache.log4j.AsyncAppender">
+        <appender-ref ref="WIREFILE" />
+    </appender>
+
+    <appender name="ASYNCBLOBSTORE" class="org.apache.log4j.AsyncAppender">
+        <appender-ref ref="BLOBSTOREFILE" />
+    </appender>
+    <!-- ================ -->
+    <!-- Limit categories -->
+    <!-- ================ -->
+    <category name="jclouds.blobstore">
+        <priority value="DEBUG" />
+        <appender-ref ref="ASYNCBLOBSTORE" />
+    </category>
+
+    <category name="org.jclouds">
+        <priority value="DEBUG" />
+        <appender-ref ref="ASYNC" />
+    </category>
+    
+    <category name="org.apache.whirr">
+        <priority value="DEBUG" />
+        <appender-ref ref="WHIRRFILE" />
+    </category>
+
+    <category name="jclouds.headers">
+        <priority value="DEBUG" />
+        <appender-ref ref="ASYNCWIRE" />
+    </category>
+    <category name="jclouds.compute">
+        <priority value="DEBUG" />
+        <appender-ref ref="ASYNCCOMPUTE" />
+    </category>
+
+    <category name="jclouds.wire">
+        <priority value="DEBUG" />
+        <appender-ref ref="ASYNCWIRE" />
+    </category><!--
+    
+       <category name="jclouds.signature">
+        <priority value="DEBUG" />
+        <appender-ref ref="ASYNCWIRE" />
+    </category>
+    
+    
+    --><!--  ======================= -->
+    <!-- Setup the Root category -->
+    <!-- ======================= -->
+
+    <root>
+        <priority value="WARN" />
+        <appender-ref ref="CONSOLE" />
+    </root>
+
+</log4j:configuration>
\ No newline at end of file

Added: whirr/trunk/services/puppet/src/test/resources/nginx-with-attribs.txt
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/resources/nginx-with-attribs.txt?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/resources/nginx-with-attribs.txt (added)
+++ whirr/trunk/services/puppet/src/test/resources/nginx-with-attribs.txt Tue Sep 20 00:44:22
2011
@@ -0,0 +1,9 @@
+rm /etc/puppet/manifests/site.pp
+cat >> /etc/puppet/manifests/site.pp <<'END_OF_FILE'
+node default {
+class { 'nginx::server':
+  hostname => foohost,
+}
+}
+END_OF_FILE
+puppet apply /etc/puppet/manifests/site.pp

Added: whirr/trunk/services/puppet/src/test/resources/whirr-puppet-test.properties
URL: http://svn.apache.org/viewvc/whirr/trunk/services/puppet/src/test/resources/whirr-puppet-test.properties?rev=1172926&view=auto
==============================================================================
--- whirr/trunk/services/puppet/src/test/resources/whirr-puppet-test.properties (added)
+++ whirr/trunk/services/puppet/src/test/resources/whirr-puppet-test.properties Tue Sep 20
00:44:22 2011
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF 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.
+#
+whirr.cluster-name=puppettest
+
+# Change the number of machines in the cluster here
+whirr.instance-templates=1 puppet:apache+puppet:ntp
+whirr.firewall-rules=80
+
+# with puppet, you need to specify where to pull the modules from
+puppet.apache.module=git://github.com/metcalfc/puppet-apache.git
+puppet.ntp.module=git://github.com/puppetlabs/puppetlabs-ntp.git
+
+# with puppet, you can set class parameters
+ntp.servers=[ '0.pool.ntp.org', 'clock.redhat.com' ]
+ntp.autoupdate=true
+
+whirr.provider=${sys:whirr.test.provider}
+whirr.identity=${sys:whirr.test.identity}
+whirr.credential=${sys:whirr.test.credential}



Mime
View raw message