brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/2] incubator-brooklyn git commit: BROOKLYN-188: set PATH in JcloudsLocation.createUser
Date Thu, 22 Oct 2015 23:46:58 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master ddcebe8df -> 5bee1915a


BROOKLYN-188: set PATH in JcloudsLocation.createUser


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/77b6d12d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/77b6d12d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/77b6d12d

Branch: refs/heads/master
Commit: 77b6d12d0161fc6c39b715b7293674ef0aedc354
Parents: ddcebe8
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Oct 22 23:42:46 2015 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri Oct 23 00:03:26 2015 +0100

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       |   7 +-
 .../location/jclouds/JcloudsSuseLiveTest.java   | 102 +++++++++++++++++++
 2 files changed, 108 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77b6d12d/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index 9c87479..4e322bd 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static java.util.concurrent.TimeUnit.SECONDS;
 import static org.apache.brooklyn.util.JavaGroovyEquivalents.elvis;
 import static org.apache.brooklyn.util.JavaGroovyEquivalents.groovyTruth;
+import static org.apache.brooklyn.util.ssh.BashCommands.sbinPath;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -1643,7 +1644,11 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
                         sshLoc = new SshMachineLocation(sshProps);
                     }
     
-                    int exitcode = sshLoc.execScript(execProps, "create-user", commands);
+                    // BROOKLYN-188: for SUSE, need to specify the path (for groupadd, useradd,
etc)
+                    Map<String, ?> env = ImmutableMap.of("PATH", sbinPath());
+                    
+                    int exitcode = sshLoc.execScript(execProps, "create-user", commands,
env);
+
                     if (exitcode != 0) {
                         LOG.warn("exit code {} when creating user for {}; usage may subsequently
fail", exitcode, node);
                     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/77b6d12d/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSuseLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSuseLiveTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSuseLiveTest.java
new file mode 100644
index 0000000..a8019a68
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSuseLiveTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.brooklyn.location.jclouds;
+
+import java.util.Map;
+
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.core.location.Locations;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
+import org.apache.brooklyn.util.collections.MutableMap;
+import org.apache.brooklyn.util.os.Os;
+import org.apache.brooklyn.util.ssh.BashCommands;
+import org.apache.brooklyn.util.stream.Streams;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Extra-special tests for deploying SUSE VMs, because we've had so many problems. For example:
+ * <ul>
+ *   <li>{@code groupadd -f}:  You are using an undocumented option (-f); and exits
with 9
+ *   <li>path does not by default contain groupadd etc (see {@link BashCommands#sbinPath()}
+ * </ul>
+ */
+public class JcloudsSuseLiveTest extends AbstractJcloudsLiveTest {
+
+    public static final String AWS_EC2_REGION_NAME = AWS_EC2_USEAST_REGION_NAME;
+    public static final String AWS_EC2_LOCATION_SPEC = "jclouds:" + AWS_EC2_PROVIDER + (AWS_EC2_REGION_NAME
== null ? "" : ":" + AWS_EC2_REGION_NAME);
+    public static final String AWS_IMAGE_ID = "us-east-1/ami-8dd105e6";
+    
+    // TODO Also requires https://github.com/jclouds/jclouds/pull/827
+    @Test(groups = {"Live", "WIP"})
+    protected void testSuseUsingJcloudsSshInit() throws Exception {
+        jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve(AWS_EC2_LOCATION_SPEC);
+        
+        JcloudsSshMachineLocation machine = createEc2Machine(ImmutableMap.<String,Object>of(
+                JcloudsLocation.USE_JCLOUDS_SSH_INIT.getName(), true,
+                JcloudsLocation.USER.getName(), "myname"));
+        assertSshable(machine);
+        
+        assertSshable(ImmutableMap.builder()
+                .put("address", machine.getAddress())
+                .put("user", "myname")
+                .put(SshMachineLocation.PRIVATE_KEY_FILE, Os.tidyPath("~/.ssh/id_rsa"))
+                .build());
+    }
+    
+    // TODO Also requires https://github.com/jclouds/jclouds/pull/??? (see BROOKLYN-188,
for checking if group exists)
+    @Test(groups = {"Live", "WIP"})
+    protected void testSuseSkippingJcloudsSshInit() throws Exception {
+        jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve(AWS_EC2_LOCATION_SPEC);
+        
+        JcloudsSshMachineLocation machine = createEc2Machine(ImmutableMap.<String,Object>of(
+                JcloudsLocation.USE_JCLOUDS_SSH_INIT.getName(), false,
+                JcloudsLocation.USER.getName(), "myname"));
+        assertSshable(machine);
+        
+        assertSshable(ImmutableMap.builder()
+                .put("address", machine.getAddress())
+                .put("user", "myname")
+                .put(SshMachineLocation.PRIVATE_KEY_FILE, Os.tidyPath("~/.ssh/id_rsa"))
+                .build());
+    }
+    
+    private JcloudsSshMachineLocation createEc2Machine(Map<String,? extends Object>
conf) throws Exception {
+        return obtainMachine(MutableMap.<String,Object>builder()
+                .putAll(conf)
+                .putIfAbsent("imageId", AWS_IMAGE_ID)
+                .putIfAbsent("loginUser", "ec2-user")
+                .putIfAbsent("hardwareId", AWS_EC2_SMALL_HARDWARE_ID)
+                .putIfAbsent("inboundPorts", ImmutableList.of(22))
+                .build());
+    }
+
+    protected void assertSshable(Map<?,?> machineConfig) {
+        SshMachineLocation machineWithThatConfig = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
+                .configure(machineConfig));
+        try {
+            assertSshable(machineWithThatConfig);
+        } finally {
+            Streams.closeQuietly(machineWithThatConfig);
+            Locations.unmanage(machineWithThatConfig);
+        }
+    }
+}


Mime
View raw message