Merge branch 'master' of github.com:jclouds/jclouds into 1.5.x

* 'master' of github.com:jclouds/jclouds:
  Issue 988:Extra port added to swift url
  consistent ordering of hardware
  fixed missing provider name on ninefold test
  Eliminate unlikely transient blobstore TOCTOU bug
diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java
index 1b1e25b..34fa547 100644
--- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java
+++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftApiMetadata.java
@@ -20,17 +20,12 @@
 
 import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
 import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
-import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
-import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
 
 import java.net.URI;
 import java.util.Properties;
 
 import org.jclouds.apis.ApiMetadata;
 import org.jclouds.blobstore.BlobStoreContext;
-import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
-import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
-import org.jclouds.openstack.services.ServiceType;
 import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
 import org.jclouds.openstack.swift.config.SwiftRestClientModule;
 import org.jclouds.openstack.swift.config.SwiftRestClientModule.StorageEndpointModule;
@@ -69,12 +64,8 @@
 
    public static Properties defaultProperties() {
       Properties properties = BaseRestApiMetadata.defaultProperties();
-      properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
-      // TODO: this doesn't actually do anything yet.
-      properties.setProperty(KeystoneProperties.VERSION, "2.0");
-      properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
-      properties.setProperty(PROPERTY_REGIONS, "DEFAULT");
       properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-");
+      properties.setProperty(PROPERTY_REGIONS, "DEFAULT");
       return properties;
    }
 
@@ -82,8 +73,8 @@
       protected Builder(Class<?> syncClient, Class<?> asyncClient){
          super(syncClient, asyncClient);
          id("swift")
-         .name("OpenStack Swift Pre-Diablo API")
-         .identityName("tenantName:user or user")
+         .name("OpenStack Swift with SwiftAuth")
+         .identityName("tenantId:user")
          .credentialName("password")
          .documentation(URI.create("http://api.openstack.org/"))
          .version("1.0")
diff --git a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java
index 520ae80..8030541 100644
--- a/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java
+++ b/apis/swift/src/main/java/org/jclouds/openstack/swift/SwiftKeystoneApiMetadata.java
@@ -19,10 +19,15 @@
 package org.jclouds.openstack.swift;
 
 import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
+import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
+import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
 
 import java.util.Properties;
 
 import org.jclouds.apis.ApiMetadata;
+import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
+import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
+import org.jclouds.openstack.services.ServiceType;
 import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
 import org.jclouds.openstack.swift.config.SwiftKeystoneRestClientModule;
 import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule;
@@ -64,6 +69,10 @@
 
    public static Properties defaultProperties() {
       Properties properties = SwiftApiMetadata.defaultProperties();
+      properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
+      // TODO: this doesn't actually do anything yet.
+      properties.setProperty(KeystoneProperties.VERSION, "2.0");
+      properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
       properties.remove(PROPERTY_REGIONS);
       return properties;
    }
@@ -72,6 +81,9 @@
       protected Builder(){
          super(SwiftKeystoneClient.class, SwiftKeystoneAsyncClient.class);
          id("swift-keystone")
+         .name("OpenStack Swift with Keystone authentication")
+         .identityName("tenantName:user or user")
+         .credentialName("password")
          .context(CONTEXT_TOKEN)
          .defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneStorageEndpointModule.class, SwiftKeystoneRestClientModule.class, SwiftBlobStoreContextModule.class));
       }
diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientExpectTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientExpectTest.java
new file mode 100644
index 0000000..7070455
--- /dev/null
+++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/SwiftClientExpectTest.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.openstack.swift;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.swift.internal.BaseSwiftExpectTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMultimap;
+
+/**
+ * 
+ * @author Adrian Cole
+ */
+@Test(testName = "SwiftClientExpectTest")
+public class SwiftClientExpectTest extends BaseSwiftExpectTest<SwiftClient> {
+
+   public void testContainerExistsWhenResponseIs2xxReturnsTrue() throws Exception {
+      HttpRequest headContainer = HttpRequest.builder()
+            .method("HEAD")
+            .endpoint(URI.create(swiftEndpointWithHostReplaced + "/foo"))
+            .headers(
+                  ImmutableMultimap.<String, String> builder()
+                        .put("X-Auth-Token", authToken).build()).build();
+
+      HttpResponse headContainerResponse = HttpResponse.builder().statusCode(200).build();
+
+      SwiftClient clientWhenContainerExists = requestsSendResponses(authRequest,
+            authResponse, headContainer, headContainerResponse);
+
+      assertTrue(clientWhenContainerExists.containerExists("foo"));
+   }
+
+   public void testContainerExistsWhenResponseIs404ReturnsFalse() throws Exception {
+      HttpRequest headContainer = HttpRequest.builder()
+            .method("HEAD")
+            .endpoint(URI.create(swiftEndpointWithHostReplaced + "/foo"))
+            .headers(
+                  ImmutableMultimap.<String, String> builder()
+                        .put("X-Auth-Token", authToken).build()).build();
+
+      HttpResponse headContainerResponse = HttpResponse.builder().statusCode(404).build();
+
+      SwiftClient clientWhenContainerDoesntExist = requestsSendResponses(authRequest,
+            authResponse, headContainer, headContainerResponse);
+
+      assertFalse(clientWhenContainerDoesntExist.containerExists("foo"));
+
+   }
+
+}
diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BaseSwiftExpectTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BaseSwiftExpectTest.java
new file mode 100644
index 0000000..ff15a6c
--- /dev/null
+++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/internal/BaseSwiftExpectTest.java
@@ -0,0 +1,75 @@
+/**
+ * Licensed to jclouds, Inc. (jclouds) under one or more
+ * contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  jclouds licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.jclouds.openstack.swift.internal;
+
+import java.net.URI;
+import java.util.Properties;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.rest.internal.BaseRestClientExpectTest;
+
+import com.google.common.collect.ImmutableMultimap;
+
+/**
+ * Base class for writing Swift Expect tests
+ * 
+ * @author Adrian Cole
+ */
+public class BaseSwiftExpectTest<T> extends BaseRestClientExpectTest<T> {
+
+   protected String endpoint = "http://myhost:8080/auth";
+   protected HttpRequest authRequest;
+   public BaseSwiftExpectTest() {
+      provider = "swift";
+      identity = "test:tester";
+      credential = "testing";
+      authRequest = HttpRequest.builder()
+            .method("GET")
+            .endpoint(URI.create(endpoint+ "/v1.0"))
+            .headers(ImmutableMultimap.<String, String>builder()
+                  .put("X-Auth-User", identity)
+                  .put("X-Auth-Key", credential)
+                  .put("Accept", "*/*")
+                  .put("Host", "myhost:8080").build()).build();
+   }
+   
+   protected String authToken = "AUTH_tk36dabe83ca744cc296a98ec46089ec35";
+
+   protected String swiftEndpoint = "http://127.0.0.1:8080/v1/AUTH_test";
+
+   /**
+    * often swift returns the localhost url when requested via a dns name. this
+    * test ensures that replacement works.
+    */
+   protected String swiftEndpointWithHostReplaced = swiftEndpoint.replace("127.0.0.1", "myhost");
+   
+   protected HttpResponse authResponse = HttpResponse.builder()
+         .statusCode(200)
+         .message("HTTP/1.1 200 OK")
+         .headers(ImmutableMultimap.<String, String>builder()
+               .put("X-Storage-Url", swiftEndpoint)
+               .put("X-Auth-Token", authToken).build()).build();
+   
+   protected Properties setupProperties() {
+      Properties props = super.setupProperties();
+      props.put(provider+".endpoint", endpoint);
+      return props;
+   }
+}
\ No newline at end of file
diff --git a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java
index 1c01114..611e93b 100644
--- a/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java
+++ b/blobstore/src/main/java/org/jclouds/blobstore/TransientStorageStrategy.java
@@ -79,8 +79,9 @@
    }
 
    public void removeBlob(final String containerName, final String blobName) {
-      if (containerToBlobs.containsKey(containerName)) 
-         containerToBlobs.get(containerName).remove(blobName);
+      Map<String, Blob> map = containerToBlobs.get(containerName);
+      if (map != null)
+         map.remove(blobName);
    }
 
    public Iterable<String> getBlobKeysInsideContainer(final String containerName) {
diff --git a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
index 8061c41..9b68139 100644
--- a/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
+++ b/common/openstack/src/main/java/org/jclouds/openstack/functions/ParseAuthenticationResponseFromHeaders.java
@@ -90,9 +90,6 @@
    @Override
    public ParseAuthenticationResponseFromHeaders setContext(HttpRequest request) {
       String host = request.getEndpoint().getHost();
-      if (request.getEndpoint().getPort() != -1) {
-         host += ":" + request.getEndpoint().getPort();
-      }
       return setHostToReplace(host);
    }
 
diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/HardwareImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/HardwareImpl.java
index 717e3b0..52e1bd9 100644
--- a/compute/src/main/java/org/jclouds/compute/domain/internal/HardwareImpl.java
+++ b/compute/src/main/java/org/jclouds/compute/domain/internal/HardwareImpl.java
@@ -19,7 +19,7 @@
 package org.jclouds.compute.domain.internal;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.compute.util.ComputeServiceUtils.getCoresAndSpeed;
+import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
 import static org.jclouds.compute.util.ComputeServiceUtils.getSpace;
 
 import java.net.URI;
@@ -104,9 +104,8 @@
    public int compareTo(ResourceMetadata<ComputeType> that) {
       if (that instanceof Hardware) {
          Hardware thatHardware = Hardware.class.cast(that);
-         return ComparisonChain.start().compare(getCoresAndSpeed(this), getCoresAndSpeed(thatHardware)).compare(
-                  this.getRam(), thatHardware.getRam()).compare(getSpace(this), getSpace(thatHardware)).compare(
-                  getHypervisor(), thatHardware.getHypervisor()).result();
+         return ComparisonChain.start().compare(getCores(this), getCores(thatHardware)).compare(this.getRam(), thatHardware.getRam())
+               .compare(getSpace(this), getSpace(thatHardware)).result();
       } else {
          return super.compareTo(that);
       }
diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java
index 63adb96..e75fc7d 100644
--- a/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java
+++ b/compute/src/main/java/org/jclouds/compute/domain/internal/TemplateBuilderImpl.java
@@ -437,6 +437,7 @@
          predicates.add(hypervisorPredicate);
       predicates.add(hardwareCoresPredicate);
       predicates.add(hardwareRamPredicate);
+      predicates.add(hardwareDiskPredicate);
 
       // looks verbose, but explicit <Hardware> type needed for this to compile
       // properly
diff --git a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java
index aeb795f..ea31832 100644
--- a/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java
+++ b/providers/hpcloud-objectstorage/src/main/java/org/jclouds/hpcloud/objectstorage/HPCloudObjectStorageApiMetadata.java
@@ -19,6 +19,8 @@
 package org.jclouds.hpcloud.objectstorage;
 
 import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
+import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
+import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
 
 import java.net.URI;
 import java.util.Properties;
@@ -26,6 +28,9 @@
 import org.jclouds.apis.ApiMetadata;
 import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
 import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule;
+import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
+import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
+import org.jclouds.openstack.services.ServiceType;
 import org.jclouds.openstack.swift.SwiftApiMetadata;
 import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule;
 import org.jclouds.rest.RestContext;
@@ -66,6 +71,10 @@
 
    public static Properties defaultProperties() {
       Properties properties = SwiftApiMetadata.defaultProperties();
+      properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
+      // TODO: this doesn't actually do anything yet.
+      properties.setProperty(KeystoneProperties.VERSION, "2.0");
+      properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
       properties.remove(PROPERTY_REGIONS);
       return properties;
    }
diff --git a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageClientLiveTest.java b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageClientLiveTest.java
index e96403d..22dd71b 100644
--- a/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageClientLiveTest.java
+++ b/providers/ninefold-storage/src/test/java/org/jclouds/ninefold/storage/NinefoldStorageClientLiveTest.java
@@ -26,7 +26,9 @@
  * 
  * @author Adrian Cole
  */
-@Test(groups = "live", sequential = true, testName = "NinefoldStorageClientLiveTest")
+@Test(groups = "live", singleThreaded = true, testName = "NinefoldStorageClientLiveTest")
 public class NinefoldStorageClientLiveTest extends AtmosClientLiveTest {
-
+   public NinefoldStorageClientLiveTest() {
+      provider = "ninefold-storage";
+   }
 }