You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2014/03/18 03:52:01 UTC
[08/20] fixing https://issues.apache.org/jira/browse/STRATOS-520 -
adding Openstack-nova module to dependencies
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java
new file mode 100644
index 0000000..d958324
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiLiveTest.java
@@ -0,0 +1,123 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.jclouds.openstack.nova.v2_0.features.FlavorApi;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.jclouds.openstack.v2_0.domain.Resource;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
+
+/**
+ * Tests behavior of FlavorExtraSpecsApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "FlavorExtraSpecsApiLiveTest", singleThreaded = true)
+public class FlavorExtraSpecsApiLiveTest extends BaseNovaApiLiveTest {
+ private FlavorApi flavorApi;
+ private Optional<? extends FlavorExtraSpecsApi> apiOption;
+ private String zone;
+
+ private Resource testFlavor;
+ private Map<String, String> testSpecs = ImmutableMap.of("jclouds-test", "some data", "jclouds-test2", "more data!");
+
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ flavorApi = api.getFlavorApiForZone(zone);
+ apiOption = api.getFlavorExtraSpecsExtensionForZone(zone);
+ }
+
+ @AfterClass(groups = { "integration", "live" })
+ @Override
+ protected void tearDown() {
+ if (apiOption.isPresent() && testFlavor != null) {
+ for (String key : testSpecs.keySet()) {
+ assertTrue(apiOption.get().deleteMetadataKey(testFlavor.getId(), key));
+ }
+ }
+ super.tearDown();
+ }
+
+ public void testCreateExtraSpecs() {
+ if (apiOption.isPresent()) {
+ FlavorExtraSpecsApi api = apiOption.get();
+ testFlavor = Iterables.getLast(flavorApi.list().concat());
+ Map<String, String> before = api.getMetadata(testFlavor.getId());
+ assertNotNull(before);
+ Map<String, String> specs = Maps.newHashMap(before);
+ specs.putAll(testSpecs);
+ assertTrue(api.updateMetadata(testFlavor.getId(), specs));
+ assertEquals(api.getMetadata(testFlavor.getId()), specs);
+ for (Map.Entry<String, String> entry : specs.entrySet()) {
+ assertEquals(api.getMetadataKey(testFlavor.getId(), entry.getKey()), entry.getValue());
+ }
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateExtraSpecs")
+ public void testListExtraSpecs() {
+ if (apiOption.isPresent()) {
+ FlavorExtraSpecsApi api = apiOption.get();
+ for (String key : testSpecs.keySet()) {
+ assertTrue(api.getMetadata(testFlavor.getId()).containsKey(key));
+ }
+ for (Resource flavor : flavorApi.list().concat()) {
+ Map<String, String> specs = api.getMetadata(flavor.getId());
+ assertNotNull(specs);
+ for (Map.Entry<String, String> entry : specs.entrySet()) {
+ assertEquals(api.getMetadataKey(flavor.getId(), entry.getKey()), entry.getValue());
+ }
+ }
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateExtraSpecs")
+ public void testTwiddleIndividualSpecs() {
+ if (apiOption.isPresent()) {
+ FlavorExtraSpecsApi api = apiOption.get();
+ for (String key : testSpecs.keySet()) {
+ assertTrue(api.updateMetadataEntry(testFlavor.getId(), key, "new value"));
+ }
+ for (String key : testSpecs.keySet()) {
+ assertEquals(api.getMetadataKey(testFlavor.getId(), key), "new value");
+ }
+ for (Resource flavor : flavorApi.list().concat()) {
+ Map<String, String> specs = api.getMetadata(flavor.getId());
+ assertNotNull(specs);
+ for (Map.Entry<String, String> entry : specs.entrySet()) {
+ assertEquals(api.getMetadataKey(flavor.getId(), entry.getKey()), entry.getValue());
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java
new file mode 100644
index 0000000..65cf1d4
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiExpectTest.java
@@ -0,0 +1,191 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.openstack.nova.v2_0.parse.ParseFloatingIPListTest;
+import org.jclouds.openstack.nova.v2_0.parse.ParseFloatingIPTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests annotation parsing of {@code FloatingIPAsyncApi}
+ *
+ * @author Michael Arnold
+ */
+@Test(groups = "unit", testName = "FloatingIPApiExpectTest")
+public class FloatingIPApiExpectTest extends BaseNovaApiExpectTest {
+ public void testWhenNamespaceInExtensionsListFloatingIpPresent() throws Exception {
+
+ NovaApi apiWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse);
+
+ assertEquals(apiWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
+
+ assertTrue(apiWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
+
+ }
+
+ public void testWhenNamespaceNotInExtensionsListFloatingIpNotPresent() throws Exception {
+
+ NovaApi apiWhenExtensionNotInList = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, unmatchedExtensionsOfNovaResponse);
+
+ assertEquals(apiWhenExtensionNotInList.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
+
+ assertFalse(apiWhenExtensionNotInList.getFloatingIPExtensionForZone("az-1.region-a.geo-1").isPresent());
+
+ }
+
+ public void testListFloatingIPsWhenResponseIs2xx() throws Exception {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse listResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/floatingip_list.json")).build();
+
+ NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
+
+ assertEquals(apiWhenFloatingIPsExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
+
+ assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list()
+ .toString(), new ParseFloatingIPListTest().expected().toString());
+ }
+
+ public void testListFloatingIPsWhenResponseIs404() throws Exception {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
+
+ NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
+
+ assertTrue(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().list().isEmpty());
+ }
+
+ public void testGetFloatingIPWhenResponseIs2xx() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips/1")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse getResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/floatingip_details.json")).build();
+
+ NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse);
+
+ assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1")
+ .toString(), new ParseFloatingIPTest().expected().toString());
+ }
+
+ public void testGetFloatingIPWhenResponseIs404() throws Exception {
+ HttpRequest get = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips/1")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
+
+ NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, get, getResponse);
+
+ assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().get("1"));
+ }
+
+ public void testAllocateWhenResponseIs2xx() throws Exception {
+ HttpRequest createFloatingIP = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{}", "application/json")).build();
+
+ HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/floatingip_details.json")).build();
+
+ NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
+ createFloatingIPResponse);
+
+ assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create().toString(),
+ new ParseFloatingIPTest().expected().toString());
+
+ }
+
+ public void testAllocateWhenResponseIs404() throws Exception {
+ HttpRequest createFloatingIP = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{}", "application/json")).build();
+
+ HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(404).build();
+
+ NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
+ createFloatingIPResponse);
+
+ assertNull(apiWhenNoServersExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().create());
+ }
+
+ public void testAllocateWithPoolNameWhenResponseIs2xx() throws Exception {
+ HttpRequest createFloatingIP = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-floating-ips")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"pool\":\"myPool\"}", "application/json")).build();
+
+ HttpResponse createFloatingIPResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/floatingip_details.json")).build();
+
+ NovaApi apiWhenFloatingIPsExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, createFloatingIP,
+ createFloatingIPResponse);
+
+ assertEquals(apiWhenFloatingIPsExist.getFloatingIPExtensionForZone("az-1.region-a.geo-1").get().allocateFromPool("myPool").toString(),
+ new ParseFloatingIPTest().expected().toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java
new file mode 100644
index 0000000..d85604c
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FloatingIPApiLiveTest.java
@@ -0,0 +1,171 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.nova.v2_0.domain.Address;
+import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.jclouds.openstack.nova.v2_0.features.ServerApi;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Multimap;
+
+/**
+ * Tests behavior of {@code ServerApi}
+ *
+ * @author Adrian Cole
+ */
+@Test(groups = "live", testName = "FloatingIPApiLiveTest")
+public class FloatingIPApiLiveTest extends BaseNovaApiLiveTest {
+
+ private static final int INCONSISTENCY_WINDOW = 5000;
+
+ @Test
+ public void testListFloatingIPs() throws Exception {
+ for (String zoneId : api.getConfiguredZones()) {
+ Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPExtensionForZone(zoneId);
+ if (!apiOption.isPresent())
+ continue;
+ FloatingIPApi api = apiOption.get();
+ Set<? extends FloatingIP> response = api.list().toSet();
+ assert null != response;
+ assertTrue(response.size() >= 0);
+ for (FloatingIP ip : response) {
+ FloatingIP newDetails = api.get(ip.getId());
+
+ assertEquals(newDetails.getId(), ip.getId());
+ assertEquals(newDetails.getIp(), ip.getIp());
+ assertEquals(newDetails.getFixedIp(), ip.getFixedIp());
+ assertEquals(newDetails.getInstanceId(), ip.getInstanceId());
+
+ }
+ }
+ }
+
+ @Test
+ public void testAllocateAndDecreateFloatingIPs() throws Exception {
+ for (String zoneId : api.getConfiguredZones()) {
+ Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPExtensionForZone(zoneId);
+ if (!apiOption.isPresent())
+ continue;
+ FloatingIPApi api = apiOption.get();
+ FloatingIP floatingIP = api.create();
+ assertNotNull(floatingIP);
+
+ Set<? extends FloatingIP> response = api.list().toSet();
+ boolean ipInSet = false;
+ for (FloatingIP ip : response) {
+ if (ip.getId().equals(floatingIP.getId()))
+ ipInSet = true;
+ }
+ assertTrue(ipInSet);
+
+ api.delete(floatingIP.getId());
+
+ response = api.list().toSet();
+ ipInSet = false;
+ for (FloatingIP ip : response) {
+ if (ip.getId().equals(floatingIP.getId())) {
+ ipInSet = true;
+ }
+ }
+ assertFalse(ipInSet);
+ }
+ }
+
+ @Test
+ public void testAddAndRemoveFloatingIp() throws Exception {
+ for (String zoneId : api.getConfiguredZones()) {
+ Optional<? extends FloatingIPApi> apiOption = api.getFloatingIPExtensionForZone(zoneId);
+ if (!apiOption.isPresent())
+ continue;
+ FloatingIPApi api = apiOption.get();
+ ServerApi serverApi = this.api.getServerApiForZone(zoneId);
+ Server server = createServerInZone(zoneId);
+ FloatingIP floatingIP = api.create();
+ assertNotNull(floatingIP);
+ try {
+ api.addToServer(floatingIP.getIp(), server.getId());
+ assertEventually(new ServerHasFloatingIP(serverApi, server.getId(), floatingIP.getIp()));
+ } finally {
+ api.removeFromServer(floatingIP.getIp(), server.getId());
+ serverApi.delete(server.getId());
+ }
+ }
+ }
+
+ protected static void assertEventually(Runnable assertion) {
+ long start = System.currentTimeMillis();
+ AssertionError error = null;
+ for (int i = 0; i < 30; i++) {
+ try {
+ assertion.run();
+ if (i > 0)
+ System.err.printf("%d attempts and %dms asserting %s%n", i + 1, System.currentTimeMillis() - start,
+ assertion.getClass().getSimpleName());
+ return;
+ } catch (AssertionError e) {
+ error = e;
+ }
+ try {
+ Thread.sleep(INCONSISTENCY_WINDOW / 30);
+ } catch (InterruptedException e) {
+ }
+ }
+ if (error != null)
+ throw error;
+
+ }
+
+ public static final class ServerHasFloatingIP implements Runnable {
+ private final ServerApi api;
+ private final String serverId;
+ private final String floatingIP;
+
+ public ServerHasFloatingIP(ServerApi serverApi, String serverId, String floatingIP) {
+ this.api = serverApi;
+ this.serverId = serverId;
+ this.floatingIP = floatingIP;
+ }
+
+ public void run() {
+ try {
+ Server server = api.get(serverId);
+ boolean ipInServerAddresses = false;
+ Multimap<String, Address> addresses = server.getAddresses();
+ for (Address address : addresses.values()) {
+ if (address.getAddr().equals(floatingIP)) {
+ ipInServerAddresses = true;
+ }
+ }
+ assertTrue(ipInServerAddresses);
+ } catch (Exception e) {
+ throw new AssertionError(e);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java
new file mode 100644
index 0000000..97861e3
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiExpectTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+import java.util.Set;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.Host;
+import org.jclouds.openstack.nova.v2_0.domain.HostResourceUsage;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests HostAdministrationApi guice wiring and parsing (including the Response parsers in FieldValueResponseParsers)
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "HostAdministrationApiExpectTest")
+public class HostAdministrationApiExpectTest extends BaseNovaApiExpectTest {
+
+
+ public void testList() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("GET")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/hosts_list.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+
+ Host expected = Host.builder().name("ubuntu").service("compute").build();
+
+ Set<? extends Host> result = api.list().toSet();
+ Host host = Iterables.getOnlyElement(result);
+ assertEquals(host.getName(), "ubuntu");
+ assertEquals(host.getService(), "compute");
+
+ assertEquals(host, expected);
+ }
+
+ public void testGet() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/xyz");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("GET")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host.json")).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+
+ Set<HostResourceUsage> expected = ImmutableSet.of(
+ HostResourceUsage.builder().memoryMb(16083).project("(total)").cpu(4).diskGb(181).host("ubuntu").build(),
+ HostResourceUsage.builder().memoryMb(3396).project("(used_now)").cpu(3).diskGb(5).host("ubuntu").build(),
+ HostResourceUsage.builder().memoryMb(6144).project("(used_max)").cpu(3).diskGb(80).host("ubuntu").build(),
+ HostResourceUsage.builder().memoryMb(6144).project("f8535069c3fb404cb61c873b1a0b4921").cpu(3).diskGb(80).host("ubuntu").build()
+ );
+
+ assertEquals(api.listResourceUsage("xyz").toSet(), expected);
+ }
+
+ public void testEnableHost() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("PUT")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"status\":\"enable\"}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"enabled\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.enable("ubuntu"));
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class)
+ public void testEnableHostFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("PUT")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"status\":\"enable\"}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404)
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ api.enable("ubuntu");
+ }
+
+ public void testEnableHostFailNotEnabled() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("PUT")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"status\":\"enable\"}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"disabled\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertFalse(api.enable("ubuntu"));
+ }
+
+ public void testDisableHost() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("PUT")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"status\":\"disable\"}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"status\":\"disabled\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.disable("ubuntu"));
+ }
+
+ public void testStartMaintenance() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("PUT")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"maintenance_mode\":\"enable\"}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"maintenance_mode\":\"on_maintenance\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.startMaintenance("ubuntu"));
+ }
+
+ public void testStopMaintenance() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu");
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("PUT")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"maintenance_mode\":\"disable\"}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"maintenance_mode\":\"off_maintenance\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.stopMaintenance("ubuntu"));
+ }
+
+ public void testStartupHost() {
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu/startup")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"startup\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.startup("ubuntu"));
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class)
+ public void testStartupHostFailNotFound() {
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu/startup")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build(),
+ HttpResponse.builder().statusCode(404).build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.startup("ubuntu"));
+ }
+
+ public void testStartupHostFailWrongActionInProgress() {
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu/startup")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"shutdown\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertFalse(api.startup("ubuntu"));
+ }
+
+ public void testShutdownHost() {
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu/shutdown")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"shutdown\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.shutdown("ubuntu"));
+ }
+
+ public void testRebootHost() {
+ HostAdministrationApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-hosts/ubuntu/reboot")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build(),
+ HttpResponse.builder().statusCode(200)
+ .payload(payloadFromStringWithContentType("{\"host\":\"ubuntu\",\"power_action\":\"reboot\"}", MediaType.APPLICATION_JSON))
+ .build()).getHostAdministrationExtensionForZone("az-1.region-a.geo-1").get();
+ assertTrue(api.reboot("ubuntu"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java
new file mode 100644
index 0000000..814cd7d
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAdministrationApiLiveTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Set;
+
+import org.jclouds.openstack.nova.v2_0.domain.Host;
+import org.jclouds.openstack.nova.v2_0.domain.HostResourceUsage;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.testng.annotations.BeforeGroups;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of HostAdministrationApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "HostAdministrationApiLiveTest", singleThreaded = true)
+public class HostAdministrationApiLiveTest extends BaseNovaApiLiveTest {
+ private Optional<? extends HostAdministrationApi> optApi = Optional.absent();
+
+ Predicate<Host> isComputeHost = new Predicate<Host>() {
+ @Override
+ public boolean apply(Host input) {
+ return Objects.equal("compute", input.getService());
+ }
+ };
+
+ @BeforeGroups(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+
+ if (identity.endsWith(":admin")) {
+ String zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ optApi = api.getHostAdministrationExtensionForZone(zone);
+ }
+ }
+
+ public void testListAndGet() throws Exception {
+ if (optApi.isPresent()) {
+ HostAdministrationApi api = optApi.get();
+ Set<? extends Host> hosts = api.list().toSet();
+ assertNotNull(hosts);
+ for (Host host : hosts) {
+ for (HostResourceUsage usage : api.listResourceUsage(host.getName())) {
+ assertEquals(usage.getHost(), host.getName());
+ assertNotNull(usage);
+ }
+ }
+ }
+ }
+
+ @Test(enabled = false)
+ public void testEnableDisable() throws Exception {
+ if (optApi.isPresent()) {
+ HostAdministrationApi api = optApi.get();
+ Host host = Iterables.find(api.list(), isComputeHost);
+
+ assertTrue(api.disable(host.getName()));
+ assertTrue(api.enable(host.getName()));
+ }
+ }
+
+ @Test(enabled = false)
+ public void testMaintenanceMode() throws Exception {
+ if (optApi.isPresent()) {
+ HostAdministrationApi api = optApi.get();
+ Host host = Iterables.find(api.list(), isComputeHost);
+ assertTrue(api.startMaintenance(host.getName()));
+ assertTrue(api.stopMaintenance(host.getName()));
+ }
+ }
+
+ @Test(enabled = false)
+ public void testReboot() throws Exception {
+ if (optApi.isPresent()) {
+ HostAdministrationApi api = optApi.get();
+ Host host = Iterables.find(api.list(), isComputeHost);
+ assertTrue(api.reboot(host.getName()));
+ }
+ }
+
+ @Test(enabled = false)
+ public void testShutdownAndStartup() throws Exception {
+ if (optApi.isPresent()) {
+ HostAdministrationApi api = optApi.get();
+ Host host = Iterables.find(api.list(), isComputeHost);
+ assertTrue(api.shutdown(host.getName()));
+ assertTrue(api.startup(host.getName()));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java
new file mode 100644
index 0000000..4f0ac08
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiExpectTest.java
@@ -0,0 +1,179 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.date.DateService;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.HostAggregate;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests HostAggregateApi guice wiring and parsing
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "HostAggregateApiExpectTest")
+public class HostAggregateApiExpectTest extends BaseNovaApiExpectTest {
+ private DateService dateService = new SimpleDateFormatDateService();
+
+ public void testList() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_list.json")).build())
+ .getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ HostAggregate result = Iterables.getOnlyElement(api.list());
+ assertEquals(result, exampleHostAggregate());
+ }
+
+ public void testGet() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_with_host_details.json")).build())
+ .getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.get("1"), exampleHostAggregateWithHost());
+ }
+
+ public void testGetFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.get("1"));
+ }
+
+ public void testCreateAggregate() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"aggregate\":{\"name\":\"ubuntu1\",\"availability_zone\":\"nova\"}}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build())
+ .getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.createInAvailabilityZone("ubuntu1", "nova"), exampleHostAggregate());
+ }
+
+ public void testDeleteAggregate() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.delete("1"));
+ }
+
+ public void testDeleteAggregateFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(404).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.delete("1"));
+ }
+
+ public void testUpdateName() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"aggregate\":{\"name\":\"newaggregatename\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.updateName("1", "newaggregatename"), exampleHostAggregate());
+ }
+
+ public void testUpdateAvailabilityZone() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"aggregate\":{\"availability_zone\":\"zone1\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.updateAvailabilityZone("1", "zone1"), exampleHostAggregate());
+ }
+
+ public void testAddHost() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1/action");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"add_host\":{\"host\":\"ubuntu\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.addHost("1", "ubuntu"), exampleHostAggregate());
+ }
+
+ public void testRemoveHost() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1/action");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"remove_host\":{\"host\":\"ubuntu\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.removeHost("1", "ubuntu"), exampleHostAggregate());
+ }
+
+
+ public void testSetMetadata() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-aggregates/1/action");
+ HostAggregateApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"set_metadata\":{\"metadata\":{\"mykey\":\"some value or other\"}}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/host_aggregate_details.json")).build()).getHostAggregateExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.setMetadata("1", ImmutableMap.of("mykey", "some value or other")), exampleHostAggregate());
+ }
+
+ public HostAggregate exampleHostAggregate() {
+ return HostAggregate.builder().name("jclouds-test-a").availabilityZone("nova")
+ .created(dateService.iso8601SecondsDateParse("2012-05-11 11:40:17"))
+ .updated(dateService.iso8601SecondsDateParse("2012-05-11 11:46:44"))
+ .state("created").id("1").metadata(ImmutableMap.of("somekey", "somevalue", "anotherkey", "another val")).build();
+ }
+
+ public HostAggregate exampleHostAggregateWithHost() {
+ return exampleHostAggregate().toBuilder().hosts("ubuntu").build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java
new file mode 100644
index 0000000..5a237db
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/HostAggregateApiLiveTest.java
@@ -0,0 +1,148 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jclouds.openstack.nova.v2_0.domain.Host;
+import org.jclouds.openstack.nova.v2_0.domain.HostAggregate;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of AggregateApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "AggregateApiLiveTest", singleThreaded = true)
+public class HostAggregateApiLiveTest extends BaseNovaApiLiveTest {
+ private Optional<? extends HostAggregateApi> apiOption;
+ private Optional<? extends HostAdministrationApi> hostAdminOption;
+
+ private HostAggregate testAggregate;
+
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ String zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ apiOption = api.getHostAggregateExtensionForZone(zone);
+ hostAdminOption = api.getHostAdministrationExtensionForZone(zone);
+ }
+
+ @AfterClass(groups = { "integration", "live" })
+ @Override
+ protected void tearDown() {
+ if (testAggregate != null) {
+ assertTrue(apiOption.get().delete(testAggregate.getId()));
+ }
+ super.tearDown();
+ }
+
+ public void testCreateAggregate() {
+ if (apiOption.isPresent()) {
+ // TODO assuming "nova" availability zone is present
+ testAggregate = apiOption.get().createInAvailabilityZone("jclouds-test-a", "nova");
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateAggregate")
+ public void testListAndGetAggregate() {
+ if (apiOption.isPresent()) {
+ HostAggregateApi api = apiOption.get();
+ Set<? extends HostAggregate> aggregates = api.list().toSet();
+ for (HostAggregate aggregate : aggregates) {
+ assertNotNull(aggregate.getId());
+ assertNotNull(aggregate.getName());
+ assertNotNull(aggregate.getAvailabilityZone());
+
+ HostAggregate details = api.get(aggregate.getId());
+ assertEquals(details.getId(), aggregate.getId());
+ assertEquals(details.getName(), aggregate.getName());
+ assertEquals(details.getAvailabilityZone(), aggregate.getAvailabilityZone());
+ assertEquals(details.getHosts(), aggregate.getHosts());
+ }
+ }
+ }
+
+ @Test(dependsOnMethods = "testCreateAggregate")
+ public void testModifyMetadata() {
+ if (apiOption.isPresent()) {
+ HostAggregateApi api = apiOption.get();
+ for (Map<String, String> theMetaData : ImmutableSet.of(
+ ImmutableMap.of("somekey", "somevalue"),
+ ImmutableMap.of("somekey", "some other value", "anotherkey", "another val")
+ )) {
+ // Apply changes
+ HostAggregate details = api.setMetadata(testAggregate.getId(), theMetaData);
+
+ // bug in openstack - metadata values are never removed, so we just checking what we've set
+ for (Map.Entry<String, String> entry : theMetaData.entrySet()) {
+ assertEquals(details.getMetadata().get(entry.getKey()), entry.getValue());
+ }
+
+ // Re-fetch to double-check
+ details = api.get(testAggregate.getId());
+ for (Map.Entry<String, String> entry : theMetaData.entrySet()) {
+ assertEquals(details.getMetadata().get(entry.getKey()), entry.getValue());
+ }
+ }
+ }
+ }
+
+ // Note the host will be added, but cannot remove it til
+ @Test(enabled = false, dependsOnMethods = "testCreateAggregate")
+ public void testModifyHosts() {
+ if (apiOption.isPresent() && hostAdminOption.isPresent()) {
+ HostAggregateApi api = apiOption.get();
+ Host host = Iterables.getFirst(hostAdminOption.get().list(), null);
+ assertNotNull(host);
+
+ String host_id = host.getName();
+ assertNotNull(host_id);
+ HostAggregate details;
+
+ try {
+ details = api.addHost(testAggregate.getId(), host_id);
+
+ assertEquals(details.getHosts(), ImmutableSet.of(host_id));
+
+ // re-fetch to double-check
+ details = api.get(testAggregate.getId());
+ assertEquals(details.getHosts(), ImmutableSet.of(host_id));
+
+ // TODO wait until status of aggregate isn't CHANGING (hostAdministration.shutdown?)
+ } finally {
+ details = api.removeHost(testAggregate.getId(), host_id);
+ }
+
+ assertEquals(details.getHosts(), ImmutableSet.of());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java
new file mode 100644
index 0000000..55f0d58
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiExpectTest.java
@@ -0,0 +1,142 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.openstack.nova.v2_0.parse.ParseKeyPairListTest;
+import org.jclouds.openstack.nova.v2_0.parse.ParseKeyPairTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests annotation parsing of {@code KeyPairAsyncApi}
+ *
+ * @author Michael Arnold
+ */
+@Test(groups = "unit", testName = "KeyPairApiExpectTest")
+public class KeyPairApiExpectTest extends BaseNovaApiExpectTest {
+
+ public void testListKeyPairsWhenResponseIs2xx() throws Exception {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse listResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/keypair_list.json")).build();
+
+ NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
+
+ assertEquals(apiWhenServersExist.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
+
+ // NOTE this required a change to the KeyPair domain object toString method
+ assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().list().toString(),
+ new ParseKeyPairListTest().expected().toString());
+ }
+
+ public void testListKeyPairsWhenResponseIs404() throws Exception {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
+
+ NovaApi apiWhenNoServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
+
+ assertTrue(apiWhenNoServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().list().isEmpty());
+
+ }
+
+ public void testCreateKeyPair() throws Exception {
+ HttpRequest create = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"keypair\":{\"name\":\"testkeypair\"}}", "application/json"))
+ .build();
+
+ HttpResponse createResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/keypair_created.json")).build();
+
+ NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, create, createResponse);
+
+ assertEquals(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().create("testkeypair")
+ .toString(), new ParseKeyPairTest().expected().toString());
+
+ }
+
+ public void testCreateKeyPairWithPublicKey() throws Exception {
+ HttpRequest create = HttpRequest
+ .builder()
+ .method("POST")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(
+ payloadFromStringWithContentType(
+ "{\"keypair\":{\"name\":\"testkeypair\",\"public_key\":\"ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n\"}}",
+ "application/json")).build();
+
+ HttpResponse createResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/keypair_created.json")).build();
+
+ NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, create, createResponse);
+
+ assertEquals(
+ apiWhenServersExist
+ .getKeyPairExtensionForZone("az-1.region-a.geo-1")
+ .get()
+ .createWithPublicKey(
+ "testkeypair",
+ "ssh-rsa AAAXB3NzaC1yc2EAAAADAQABAAAAgQDFNyGjgs6c9akgmZ2ou/fJf7Pdrc23hC95/gM/33OrG4GZABACE4DTioa/PGN+7rHv9YUavUCtXrWayhGniKq/wCuI5fo5TO4AmDNv7/sCGHIHFumADSIoLx0vFhGJIetXEWxL9r0lfFC7//6yZM2W3KcGjbMtlPXqBT9K9PzdyQ== nova@nv-aw2az1-api0001\n")
+ .toString(), new ParseKeyPairTest().expected().toString());
+ }
+
+ public void testDeleteKeyPair() throws Exception {
+ HttpRequest delete = HttpRequest
+ .builder()
+ .method("DELETE")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-keypairs/testkeypair")
+ .addHeader("Accept", "*/*")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse deleteResponse = HttpResponse.builder().statusCode(202).build();
+
+ NovaApi apiWhenServersExist = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, delete, deleteResponse);
+
+ assertTrue(apiWhenServersExist.getKeyPairExtensionForZone("az-1.region-a.geo-1").get().delete("testkeypair"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java
new file mode 100644
index 0000000..da2e1e4
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/KeyPairApiLiveTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertNotNull;
+
+import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.FluentIterable;
+
+/**
+ * Tests behavior of {@code KeyPairApi}
+ *
+ * @author Michael Arnold
+ */
+@Test(groups = "live", testName = "KeyPairApiLiveTest")
+public class KeyPairApiLiveTest extends BaseNovaApiLiveTest {
+
+ public void testListKeyPairs() throws Exception {
+ for (String zoneId : api.getConfiguredZones()) {
+ KeyPairApi keyPairApi = api.getKeyPairExtensionForZone(zoneId).get();
+ FluentIterable<? extends KeyPair> keyPairsList = keyPairApi.list();
+ assertNotNull(keyPairsList);
+ }
+ }
+
+ public void testCreateAndDeleteKeyPair() throws Exception {
+ final String KEYPAIR_NAME = "testkp";
+ for (String zoneId : api.getConfiguredZones()) {
+ KeyPairApi keyPairApi = api.getKeyPairExtensionForZone(zoneId).get();
+ KeyPair keyPair = null;
+ try {
+ keyPair = keyPairApi.create(KEYPAIR_NAME);
+ assertNotNull(keyPair);
+ } finally {
+ if (keyPair != null) {
+ keyPairApi.delete(KEYPAIR_NAME);
+ }
+ }
+ }
+ }
+
+ public void testCreateAndDeleteKeyPairWithPublicKey() throws Exception {
+ final String KEYPAIR_NAME = "testkp";
+ final String PUBLIC_KEY = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCrrBREFxz3002l1HuXz0+UOdJQ/mOYD5DiJwwB/TOybwIKQJPOxJWA9gBoo4k9dthTKBTaEYbzrll7iZcp59E80S6mNiAr3mUgi+x5Y8uyXeJ2Ws+h6peVyFVUu9epkwpcTd1GVfdcVWsTajwDz9+lxCDhl0RZKDFoT0scTxbj/w== nova@nv-aw2az2-api0002";
+
+ for (String zoneId : api.getConfiguredZones()) {
+ KeyPairApi keyPairApi = api.getKeyPairExtensionForZone(zoneId).get();
+ KeyPair keyPair = null;
+ try {
+ keyPair = keyPairApi.createWithPublicKey(KEYPAIR_NAME, PUBLIC_KEY);
+ assertNotNull(keyPair);
+ } finally {
+ if (keyPair != null) {
+ keyPairApi.delete(KEYPAIR_NAME);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java
new file mode 100644
index 0000000..79e6747
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiExpectTest.java
@@ -0,0 +1,125 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.net.URI;
+
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.Quota;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.annotations.Test;
+
+/**
+ * Tests HostAdministrationApi guice wiring and parsing
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "QuotaApiExpectTest")
+public class QuotaApiExpectTest extends BaseNovaApiExpectTest {
+
+ public void testGetQuotas() throws Exception {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-quota-sets/demo");
+ QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.getByTenant("demo"), getTestQuotas());
+ }
+
+ public void testGetQuotasFailsTenantNotFound() throws Exception {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-quota-sets/demo");
+ QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
+ assertNull(api.getByTenant("demo"));
+ }
+
+ public void testGetDefaultQuotas() throws Exception {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-quota-sets/demo/defaults");
+ QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/quotas.json")).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.getDefaultsForTenant("demo"), getTestQuotas());
+ }
+
+ public void testGetDefaultQuotasFailsTenantNotFound() throws Exception {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-quota-sets/demo/defaults");
+ QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
+ assertNull(api.getDefaultsForTenant("demo"));
+ }
+
+
+ public void testUpdateQuotas() throws Exception {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-quota-sets/demo");
+ QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().endpoint(endpoint).method("PUT")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromResourceWithContentType("/quotas.json", MediaType.APPLICATION_JSON))
+ .build(),
+ HttpResponse.builder().statusCode(200).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.updateQuotaOfTenant(getTestQuotas(), "demo"));
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class)
+ public void testUpdateQuotasFailsNotFound() throws Exception {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-quota-sets/demo");
+ QuotaApi api = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ HttpRequest.builder().endpoint(endpoint).method("PUT")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromResourceWithContentType("/quotas.json", MediaType.APPLICATION_JSON))
+ .build(),
+ HttpResponse.builder().statusCode(404).build()).getQuotaExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.updateQuotaOfTenant(getTestQuotas(), "demo");
+ }
+
+ public static Quota getTestQuotas() {
+ return Quota.builder()
+ .metadataItems(128)
+ .injectedFileContentBytes(10240)
+ .injectedFiles(5)
+ .gigabytes(1000)
+ .ram(51200)
+ .floatingIps(10)
+ .securityGroups(10)
+ .securityGroupRules(20)
+ .instances(10)
+ .keyPairs(100)
+ .volumes(10)
+ .cores(20)
+ .id("demo").build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5857efca/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java
new file mode 100644
index 0000000..1408223
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/QuotaApiLiveTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.jclouds.openstack.nova.v2_0.extensions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+import org.jclouds.openstack.nova.v2_0.domain.Quota;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+
+/**
+ * Tests behavior of QuotaApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "QuotaApiLiveTest", singleThreaded = true)
+public class QuotaApiLiveTest extends BaseNovaApiLiveTest {
+ private Optional<? extends QuotaApi> apiOption;
+ private String tenant;
+
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ tenant = identity.split(":")[0];
+ String zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ apiOption = api.getQuotaExtensionForZone(zone);
+ }
+
+ public void testGetQuotasForCurrentTenant() {
+ if (apiOption.isPresent()) {
+ Quota quota = apiOption.get().getByTenant(tenant);
+ assertQuotasIsValid(quota);
+ }
+ }
+
+ public void testGetDefaultQuotasForCurrentTenant() {
+ if (apiOption.isPresent()) {
+ Quota quota = apiOption.get().getDefaultsForTenant(tenant);
+ assertQuotasIsValid(quota);
+ }
+ }
+
+ public void testUpdateQuotasOfCurrentTenantThenReset() {
+ if (apiOption.isPresent()) {
+ QuotaApi api = apiOption.get();
+ Quota before = api.getByTenant(tenant);
+ assertQuotasIsValid(before);
+
+ Quota modified = before.toBuilder()
+ .cores(before.getCores() - 1)
+ .instances(before.getInstances() - 1)
+ .metadataItems(before.getMetadatas() - 1)
+ .ram(before.getRam() - 1)
+ .volumes(before.getVolumes() - 1)
+ .build();
+
+ assertTrue(api.updateQuotaOfTenant(modified, tenant));
+
+ assertEquals(api.getByTenant(tenant), modified);
+
+ assertTrue(api.updateQuotaOfTenant(before, tenant));
+
+ assertEquals(api.getByTenant(tenant), before);
+ }
+ }
+
+ protected void assertQuotasIsValid(Quota quota) {
+ assertTrue(quota.getCores() > 0);
+ assertTrue(quota.getFloatingIps() >= 0);
+ assertTrue(quota.getGigabytes() > 0);
+ assertTrue(quota.getInjectedFileContentBytes() >= 0);
+ assertTrue(quota.getInjectedFiles() >= 0);
+ assertTrue(quota.getInstances() > 0);
+ assertTrue(quota.getKeyPairs() > 0);
+ assertTrue(quota.getRam() > 0);
+ assertTrue(quota.getSecurityGroups() > 0);
+ assertTrue(quota.getSecurityGroupRules() > 0);
+ assertTrue(quota.getVolumes() > 0);
+ }
+}