You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ha...@apache.org on 2015/08/14 05:42:41 UTC
[12/54] incubator-brooklyn git commit: [BROOKLYN-162] Renaming
package brooklyn.location
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsAddressesLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsAddressesLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsAddressesLiveTest.java
deleted file mode 100644
index 2d5d511..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsAddressesLiveTest.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.io.ByteArrayOutputStream;
-import java.io.OutputStream;
-import java.net.InetAddress;
-import java.util.Map;
-import java.util.Set;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-import brooklyn.location.LocationSpec;
-import brooklyn.location.basic.Locations;
-import brooklyn.location.basic.SshMachineLocation;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.stream.Streams;
-
-/**
- * Tests that the correct address is advertised for the VM - for its public/private,
- * its subnet hostname, etc.
- */
-public class JcloudsAddressesLiveTest extends AbstractJcloudsLiveTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(JcloudsAddressesLiveTest.class);
-
- 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);
-
- // Image: {id=us-east-1/ami-7d7bfc14, providerId=ami-7d7bfc14, name=RightImage_CentOS_6.3_x64_v5.8.8.5, location={scope=REGION, id=us-east-1, description=us-east-1, parent=aws-ec2, iso3166Codes=[US-VA]}, os={family=centos, arch=paravirtual, version=6.0, description=rightscale-us-east/RightImage_CentOS_6.3_x64_v5.8.8.5.manifest.xml, is64Bit=true}, description=rightscale-us-east/RightImage_CentOS_6.3_x64_v5.8.8.5.manifest.xml, version=5.8.8.5, status=AVAILABLE[available], loginUser=root, userMetadata={owner=411009282317, rootDeviceType=instance-store, virtualizationType=paravirtual, hypervisor=xen}}
- public static final String AWS_EC2_CENTOS_IMAGE_ID = "us-east-1/ami-7d7bfc14";
-
- // Image: {id=us-east-1/ami-d0f89fb9, providerId=ami-d0f89fb9, name=ubuntu/images/ebs/ubuntu-precise-12.04-amd64-server-20130411.1, location={scope=REGION, id=us-east-1, description=us-east-1, parent=aws-ec2, iso3166Codes=[US-VA]}, os={family=ubuntu, arch=paravirtual, version=12.04, description=099720109477/ubuntu/images/ebs/ubuntu-precise-12.04-amd64-server-20130411.1, is64Bit=true}, description=099720109477/ubuntu/images/ebs/ubuntu-precise-12.04-amd64-server-20130411.1, version=20130411.1, status=AVAILABLE[available], loginUser=ubuntu, userMetadata={owner=099720109477, rootDeviceType=ebs, virtualizationType=paravirtual, hypervisor=xen}}
- public static final String AWS_EC2_UBUNTU_IMAGE_ID = "us-east-1/ami-d0f89fb9";
-
- // Image: {id=us-east-1/ami-5e008437, providerId=ami-5e008437, name=RightImage_Ubuntu_10.04_x64_v5.8.8.3, location={scope=REGION, id=us-east-1, description=us-east-1, parent=aws-ec2, iso3166Codes=[US-VA]}, os={family=ubuntu, arch=paravirtual, version=10.04, description=rightscale-us-east/RightImage_Ubuntu_10.04_x64_v5.8.8.3.manifest.xml, is64Bit=true}, description=rightscale-us-east/RightImage_Ubuntu_10.04_x64_v5.8.8.3.manifest.xml, version=5.8.8.3, status=AVAILABLE[available], loginUser=root, userMetadata={owner=411009282317, rootDeviceType=instance-store, virtualizationType=paravirtual, hypervisor=xen}}
- // Uses "root" as loginUser
- public static final String AWS_EC2_UBUNTU_10_IMAGE_ID = "us-east-1/ami-5e008437";
-
- public static final String RACKSPACE_LOCATION_SPEC = "jclouds:" + RACKSPACE_PROVIDER;
-
- // Image: {id=LON/c52a0ca6-c1f2-4cd1-b7d6-afbcd1ebda22, providerId=c52a0ca6-c1f2-4cd1-b7d6-afbcd1ebda22, name=CentOS 6.0, location={scope=ZONE, id=LON, description=LON, parent=rackspace-cloudservers-uk, iso3166Codes=[GB-SLG]}, os={family=centos, name=CentOS 6.0, version=6.0, description=CentOS 6.0, is64Bit=true}, description=CentOS 6.0, status=AVAILABLE, loginUser=root, userMetadata={os_distro=centos, com.rackspace__1__visible_core=1, com.rackspace__1__build_rackconnect=1, com.rackspace__1__options=0, image_type=base, cache_in_nova=True, com.rackspace__1__source=kickstart, org.openstack__1__os_distro=org.centos, com.rackspace__1__release_build_date=2013-07-25_18-56-29, auto_disk_config=True, com.rackspace__1__release_version=5, os_type=linux, com.rackspace__1__visible_rackconnect=1, com.rackspace__1__release_id=210, com.rackspace__1__visible_managed=0, com.rackspace__1__build_core=1, org.openstack__1__os_version=6.0, org.openstack__1__architecture=x64, com.rackspace__1__build_ma
naged=0}}
- public static final String RACKSPACE_CENTOS_IMAGE_NAME_REGEX = "CentOS 6.0";
-
- protected JcloudsSshMachineLocation machine;
-
- @Test(groups = {"Live"})
- protected void testAwsEc2Addresses() throws Exception {
- jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve(AWS_EC2_LOCATION_SPEC);
-
- machine = createEc2Machine(ImmutableMap.<String,Object>of());
- assertSshable(machine);
-
- String locationAddress = machine.getAddress().getHostName();
- InetAddress address = machine.getAddress();
- Set<String> publicAddresses = machine.getPublicAddresses();
- Set<String> privateAddresses = machine.getPrivateAddresses();
- String subnetIp = machine.getSubnetIp();
- String hostname = machine.getHostname();
- String subnetHostname = machine.getSubnetHostname();
- String msg = "locationAddress="+locationAddress+"; address="+address+"; publicAddrs="+publicAddresses+"; privateAddrs="+privateAddresses+"; subnetIp="+subnetIp+"; hostname="+hostname+"; subnetHostname="+subnetHostname;
- LOG.info("node: "+msg);
-
- // On AWS, machine advertises its FQ hostname that is accessible from inside and outside the region
- assertReachable(machine, locationAddress, msg);
- assertReachableFromMachine(machine, locationAddress, msg);
-
- assertReachable(machine, address, msg);
-
- assertTrue(publicAddresses.size() > 0, msg);
- for (String publicAddress: publicAddresses) {
- assertReachable(machine, publicAddress, msg);
- }
-
- // On AWS, private address is not reachable from outside.
- // If you ran this test from the same AWS region, it would fail!
- assertTrue(privateAddresses.size() > 0, msg);
- for (String privateAddress: privateAddresses) {
- assertReachableFromMachine(machine, privateAddress, msg);
- assertNotReachable(machine, privateAddress, msg);
- }
-
- assertNotNull(subnetIp, msg);
- assertReachableFromMachine(machine, subnetIp, msg);
-
- // hostname is reachable from inside; not necessarily reachable from outside
- assertNotNull(hostname, msg);
- assertReachableFromMachine(machine, hostname, msg);
-
- assertNotNull(subnetHostname, msg);
- assertReachableFromMachine(machine, subnetHostname, msg);
- }
-
- @Test(groups = {"Live"})
- protected void testRackspaceAddresses() throws Exception {
- jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve(RACKSPACE_LOCATION_SPEC);
-
- machine = createRackspaceMachine(ImmutableMap.<String,Object>of());
- assertSshable(machine);
-
- String locationAddress = machine.getAddress().getHostAddress();
- InetAddress address = machine.getAddress();
- Set<String> publicAddresses = machine.getPublicAddresses();
- Set<String> privateAddresses = machine.getPrivateAddresses();
- String subnetIp = machine.getSubnetIp();
- String hostname = machine.getHostname();
- String subnetHostname = machine.getSubnetHostname();
- String msg = "locationAddress="+locationAddress+"; address="+address+"; publicAddrs="+publicAddresses+"; privateAddrs="+privateAddresses+"; subnetIp="+subnetIp+"; hostname="+hostname+"; subnetHostname="+subnetHostname;
- LOG.info("node: "+msg);
-
- // On Rackspace, IP is accessible from inside and outside.
- assertReachable(machine, locationAddress, msg);
- assertReachableFromMachine(machine, locationAddress, msg);
-
- assertReachable(machine, address, msg);
-
- assertTrue(publicAddresses.size() > 0, msg);
- for (String publicAddress: publicAddresses) {
- assertReachable(machine, publicAddress, msg);
- }
-
- // On Rackspace, don't care if no private addresses
- for (String privateAddress: privateAddresses) {
- assertReachableFromMachine(machine, privateAddress, msg);
- assertNotReachable(machine, privateAddress, msg);
- }
-
- assertNotNull(subnetIp, msg);
- assertReachableFromMachine(machine, subnetIp, msg);
-
- // hostname is reachable from inside; not necessarily reachable from outside
- assertNotNull(hostname, msg);
- assertReachableFromMachine(machine, hostname, msg);
-
- assertNotNull(subnetHostname, msg);
- assertReachableFromMachine(machine, subnetHostname, msg);
- }
-
- private void assertReachable(SshMachineLocation machine, InetAddress addr, String msg) {
- assertReachable(machine, addr.getHostAddress(), msg);
- }
-
- private void assertReachable(SshMachineLocation machine, String addr, String msg) {
- assertReachability(true, machine, addr, msg);
- }
-
- private void assertNotReachable(SshMachineLocation machine, String addr, String msg) {
- assertReachability(false, machine, addr, msg);
- }
-
- private void assertReachability(boolean expectedReachable, SshMachineLocation machine, String addr, String msg) {
- SshMachineLocation tmpMachine = managementContext.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
- .configure(machine.config().getBag().getAllConfig())
- .configure("address", addr));
- try {
- boolean sshable = tmpMachine.isSshable();
- assertEquals(sshable, expectedReachable, addr+" not sshable; "+msg);
- } finally {
- Locations.unmanage(tmpMachine);
- }
- }
-
- // TODO Assumes that "ping" will work; i.e. that ICMP is not firewall'ed
- private void assertReachableFromMachine(SshMachineLocation machine, String addr, String msg) {
- OutputStream outStream = new ByteArrayOutputStream();
- OutputStream errStream = new ByteArrayOutputStream();
- int result = machine.execScript(MutableMap.of("out", outStream, "err", errStream), "reach "+addr, ImmutableList.of("ping -c 1 "+addr));
- String outString = outStream.toString();
- String errString = errStream.toString();
- assertEquals(result, 0, "result="+0+"; err="+errString+"; out="+outString+"; msg="+msg);
- }
-
- @Override
- protected void releaseMachine(JcloudsSshMachineLocation machine) {
- jcloudsLocation.release(machine);
- }
-
- private JcloudsSshMachineLocation createEc2Machine(Map<String,? extends Object> conf) throws Exception {
- return obtainMachine(MutableMap.<String,Object>builder()
- .putAll(conf)
- .putIfAbsent("imageId", AWS_EC2_CENTOS_IMAGE_ID)
- .putIfAbsent("hardwareId", AWS_EC2_SMALL_HARDWARE_ID)
- .putIfAbsent("inboundPorts", ImmutableList.of(22))
- .build());
- }
-
- private JcloudsSshMachineLocation createRackspaceMachine(Map<String,? extends Object> conf) throws Exception {
- return obtainMachine(MutableMap.<String,Object>builder()
- .putAll(conf)
- .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);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java
deleted file mode 100644
index 822bae0..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverAwsLiveTest.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.net.InetAddress;
-import java.util.Map;
-import java.util.Set;
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import brooklyn.location.basic.FixedListMachineProvisioningLocation;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.util.collections.MutableMap;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-public class JcloudsByonLocationResolverAwsLiveTest extends AbstractJcloudsLiveTest {
-
- private static final String AWS_REGION = "eu-west-1";
- private static final String AWS_LOCATION_SPEC = "jclouds:aws-ec2:"+AWS_REGION;
-
- private String awsVmUser;
- private String awsVmInstanceId;
- private String awsVmIp;
- private String awsVmHostname;
-
- private LocalManagementContext classManagementContext;
- private JcloudsLocation classEc2Loc;
- private JcloudsSshMachineLocation classEc2Vm;
-
- @BeforeClass(groups="Live")
- public void setUpClass() throws Exception {
- classManagementContext = newManagementContext();
- classEc2Loc = (JcloudsLocation) classManagementContext.getLocationRegistry().resolve(AWS_LOCATION_SPEC);
- classEc2Vm = (JcloudsSshMachineLocation)classEc2Loc.obtain(MutableMap.<String,Object>builder()
- .put("hardwareId", AWS_EC2_SMALL_HARDWARE_ID)
- .put("inboundPorts", ImmutableList.of(22))
- .build());
- awsVmUser = classEc2Vm.getUser();
- awsVmInstanceId = classEc2Vm.getNode().getProviderId(); // id without region (e.g. "i-6ff96d2f" instead of "eu-west-1/i-6ff96d2f")
- awsVmIp = classEc2Vm.getAddress().getHostAddress();
- awsVmHostname = classEc2Vm.getAddress().getHostName();
- }
-
- @AfterClass(alwaysRun=true)
- public void tearDownClass() throws Exception {
- try {
- if (classEc2Vm != null) {
- classEc2Loc.release(classEc2Vm);
- }
- } finally {
- if (classManagementContext != null) classManagementContext.terminate();
- }
- }
-
- // TODO Requires that a VM already exists; could create that VM first to make test more robust
- @Test(groups={"Live"})
- public void testResolvesJcloudsByonAws() throws Exception {
- String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\""+AWS_REGION+"\",user=\""+awsVmUser+"\",hosts=\""+awsVmInstanceId+"\",anotherprop=myval)";
-
- FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> loc = resolve(spec);
-
- Set<JcloudsSshMachineLocation> machines = loc.getAllMachines();
- JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines);
- assertEquals(machine.getParent().getProvider(), "aws-ec2");
- assertEquals(machine.getAddress().getHostAddress(), awsVmIp);
- assertEquals(machine.getAddress().getHostName(), awsVmHostname);
- assertEquals(machine.getUser(), awsVmUser);
- assertEquals(machine.config().getBag().getStringKey("anotherprop"), "myval");
-
- assertTrue(machine.isSshable());
- }
-
- @Test(groups={"Live"})
- public void testResolvesNamedJcloudsByon() throws Exception {
- String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\""+AWS_REGION+"\",user=\""+awsVmUser+"\",hosts=\""+awsVmInstanceId+"\")";
- brooklynProperties.put("brooklyn.location.named.mynamed", spec);
-
- FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> loc = resolve("named:mynamed");
- assertEquals(loc.obtain().getAddress(), InetAddress.getByName(awsVmHostname));
- }
-
- @Test(groups={"Live"})
- public void testJcloudsPropertiesPrecedence() throws Exception {
- String spec = "jcloudsByon:(provider=\"aws-ec2\",region=\""+AWS_REGION+"\",user=\""+awsVmUser+"\",hosts=\""+awsVmInstanceId+"\")";
- brooklynProperties.put("brooklyn.location.named.mynamed", spec);
-
- // prefer those in spec string over everything else
- brooklynProperties.put("brooklyn.location.named.mynamed.user", "user-inNamed");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.user", "user-inProviderSpecific");
- brooklynProperties.put("brooklyn.jclouds.aws-ec2.user", "user-inProviderSpecificDeprecated");
- brooklynProperties.put("brooklyn.location.jclouds.user", "user-inJcloudsGeneric");
- brooklynProperties.put("brooklyn.jclouds.user", "user-inJcloudsGenericDeprecated");
- brooklynProperties.put("brooklyn.location.user", "user-inLocationGeneric");
-
- // prefer those in "named" over everything else (except spec string itself)
- brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyFile", "privateKeyFile-inNamed");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecific");
- brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecificDeprecated");
- brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGeneric");
- brooklynProperties.put("brooklyn.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGenericDeprecated");
- brooklynProperties.put("brooklyn.location.privateKeyFile", "privateKeyFile-inLocationGeneric");
-
- // prefer those in provider-specific over generic
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecific");
- brooklynProperties.put("brooklyn.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecificDeprecated");
- brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGeneric");
- brooklynProperties.put("brooklyn.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGenericDeprecated");
- brooklynProperties.put("brooklyn.location.publicKeyFile", "publicKeyFile-inLocationGeneric");
-
- // prefer those in provider-specific (deprecated scope) over generic
- brooklynProperties.put("brooklyn.jclouds.aws-ec2.securityGroups", "securityGroups-inProviderSpecificDeprecated");
- brooklynProperties.put("brooklyn.location.jclouds.securityGroups", "securityGroups-inJcloudsGeneric");
- brooklynProperties.put("brooklyn.jclouds.securityGroups", "securityGroups-inJcloudsGenericDeprecated");
- brooklynProperties.put("brooklyn.location.securityGroups", "securityGroups-inLocationGeneric");
-
- // prefer those in jclouds-generic over location-generic
- brooklynProperties.put("brooklyn.location.jclouds.loginUser", "loginUser-inJcloudsGeneric");
- brooklynProperties.put("brooklyn.jclouds.loginUser", "loginUser-inJcloudsGenericDeprecated");
- brooklynProperties.put("brooklyn.location.loginUser", "loginUser-inLocationGeneric");
-
- // prefer those in jclouds-generic (deprecated) over location-generic
- brooklynProperties.put("brooklyn.jclouds.imageId", "imageId-inJcloudsGenericDeprecated");
- brooklynProperties.put("brooklyn.location.imageId", "imageId-inLocationGeneric");
-
- // prefer location-generic if nothing else
- brooklynProperties.put("brooklyn.location.keyPair", "keyPair-inLocationGeneric");
-
- // prefer deprecated properties in "named" over those less specific
- brooklynProperties.put("brooklyn.location.named.mynamed.private-key-data", "privateKeyData-inNamed");
- brooklynProperties.put("brooklyn.jclouds.aws-ec2.privateKeyData", "privateKeyData-inProviderSpecific");
- brooklynProperties.put("brooklyn.jclouds.privateKeyData", "privateKeyData-inJcloudsGeneric");
-
- // prefer "named" over everything else: confirm deprecated don't get transformed to overwrite it accidentally
- brooklynProperties.put("brooklyn.location.named.mynamed.privateKeyPassphrase", "privateKeyPassphrase-inNamed");
- brooklynProperties.put("brooklyn.jclouds.aws-ec2.private-key-passphrase", "privateKeyPassphrase-inProviderSpecific");
- brooklynProperties.put("brooklyn.jclouds.private-key-passphrase", "privateKeyPassphrase-inJcloudsGeneric");
-
- Map<String, Object> conf = resolve("named:mynamed").obtain().config().getBag().getAllConfig();
-
- assertEquals(conf.get("user"), awsVmUser);
- assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed");
- assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific");
- assertEquals(conf.get("securityGroups"), "securityGroups-inProviderSpecificDeprecated");
- assertEquals(conf.get("loginUser"), "loginUser-inJcloudsGeneric");
- assertEquals(conf.get("imageId"), "imageId-inJcloudsGenericDeprecated");
- assertEquals(conf.get("keyPair"), "keyPair-inLocationGeneric");
- assertEquals(conf.get("privateKeyData"), "privateKeyData-inNamed");
- assertEquals(conf.get("privateKeyPassphrase"), "privateKeyPassphrase-inNamed");
- }
-
- @SuppressWarnings("unchecked")
- private FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> resolve(String spec) {
- return (FixedListMachineProvisioningLocation<JcloudsSshMachineLocation>) managementContext.getLocationRegistry().resolve(spec);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java
deleted file mode 100644
index b60d4e8..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverSoftlayerLiveTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Set;
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import brooklyn.location.basic.FixedListMachineProvisioningLocation;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.util.collections.MutableMap;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-
-public class JcloudsByonLocationResolverSoftlayerLiveTest extends AbstractJcloudsLiveTest {
-
- private static final String SOFTLAYER_REGION = "dal05";
- private static final String SOFTLAYER_LOCATION_SPEC = "jclouds:softlayer:"+SOFTLAYER_REGION;
-
- private String slVmUser;
- private String slVmInstanceId;
- private String slVmIp;
- private String slVmHostname;
-
- private LocalManagementContext classManagementContext;
- private JcloudsLocation classEc2Loc;
- private JcloudsSshMachineLocation classVm;
-
- @BeforeClass(groups="Live")
- public void setUpClass() throws Exception {
- classManagementContext = newManagementContext();
- classEc2Loc = (JcloudsLocation) classManagementContext.getLocationRegistry().resolve(SOFTLAYER_LOCATION_SPEC);
- classVm = (JcloudsSshMachineLocation)classEc2Loc.obtain(MutableMap.<String,Object>builder()
- .put("inboundPorts", ImmutableList.of(22))
- .build());
- slVmUser = classVm.getUser();
- slVmInstanceId = classVm.getJcloudsId();
- slVmIp = classVm.getAddress().getHostAddress();
- slVmHostname = classVm.getNode().getHostname();
- }
-
- @AfterClass(alwaysRun=true)
- public void tearDownClass() throws Exception {
- try {
- if (classVm != null) {
- classEc2Loc.release(classVm);
- }
- } finally {
- if (classManagementContext != null) classManagementContext.terminate();
- }
- }
-
- @Test(groups={"Live"})
- public void testResolvesJcloudsByonSoftlayer() throws Exception {
- checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\""+SOFTLAYER_REGION+"\",hosts=\""+slVmInstanceId+"\",user=\""+slVmUser+"\")");
- checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\""+SOFTLAYER_REGION+"\",hosts=\""+slVmHostname+"\")");
- checkSoftlayer("jcloudsByon:(provider=\"softlayer\",region=\""+SOFTLAYER_REGION+"\",hosts=\""+slVmIp+"\")");
- checkSoftlayer("jcloudsByon:(provider=\"softlayer\",hosts=\""+slVmIp+"\")");
- }
-
- private void checkSoftlayer(String spec) {
- FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> loc = resolve(spec);
-
- Set<JcloudsSshMachineLocation> machines = loc.getAllMachines();
- JcloudsSshMachineLocation machine = Iterables.getOnlyElement(machines);
- assertEquals(machine.getParent().getProvider(), "softlayer");
- assertEquals(machine.getNode().getId(), slVmInstanceId);
- assertEquals(machine.getAddress().getHostAddress(), slVmIp);
- assertTrue(slVmHostname.equals(machine.getAddress().getHostName()) || slVmIp.equals(machine.getAddress().getHostName()),
- "address hostname is: "+machine.getAddress().getHostName());
- assertTrue(slVmHostname.equals(machine.getNode().getHostname()) || slVmIp.equals(machine.getNode().getHostname()),
- "node hostname is: "+machine.getNode().getHostname());
-
- // could also assert this, given a user credential, but not currently set up
-// assertTrue(machine.isSshable());
- }
-
- @SuppressWarnings("unchecked")
- private FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> resolve(String spec) {
- return (FixedListMachineProvisioningLocation<JcloudsSshMachineLocation>) managementContext.getLocationRegistry().resolve(spec);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java
deleted file mode 100644
index 44af0c7..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsByonLocationResolverTest.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static org.testng.Assert.fail;
-
-import java.util.NoSuchElementException;
-
-import org.apache.brooklyn.test.entity.LocalManagementContextForTests;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.basic.Entities;
-import brooklyn.location.basic.FixedListMachineProvisioningLocation;
-import brooklyn.management.internal.LocalManagementContext;
-
-public class JcloudsByonLocationResolverTest {
-
- private LocalManagementContext managementContext;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- managementContext = LocalManagementContextForTests.newInstance();
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (managementContext != null) Entities.destroyAll(managementContext);
- }
-
- @Test
- public void testThrowsOnInvalid() throws Exception {
- assertThrowsNoSuchElement("wrongprefix:(hosts=\"1.1.1.1\")");
- assertThrowsIllegalArgument("jcloudsByon"); // no hosts
- assertThrowsIllegalArgument("jcloudsByon:()"); // no hosts
- assertThrowsIllegalArgument("jcloudsByon:(hosts=\"\")"); // empty hosts
- assertThrowsIllegalArgument("jcloudsByon:(hosts=\"i-72b1b132\""); // no closing bracket
- assertThrowsIllegalArgument("jcloudsByon:(hosts=\"i-72b1b132\", name)"); // no value for name
- assertThrowsIllegalArgument("jcloudsByon:(hosts=\"i-72b1b132\", name=)"); // no value for name
- }
-
- @SuppressWarnings("unchecked")
- private FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> resolve(String spec) {
- return (FixedListMachineProvisioningLocation<JcloudsSshMachineLocation>) managementContext.getLocationRegistry().resolve(spec);
- }
-
- private void assertThrowsNoSuchElement(String val) {
- try {
- resolve(val);
- fail();
- } catch (NoSuchElementException e) {
- // success
- }
- }
-
- private void assertThrowsIllegalArgument(String val) {
- try {
- resolve(val);
- fail();
- } catch (IllegalArgumentException e) {
- // success
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java
deleted file mode 100644
index 8d7f55e..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.domain.LoginCredentials;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.Test;
-
-import brooklyn.util.collections.MutableMap;
-
-import com.google.common.collect.ImmutableList;
-
-public class JcloudsHardwareProfilesStubbedLiveTest extends AbstractJcloudsStubbedLiveTest {
-
- @SuppressWarnings("unused")
- private static final Logger log = LoggerFactory.getLogger(JcloudsHardwareProfilesStubbedLiveTest.class);
-
- private Template template;
-
- @Override
- protected NodeCreator newNodeCreator() {
- return new NodeCreator() {
- @Override protected NodeMetadata newNode(String group, Template template) {
- JcloudsHardwareProfilesStubbedLiveTest.this.template = template;
-
- NodeMetadata result = new NodeMetadataBuilder()
- .id("myid")
- .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
- .loginPort(22)
- .status(Status.RUNNING)
- .publicAddresses(ImmutableList.of("173.194.32.123"))
- .privateAddresses(ImmutableList.of("172.168.10.11"))
- .build();
- return result;
- }
- };
- }
-
- @Test(groups={"Live", "Live-sanity"})
- public void testJcloudsCreateWithHardwareProfiles() throws Exception {
- obtainMachine(MutableMap.of(JcloudsLocationConfig.MIN_RAM, "4096"));
- assertTrue(template.getHardware().getRam() >= 4096, "template="+template);
-
- obtainMachine(MutableMap.of(JcloudsLocationConfig.MIN_CORES, "4"));
- assertTrue(template.getHardware().getProcessors().get(0).getCores() >= 4, "template="+template);
-
- obtainMachine(MutableMap.of(JcloudsLocationConfig.MIN_DISK, "51"));
- assertTrue(template.getHardware().getVolumes().get(0).getSize() >= 51, "template="+template);
-
- String hardwareId = "cpu=1,memory=6144,disk=25,type=LOCAL";
- obtainMachine(MutableMap.of(JcloudsLocationConfig.HARDWARE_ID, hardwareId));
- assertEquals(template.getHardware().getId(), hardwareId, "template="+template);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java
deleted file mode 100644
index 4454045..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationMetadataTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static org.testng.Assert.assertEquals;
-
-import org.apache.brooklyn.test.entity.LocalManagementContextForTests;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.config.BrooklynProperties;
-import brooklyn.entity.basic.Entities;
-import brooklyn.location.Location;
-import brooklyn.location.basic.LocationConfigKeys;
-import brooklyn.management.internal.LocalManagementContext;
-
-import com.google.common.collect.ImmutableSet;
-
-/**
- * @author Shane Witbeck
- */
-public class JcloudsLocationMetadataTest implements JcloudsLocationConfig {
-
- protected BrooklynProperties brooklynProperties;
- protected LocalManagementContext managementContext;
-
- @BeforeMethod(alwaysRun=true)
- public void setUp() throws Exception {
- managementContext = LocalManagementContextForTests.newInstance(BrooklynProperties.Factory.builderEmpty().build());
- brooklynProperties = managementContext.getBrooklynProperties();
- }
-
- @AfterMethod(alwaysRun=true)
- public void tearDown() throws Exception {
- if (managementContext != null) Entities.destroyAll(managementContext);
- }
-
-
- @Test
- public void testGetsDefaultAwsEc2Metadata() throws Exception {
- Location loc = managementContext.getLocationRegistry().resolve("jclouds:aws-ec2:us-west-1");
-
- assertEquals(loc.getConfig(LocationConfigKeys.LATITUDE), 40.0d);
- assertEquals(loc.getConfig(LocationConfigKeys.LONGITUDE), -120.0d);
- assertEquals(loc.getConfig(LocationConfigKeys.ISO_3166), ImmutableSet.of("US-CA"));
- }
-
- @Test
- public void testCanOverrideDefaultAwsEc2Metadata() throws Exception {
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2@us-west-1.latitude", "41.2");
- Location loc = managementContext.getLocationRegistry().resolve("jclouds:aws-ec2:us-west-1");
-
- assertEquals(loc.getConfig(LocationConfigKeys.LATITUDE), 41.2d);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java
deleted file mode 100644
index d2f1b84..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationRebindMachineLiveTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import java.net.InetAddress;
-import java.util.Collections;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.location.basic.SshMachineLocation;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class JcloudsLocationRebindMachineLiveTest extends AbstractJcloudsLiveTest {
-
- private static final Logger LOG = LoggerFactory.getLogger(JcloudsLocationRebindMachineLiveTest.class);
-
- private static final String EUWEST_IMAGE_ID = AWS_EC2_EUWEST_REGION_NAME+"/"+"ami-89def4fd";
- private static final String IMAGE_OWNER = "411009282317";
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
- jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve(AWS_EC2_PROVIDER+":"+AWS_EC2_EUWEST_REGION_NAME);
- }
-
- @Test(groups = { "Live", "Live-sanity" })
- public void testRebindWithIncorrectId() throws Exception {
- try {
- jcloudsLocation.rebindMachine(ImmutableMap.of("id", "incorrectid", "hostname", "myhostname", "user", "myusername"));
- } catch (IllegalArgumentException e) {
- if (e.getMessage().contains("node not found")) {
- // success
- } else {
- throw e;
- }
- }
- }
-
- @Test(groups = { "Live" })
- public void testRebindVm() throws Exception {
- // FIXME How to create a machine - go directly through jclouds instead?
- // Going through LocationRegistry.resolve, loc and loc2 might be same instance
-
- // Create a VM through jclouds
- JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of("imageId", EUWEST_IMAGE_ID, "imageOwner", IMAGE_OWNER));
- assertTrue(machine.isSshable());
- LOG.info("obtained "+machine);
-
- String id = checkNotNull(machine.getJcloudsId(), "id");
- InetAddress address = checkNotNull(machine.getAddress(), "address");
- String hostname = checkNotNull(address.getHostName(), "hostname");
- String user = checkNotNull(machine.getUser(), "user");
-
- // Create a new jclouds location, and re-bind the existing VM to that
- JcloudsLocation loc2 = (JcloudsLocation) managementContext.getLocationRegistry().resolve(AWS_EC2_PROVIDER+":"+AWS_EC2_EUWEST_REGION_NAME);
- SshMachineLocation machine2 = loc2.rebindMachine(ImmutableMap.of("id", id, "hostname", hostname, "user", user));
-
- LOG.info("rebinded to "+machine2);
-
- // Confirm the re-bound machine is wired up
- assertTrue(machine2.isSshable());
- assertEquals(ImmutableSet.copyOf(loc2.getChildren()), ImmutableSet.of(machine2));
-
- // Confirm can release the re-bound machine via the new jclouds location
- loc2.release(machine2);
- assertFalse(machine.isSshable());
- assertEquals(ImmutableSet.copyOf(loc2.getChildren()), Collections.emptySet());
- }
-
- @Test(groups = { "Live" })
- public void testRebindVmDeprecated() throws Exception {
- // FIXME See comments in testRebindVm
-
- // Create a VM through jclouds
- JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of("imageId", EUWEST_IMAGE_ID, "imageOwner", IMAGE_OWNER));
- assertTrue(machine.isSshable());
-
- String id = machine.getJcloudsId();
- InetAddress address = machine.getAddress();
- String hostname = address.getHostName();
- String username = machine.getUser();
-
- // Create a new jclouds location, and re-bind the existing VM to that
- JcloudsLocation loc2 = (JcloudsLocation) managementContext.getLocationRegistry().resolve(AWS_EC2_PROVIDER+":"+AWS_EC2_EUWEST_REGION_NAME);
- // pass deprecated userName
- SshMachineLocation machine2 = loc2.rebindMachine(ImmutableMap.of("id", id, "hostname", hostname, "userName", username));
-
- // Confirm the re-bound machine is wired up
- assertTrue(machine2.isSshable());
- assertEquals(ImmutableSet.copyOf(loc2.getChildren()), ImmutableSet.of(machine2));
-
- // Confirm can release the re-bound machine via the new jclouds location
- loc2.release(machine2);
- assertFalse(machine.isSshable());
- assertEquals(ImmutableSet.copyOf(loc2.getChildren()), Collections.emptySet());
- }
-
- // Useful for debugging; accesss a hard-coded existing instance so don't need to wait for provisioning a new one
- @Test(enabled=false, groups = { "Live" })
- public void testRebindVmToHardcodedInstance() throws Exception {
- String id = "eu-west-1/i-5504f21d";
- InetAddress address = InetAddress.getByName("ec2-176-34-93-58.eu-west-1.compute.amazonaws.com");
- String hostname = address.getHostName();
- String username = "root";
-
- SshMachineLocation machine = jcloudsLocation.rebindMachine(ImmutableMap.of("id", id, "hostname", hostname, "userName", username));
-
- // Confirm the re-bound machine is wired up
- assertTrue(machine.isSshable());
- assertEquals(ImmutableSet.copyOf(jcloudsLocation.getChildren()), ImmutableSet.of(machine));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java
deleted file mode 100644
index 0dc2658..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationResolverTest.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.fail;
-
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import org.apache.brooklyn.test.entity.LocalManagementContextForTests;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import brooklyn.config.BrooklynProperties;
-import brooklyn.event.basic.MapConfigKey;
-import brooklyn.event.basic.SetConfigKey;
-import brooklyn.location.basic.LocationInternal;
-import brooklyn.location.cloud.CloudLocationConfig;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.collections.MutableSet;
-
-public class JcloudsLocationResolverTest {
-
- private static final Logger log = LoggerFactory.getLogger(JcloudsLocationResolverTest.class);
-
- private LocalManagementContext managementContext;
- private BrooklynProperties brooklynProperties;
-
- @BeforeMethod(alwaysRun = true)
- public void setUp() throws Exception {
- managementContext = LocalManagementContextForTests.newInstance();
- brooklynProperties = managementContext.getBrooklynProperties();
-
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.identity", "aws-ec2-id");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.credential", "aws-ec2-cred");
- brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.identity", "cloudservers-uk-id");
- brooklynProperties.put("brooklyn.location.jclouds.rackspace-cloudservers-uk.credential", "cloudservers-uk-cred");
- }
-
- @AfterMethod(alwaysRun = true)
- public void tearDown() throws Exception {
- if (managementContext != null)
- managementContext.terminate();
- }
-
- @Test
- public void testJcloudsTakesDotSeparateProperty() {
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.loginUser.privateKeyFile", "myfile");
- String file = resolve("jclouds:aws-ec2").getConfig(JcloudsLocation.LOGIN_USER_PRIVATE_KEY_FILE);
- assertEquals(file, "myfile");
- }
-
- @Test
- public void testJcloudsTakesProviderScopedProperties() {
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyFile", "myprivatekeyfile");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyFile", "mypublickeyfile");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyData", "myprivateKeyData");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyData", "myPublicKeyData");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyPassphrase", "myprivateKeyPassphrase");
- Map<String, Object> conf = resolve("jclouds:aws-ec2").config().getBag().getAllConfig();
-
- assertEquals(conf.get("privateKeyFile"), "myprivatekeyfile");
- assertEquals(conf.get("publicKeyFile"), "mypublickeyfile");
- assertEquals(conf.get("privateKeyData"), "myprivateKeyData");
- assertEquals(conf.get("publicKeyData"), "myPublicKeyData");
- assertEquals(conf.get("privateKeyPassphrase"), "myprivateKeyPassphrase");
- }
-
- @Test
- public void testJcloudsTakesGenericScopedProperties() {
- brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "myprivatekeyfile");
- brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "mypublickeyfile");
- brooklynProperties.put("brooklyn.location.jclouds.privateKeyData", "myprivateKeyData");
- brooklynProperties.put("brooklyn.location.jclouds.publicKeyData", "myPublicKeyData");
- brooklynProperties.put("brooklyn.location.jclouds.privateKeyPassphrase", "myprivateKeyPassphrase");
- Map<String, Object> conf = resolve("jclouds:aws-ec2").config().getBag().getAllConfig();
-
- assertEquals(conf.get("privateKeyFile"), "myprivatekeyfile");
- assertEquals(conf.get("publicKeyFile"), "mypublickeyfile");
- assertEquals(conf.get("privateKeyData"), "myprivateKeyData");
- assertEquals(conf.get("publicKeyData"), "myPublicKeyData");
- assertEquals(conf.get("privateKeyPassphrase"), "myprivateKeyPassphrase");
- }
-
- @Test
- public void testJcloudsTakesDeprecatedProperties() {
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.private-key-file", "myprivatekeyfile");
- brooklynProperties.put("brooklyn.location.jclouds.public-key-file", "mypublickeyfile");
- brooklynProperties.put("brooklyn.location.jclouds.private-key-data", "myprivateKeyData");
- brooklynProperties.put("brooklyn.location.jclouds.public-key-data", "myPublicKeyData");
- brooklynProperties.put("brooklyn.location.jclouds.private-key-passphrase", "myprivateKeyPassphrase");
- brooklynProperties.put("brooklyn.location.jclouds.image-id", "myimageid");
- Map<String, Object> conf = resolve("jclouds:aws-ec2").config().getBag().getAllConfig();
-
- assertEquals(conf.get("privateKeyFile"), "myprivatekeyfile");
- assertEquals(conf.get("publicKeyFile"), "mypublickeyfile");
- assertEquals(conf.get("privateKeyData"), "myprivateKeyData");
- assertEquals(conf.get("publicKeyData"), "myPublicKeyData");
- assertEquals(conf.get("privateKeyPassphrase"), "myprivateKeyPassphrase");
- assertEquals(conf.get("imageId"), "myimageid");
- }
-
- @Test
- public void testJcloudsPropertiesPrecedence() {
- brooklynProperties.put("brooklyn.location.named.myaws-ec2", "jclouds:aws-ec2");
-
- // prefer those in "named" over everything else
- brooklynProperties.put("brooklyn.location.named.myaws-ec2.privateKeyFile", "privateKeyFile-inNamed");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyFile", "privateKeyFile-inProviderSpecific");
- brooklynProperties.put("brooklyn.location.jclouds.privateKeyFile", "privateKeyFile-inJcloudsGeneric");
-
- // prefer those in provider-specific over generic
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.publicKeyFile", "publicKeyFile-inProviderSpecific");
- brooklynProperties.put("brooklyn.location.jclouds.publicKeyFile", "publicKeyFile-inJcloudsGeneric");
-
- // prefer deprecated properties in "named" over those less specific
- brooklynProperties.put("brooklyn.location.named.myaws-ec2.private-key-data", "privateKeyData-inNamed");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.privateKeyData", "privateKeyData-inProviderSpecific");
- brooklynProperties.put("brooklyn.location.jclouds.privateKeyData", "privateKeyData-inJcloudsGeneric");
-
- // prefer generic if nothing else
- brooklynProperties.put("brooklyn.location.jclouds.publicKeyData", "publicKeyData-inJcloudsGeneric");
-
- // prefer "named" over everything else: confirm deprecated don't get
- // transformed to overwrite it accidentally
- brooklynProperties
- .put("brooklyn.location.named.myaws-ec2.privateKeyPassphrase", "privateKeyPassphrase-inNamed");
- brooklynProperties.put("brooklyn.location.jclouds.aws-ec2.private-key-passphrase",
- "privateKeyPassphrase-inProviderSpecific");
- brooklynProperties.put("brooklyn.location.jclouds.private-key-passphrase", "privateKeyPassphrase-inJcloudsGeneric");
-
- Map<String, Object> conf = resolve("named:myaws-ec2").config().getBag().getAllConfig();
-
- assertEquals(conf.get("privateKeyFile"), "privateKeyFile-inNamed");
- assertEquals(conf.get("publicKeyFile"), "publicKeyFile-inProviderSpecific");
- assertEquals(conf.get("privateKeyData"), "privateKeyData-inNamed");
- assertEquals(conf.get("publicKeyData"), "publicKeyData-inJcloudsGeneric");
- assertEquals(conf.get("privateKeyPassphrase"), "privateKeyPassphrase-inNamed");
- }
-
- @Test
- public void testJcloudsLoads() {
- Assert.assertTrue(resolve("jclouds:aws-ec2") instanceof JcloudsLocation);
- }
-
- @Test
- public void testJcloudsImplicitLoads() {
- Assert.assertTrue(resolve("aws-ec2") instanceof JcloudsLocation);
- }
-
- @Test
- public void testJcloudsLocationLoads() {
- Assert.assertTrue(resolve("aws-ec2:eu-west-1") instanceof JcloudsLocation);
- }
-
- @Test
- public void testJcloudsRegionOnlyLoads() {
- Assert.assertTrue(resolve("eu-west-1") instanceof JcloudsLocation);
- }
-
- @Test
- public void testJcloudsEndpointLoads() {
- JcloudsLocation loc = resolve("jclouds:openstack-nova:http://foo/api");
- assertEquals(loc.getProvider(), "openstack-nova");
- assertEquals(loc.getEndpoint(), "http://foo/api");
- }
-
- @Test
- public void testJcloudsEndpointLoadsAsProperty() {
- brooklynProperties.put("brooklyn.location.jclouds.openstack-nova.endpoint", "myendpoint");
- JcloudsLocation loc = resolve("jclouds:openstack-nova");
- // just checking
- assertEquals(loc.config().getLocalBag().getStringKey("endpoint"), "myendpoint");
- assertEquals(loc.getConfig(CloudLocationConfig.CLOUD_ENDPOINT), "myendpoint");
- // this is the one we really care about!:
- assertEquals(loc.getEndpoint(), "myendpoint");
- }
-
- @Test
- public void testJcloudsLegacyRandomProperty() {
- brooklynProperties.put("brooklyn.location.jclouds.openstack-nova.foo", "bar");
- JcloudsLocation loc = resolve("jclouds:openstack-nova");
- assertEquals(loc.config().getLocalBag().getStringKey("foo"), "bar");
- }
-
- @Test
- public void testJcloudsRandomProperty() {
- brooklynProperties.put("brooklyn.location.jclouds.openstack-nova.foo", "bar");
- JcloudsLocation loc = resolve("jclouds:openstack-nova");
- assertEquals(loc.config().getLocalBag().getStringKey("foo"), "bar");
- }
-
- @Test
- public void testThrowsOnInvalid() throws Exception {
- // Tries to treat "wrongprefix" as a cloud provider
- assertThrows("wrongprefix:aws-ec2:us-east-1", NoSuchElementException.class);
-
- // no provider
- assertThrows("jclouds", IllegalArgumentException.class);
-
- // empty provider
- assertThrows("jclouds:", IllegalArgumentException.class);
-
- // invalid provider
- assertThrows("jclouds:doesnotexist", NoSuchElementException.class);
- }
-
- @Test
- public void testResolvesJclouds() throws Exception {
- // test with provider + region
- assertJcloudsEquals(resolve("jclouds:aws-ec2:us-east-1"), "aws-ec2", "us-east-1");
-
- // test with provider that has no region
- assertJcloudsEquals(resolve("jclouds:rackspace-cloudservers-uk"), "rackspace-cloudservers-uk", null);
- }
-
- @Test
- public void testJcloudsRegionOverridesParent() {
- Map<String, Object> conf;
-
- brooklynProperties.put("brooklyn.location.named.softlayer-was", "jclouds:softlayer:was01");
- brooklynProperties.put("brooklyn.location.named.softlayer-was2", "jclouds:softlayer:was01");
- brooklynProperties.put("brooklyn.location.named.softlayer-was2.region", "was02");
- conf = resolve("named:softlayer-was").config().getBag().getAllConfig();
- assertEquals(conf.get("region"), "was01");
-
- conf = resolve("named:softlayer-was2").config().getBag().getAllConfig();
- assertEquals(conf.get("region"), "was02");
-
- conf = ((LocationInternal) managementContext.getLocationRegistry().resolve("named:softlayer-was2", MutableMap.of("region", "was03")))
- .config().getBag().getAllConfig();;
- assertEquals(conf.get("region"), "was03");
- }
-
- // TODO Visual inspection test that it logs warnings
- @Test
- public void testLogsWarnings() throws Exception {
- assertJcloudsEquals(resolve("jclouds:jclouds:aws-ec2:us-east-1"), "aws-ec2", "us-east-1");
- assertJcloudsEquals(resolve("us-east-1"), "aws-ec2", "us-east-1");
-
- // TODO Should we enforce a jclouds prefix? Currently we don't
- // assertJcloudsEquals(resolve("aws-ec2:us-east-1"), "aws-ec2",
- // "us-east-1");
-
- }
-
- @Test
- public void testResolvesJcloudsFromNamedOfNamedWithPropertiesOverriddenCorrectly() throws Exception {
- brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop1", "1");
- brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop2", "1");
- brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop3", "1");
- brooklynProperties.put("brooklyn.location.named.foo", "jclouds:softlayer:138124");
- brooklynProperties.put("brooklyn.location.named.foo.prop2", "2");
- brooklynProperties.put("brooklyn.location.named.foo.prop3", "2");
- brooklynProperties.put("brooklyn.location.named.bar", "named:foo");
- brooklynProperties.put("brooklyn.location.named.bar.prop3", "3");
-
- JcloudsLocation l = resolve("named:bar");
- assertJcloudsEquals(l, "softlayer", "138124");
- assertEquals(l.config().getLocalBag().getStringKey("prop3"), "3");
- assertEquals(l.config().getLocalBag().getStringKey("prop2"), "2");
- assertEquals(l.config().getLocalBag().getStringKey("prop1"), "1");
- }
-
- @Test
- public void testResolvesListAndMapProperties() throws Exception {
- brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop1", "[ a, b ]");
- brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop2", "{ a: 1, b: 2 }");
- brooklynProperties.put("brooklyn.location.named.foo", "jclouds:softlayer:ams01");
-
- JcloudsLocation l = resolve("named:foo");
- assertJcloudsEquals(l, "softlayer", "ams01");
- assertEquals(l.config().get(new SetConfigKey<String>(String.class, "prop1")), MutableSet.of("a", "b"));
- assertEquals(l.config().get(new MapConfigKey<String>(String.class, "prop2")), MutableMap.of("a", 1, "b", 2));
- }
-
- @Test
- public void testResolvesListAndMapPropertiesWithoutMergeOnInheritance() throws Exception {
- // when we have a yaml way to specify config we may wish to have different semantics;
- // it could depend on the collection config key whether to merge on inheritance
- brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop1", "[ a, b ]");
- brooklynProperties.put("brooklyn.location.jclouds.softlayer.prop2", "{ a: 1, b: 2 }");
- brooklynProperties.put("brooklyn.location.named.foo", "jclouds:softlayer:ams01");
-
- brooklynProperties.put("brooklyn.location.named.foo.prop1", "[ a: 1, c: 3 ]");
- brooklynProperties.put("brooklyn.location.named.foo.prop2", "{ b: 3, c: 3 }");
- brooklynProperties.put("brooklyn.location.named.bar", "named:foo");
- brooklynProperties.put("brooklyn.location.named.bar.prop2", "{ c: 4, d: 4 }");
-
- // these do NOT affect the maps
- brooklynProperties.put("brooklyn.location.named.foo.prop2.z", "9");
- brooklynProperties.put("brooklyn.location.named.foo.prop3.z", "9");
-
- JcloudsLocation l = resolve("named:bar");
- assertJcloudsEquals(l, "softlayer", "ams01");
-
- Set<? extends String> prop1 = l.config().get(new SetConfigKey<String>(String.class, "prop1"));
- log.info("prop1: "+prop1);
- assertEquals(prop1, MutableSet.of("a: 1", "c: 3"));
-
- Map<String, String> prop2 = l.config().get(new MapConfigKey<String>(String.class, "prop2"));
- log.info("prop2: "+prop2);
- assertEquals(prop2, MutableMap.of("c", 4, "d", 4));
-
- Map<String, String> prop3 = l.config().get(new MapConfigKey<String>(String.class, "prop3"));
- log.info("prop3: "+prop3);
- assertEquals(prop3, null);
- }
-
- private void assertJcloudsEquals(JcloudsLocation loc, String expectedProvider, String expectedRegion) {
- assertEquals(loc.getProvider(), expectedProvider);
- assertEquals(loc.getRegion(), expectedRegion);
- }
-
- private void assertThrows(String val, Class<?> expectedExceptionType) throws Exception {
- try {
- resolve(val);
- fail();
- } catch (Exception e) {
- if (!expectedExceptionType.isInstance(e))
- throw e; // otherwise success
-
- }
- }
-
- @Test(expectedExceptions = { NoSuchElementException.class, IllegalArgumentException.class }, expectedExceptionsMessageRegExp = ".*insufficient.*")
- public void testJcloudsOnlyFails() {
- resolve("jclouds");
- }
-
- private JcloudsLocation resolve(String spec) {
- return (JcloudsLocation) managementContext.getLocationRegistry().resolve(spec);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e2c57058/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTemplateOptionsCustomisersLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTemplateOptionsCustomisersLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTemplateOptionsCustomisersLiveTest.java
deleted file mode 100644
index d22e134..0000000
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsLocationTemplateOptionsCustomisersLiveTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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 brooklyn.location.jclouds;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.location.NoMachinesAvailableException;
-import brooklyn.location.basic.SshMachineLocation;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.config.ConfigBag;
-import brooklyn.util.ssh.BashCommands;
-import brooklyn.util.text.Identifiers;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.ec2.domain.BlockDeviceMapping;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import java.io.ByteArrayOutputStream;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
-public class JcloudsLocationTemplateOptionsCustomisersLiveTest extends AbstractJcloudsLiveTest {
-
- private static final String LOCATION_SPEC = AWS_EC2_PROVIDER + ":" + AWS_EC2_USEAST_REGION_NAME;
-
- @BeforeMethod(alwaysRun=true)
- @Override
- public void setUp() throws Exception {
- super.setUp();
- jcloudsLocation = resolve(LOCATION_SPEC);
- }
-
- // Doesn't actually do much with the cloud, but jclouds requires identity and credential before it will work
- @Test(groups = "Live")
- public void testGeneralPurposeTemplateOptionCustomisation() throws Exception {
- ConfigKey<Map<String, Object>> key = JcloudsLocationConfig.TEMPLATE_OPTIONS;
-
- ConfigBag config = ConfigBag.newInstance()
- .configure(key, ImmutableMap.of("iamInstanceProfileName", (Object)"helloworld"));
- AWSEC2TemplateOptions templateOptions = jcloudsLocation.getComputeService().templateOptions().as(AWSEC2TemplateOptions.class);
-
- invokeCustomizeTemplateOptions(templateOptions, JcloudsLocationConfig.TEMPLATE_OPTIONS, config);
-
- assertEquals(templateOptions.getIAMInstanceProfileName(), "helloworld");
- }
-
- // Doesn't actually do much with the cloud, but jclouds requires identity and credential before it will work
- @Test(groups = "Live")
- public void testGeneralPurposeTemplateOptionCustomisationWithList() throws Exception {
- ConfigKey<Map<String, Object>> key = JcloudsLocationConfig.TEMPLATE_OPTIONS;
-
- ConfigBag config = ConfigBag.newInstance()
- .configure(key, ImmutableMap.of(
- "iamInstanceProfileName", (Object) "helloworld",
- "mapNewVolumeToDeviceName", (Object) ImmutableList.of("/dev/sda1/", 123, true)));
- AWSEC2TemplateOptions templateOptions = jcloudsLocation.getComputeService().templateOptions().as(AWSEC2TemplateOptions.class);
-
- invokeCustomizeTemplateOptions(templateOptions, JcloudsLocationConfig.TEMPLATE_OPTIONS, config);
-
- assertEquals(templateOptions.getIAMInstanceProfileName(), "helloworld");
- assertEquals(templateOptions.getBlockDeviceMappings().size(), 1);
- BlockDeviceMapping blockDeviceMapping = templateOptions.getBlockDeviceMappings().iterator().next();
- assertEquals(blockDeviceMapping.getDeviceName(), "/dev/sda1/");
- assertEquals(blockDeviceMapping.getEbsVolumeSize(), (Integer)123);
- assertTrue(blockDeviceMapping.getEbsDeleteOnTermination());
- }
-
- /**
- * Invoke a specific template options customizer on a TemplateOptions instance.
- *
- * @param templateOptions the TemplateOptions instance that you expect the customizer to modify.
- * @param keyToTest the config key that identifies the customizer. This must be present in both @{code locationConfig} and @{link JcloudsLocation.SUPPORTED_TEMPLATE_OPTIONS_PROPERTIES}.
- * @param locationConfig simulated configuration for the location. This must contain at least an entry for @{code keyToTest}.
- */
- private void invokeCustomizeTemplateOptions(TemplateOptions templateOptions, ConfigKey<?> keyToTest, ConfigBag locationConfig) {
- checkNotNull(templateOptions, "templateOptions");
- checkNotNull(keyToTest, "keyToTest");
- checkNotNull(locationConfig, "locationConfig");
- checkState(JcloudsLocation.SUPPORTED_TEMPLATE_OPTIONS_PROPERTIES.containsKey(keyToTest),
- "SUPPORTED_TEMPLATE_OPTIONS_PROPERTIES does not contain a customiser for the key " + keyToTest.getName());
- checkState(locationConfig.containsKey(keyToTest),
- "location config does not contain the key " + keyToTest.getName());
-
- JcloudsLocation.CustomizeTemplateOptions code = JcloudsLocation.SUPPORTED_TEMPLATE_OPTIONS_PROPERTIES.get(keyToTest);
- code.apply(templateOptions, locationConfig, locationConfig.get(keyToTest));
- }
-
- private JcloudsLocation resolve(String spec) {
- return (JcloudsLocation) managementContext.getLocationRegistry().resolve("jclouds:"+spec);
- }
-}