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:02 UTC
[09/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/compute/functions/ServerInZoneToNodeMetadataTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java
new file mode 100644
index 0000000..7ef9fa7
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/ServerInZoneToNodeMetadataTest.java
@@ -0,0 +1,311 @@
+/*
+ * 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.compute.functions;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Set;
+
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.HardwareBuilder;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.ImageBuilder;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.OperatingSystem;
+import org.jclouds.compute.domain.OsFamily;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
+import org.jclouds.domain.LocationScope;
+import org.jclouds.openstack.nova.v2_0.compute.config.NovaComputeServiceContextModule;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ServerInZone;
+import org.jclouds.openstack.nova.v2_0.parse.ParseServerTest;
+import org.jclouds.openstack.v2_0.domain.Link;
+import org.jclouds.openstack.v2_0.domain.Resource;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.inject.Guice;
+
+/**
+ * Tests for the function for transforming a nova specific Server into a generic
+ * NodeMetadata object.
+ *
+ * @author Matt Stephenson, Adam Lowe, Adrian Cole
+ */
+@Test(testName = "ServerInZoneToNodeMetadataTest")
+public class ServerInZoneToNodeMetadataTest {
+
+ Location provider = new LocationBuilder().scope(LocationScope.PROVIDER).id("openstack-nova")
+ .description("openstack-nova").build();
+ Location zone = new LocationBuilder().id("az-1.region-a.geo-1").description("az-1.region-a.geo-1")
+ .scope(LocationScope.ZONE).parent(provider).build();
+ Supplier<Map<String, Location>> locationIndex = Suppliers.<Map<String, Location>> ofInstance(ImmutableMap
+ .<String, Location> of("az-1.region-a.geo-1", zone));
+
+ GroupNamingConvention.Factory namingConvention = Guice.createInjector().getInstance(GroupNamingConvention.Factory.class);
+
+ @Test
+ public void testWhenNoHardwareOrImageMatchServerScopedIdsImageIdIsStillSet() {
+
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/FOOOOOOOO").providerId("FOOOOOOOO")
+ .location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/FOOOOOOOO")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("FOOOOOOOO").description("foobuntu").location(zone).status(Image.Status.AVAILABLE).build();
+
+ checkHardwareAndImageStatus(null, existingHardware, "az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54",
+ null, existingImage);
+ }
+
+ @Test
+ public void testWhenNoHardwareAndImageMatchServerScopedIdsHardwareOperatingSystemAndImageIdAreSet() {
+
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ checkHardwareAndImageStatus(existingHardware, existingHardware, existingImage.getId(),
+ existingImage.getOperatingSystem(), existingImage);
+ }
+
+ @Test
+ public void testNullAccessIPs() {
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected().toBuilder()
+ .accessIPv4(null)
+ .accessIPv6(null)
+ .build();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131"));
+ }
+
+ @Test
+ public void testDuplicateAccessIPs() {
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected().toBuilder()
+ .accessIPv4("67.23.10.132")
+ .accessIPv6("::babe:67.23.10.132")
+ .build();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131"));
+ }
+
+ @Test
+ public void testAlternateAccessIPs() {
+ Hardware existingHardware = new HardwareBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f216543fd")
+ .providerId("52415800-8b69-11e0-9b19-734f216543fd").location(zone).build();
+ Image existingImage = new ImageBuilder().id("az-1.region-a.geo-1/52415800-8b69-11e0-9b19-734f6f006e54")
+ .operatingSystem(OperatingSystem.builder().family(OsFamily.LINUX).description("foobuntu").build())
+ .providerId("52415800-8b69-11e0-9b19-734f6f006e54").description("foobuntu").status(Image.Status.AVAILABLE)
+ .location(zone).build();
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected().toBuilder()
+ .accessIPv4("76.32.1.231")
+ .accessIPv6("::babe:76.32.1.231")
+ .build();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131", "76.32.1.231"));
+ }
+
+ // TODO: clean up this syntax
+ private void checkHardwareAndImageStatus(Hardware expectedHardware, Hardware existingHardware,
+ String expectedImageId, OperatingSystem expectedOs, Image existingImage) {
+
+ Set<Image> images = existingImage == null ? ImmutableSet.<Image> of() : ImmutableSet.of(existingImage);
+ Set<Hardware> hardwares = existingHardware == null ? ImmutableSet.<Hardware> of() : ImmutableSet
+ .of(existingHardware);
+ Server serverToConvert = new ParseServerTest().expected();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
+ assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
+
+ assertEquals(convertedNodeMetadata.getLocation().getScope(), LocationScope.HOST);
+ assertEquals(convertedNodeMetadata.getLocation().getId(), "e4d909c290d0fb1ca068ffaddf22cbd0");
+
+ assertEquals(convertedNodeMetadata.getLocation().getParent(), locationIndex.get().get("az-1.region-a.geo-1"));
+
+ assertEquals(serverToConvert.getName(), convertedNodeMetadata.getName());
+ assertEquals(convertedNodeMetadata.getGroup(), "sample");
+
+ assertEquals(convertedNodeMetadata.getImageId(), expectedImageId);
+ assertEquals(convertedNodeMetadata.getOperatingSystem(), expectedOs);
+
+ assertEquals(convertedNodeMetadata.getHardware(), expectedHardware);
+
+ assertEquals(NovaComputeServiceContextModule.toPortableNodeStatus.get(serverToConvert.getStatus()),
+ convertedNodeMetadata.getStatus());
+
+ assertNotNull(convertedNodeMetadata.getPrivateAddresses());
+ assertEquals(convertedNodeMetadata.getPrivateAddresses(), ImmutableSet.of("10.176.42.16"));
+
+ assertNotNull(convertedNodeMetadata.getPublicAddresses());
+ // note jclouds doesn't yet support ipv6 b/c not tested yet
+ assertEquals(convertedNodeMetadata.getPublicAddresses(), ImmutableSet.of("67.23.10.132", "67.23.10.131"));
+
+ assertNotNull(convertedNodeMetadata.getUserMetadata());
+ assertEquals(convertedNodeMetadata.getUserMetadata(),
+ ImmutableMap.<String, String> of("Server Label", "Web Head 1", "Image Version", "2.1"));
+
+ URI expectedURI = URI.create("http://servers.api.openstack.org/v1.1/1234/servers/52415800-8b69-11e0-9b19-734f6f006e54");
+ assertEquals(convertedNodeMetadata.getUri(), expectedURI);
+ }
+
+ @Test
+ public void testNewServerWithoutHostIdSetsZoneAsLocation() {
+
+ Set<Image> images = ImmutableSet.<Image> of();
+ Set<Hardware> hardwares = ImmutableSet.<Hardware> of();
+
+ Server serverToConvert = expectedServer();
+
+ ServerInZone serverInZoneToConvert = new ServerInZone(serverToConvert, "az-1.region-a.geo-1");
+
+ ServerInZoneToNodeMetadata converter = new ServerInZoneToNodeMetadata(
+ NovaComputeServiceContextModule.toPortableNodeStatus, locationIndex, Suppliers
+ .<Set<? extends Image>> ofInstance(images), Suppliers
+ .<Set<? extends Hardware>> ofInstance(hardwares), namingConvention);
+
+ NodeMetadata convertedNodeMetadata = converter.apply(serverInZoneToConvert);
+
+ assertEquals(serverInZoneToConvert.slashEncode(), convertedNodeMetadata.getId());
+ assertEquals(serverToConvert.getId(), convertedNodeMetadata.getProviderId());
+
+ assertEquals(convertedNodeMetadata.getLocation(), zone);
+
+ URI expectedURI = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752");
+ assertEquals(convertedNodeMetadata.getUri(), expectedURI);
+ }
+
+ public Server expectedServer() {
+ return Server
+ .builder()
+ .id("71752")
+ .uuid("47491020-6a78-4f63-9475-23195ac4515c")
+ .tenantId("37936628937291")
+ .userId("54297837463082")
+ .name("test-e92")
+ .updated(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-03-19T06:21:13Z"))
+ .created(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-03-19T06:21:13Z"))
+ .status(Server.Status.BUILD)
+ .image(
+ Resource
+ .builder()
+ .id("1241")
+ .links(
+ Link.create(
+ Link.Relation.BOOKMARK,
+ URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/images/1241")))
+ .build())
+ .flavor(
+ Resource
+ .builder()
+ .id("100")
+ .links(
+ Link.create(
+ Link.Relation.BOOKMARK,
+ URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/flavors/100")))
+ .build())
+ .links(
+ Link.create(Link.Relation.SELF, URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/37936628937291/servers/71752")),
+ Link.create(Link.Relation.BOOKMARK, URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/37936628937291/servers/71752"))).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/compute/loaders/CreateUniqueKeyPairTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java
new file mode 100644
index 0000000..9bca8e1
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/CreateUniqueKeyPairTest.java
@@ -0,0 +1,111 @@
+/*
+ * 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.compute.loaders;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+
+import java.net.UnknownHostException;
+
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.extensions.KeyPairApi;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.inject.AbstractModule;
+import com.google.inject.Guice;
+import com.google.inject.TypeLiteral;
+
+/**
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "CreateUniqueKeyPairTest")
+public class CreateUniqueKeyPairTest {
+
+ @Test
+ public void testApply() throws UnknownHostException {
+ final NovaApi api = createMock(NovaApi.class);
+ KeyPairApi keyApi = createMock(KeyPairApi.class);
+
+ KeyPair pair = createMock(KeyPair.class);
+
+ Optional optKeyApi = Optional.of(keyApi);
+
+ expect(api.getKeyPairExtensionForZone("zone")).andReturn(optKeyApi).atLeastOnce();
+
+ expect(keyApi.create("group-1")).andReturn(pair);
+
+ replay(api, keyApi);
+
+ CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() {
+
+ @Override
+ protected void configure() {
+ bind(new TypeLiteral<Supplier<String>>() {
+ }).toInstance(Suppliers.ofInstance("1"));
+ bind(NovaApi.class).toInstance(api);
+ }
+
+ }).getInstance(CreateUniqueKeyPair.class);
+
+ assertEquals(parser.load(ZoneAndName.fromZoneAndName("zone", "group")), pair);
+
+ verify(api, keyApi);
+ }
+
+ @Test
+ public void testApplyWithIllegalStateException() throws UnknownHostException {
+ final NovaApi api = createMock(NovaApi.class);
+ KeyPairApi keyApi = createMock(KeyPairApi.class);
+ @SuppressWarnings("unchecked")
+ final Supplier<String> uniqueIdSupplier = createMock(Supplier.class);
+
+ KeyPair pair = createMock(KeyPair.class);
+
+ expect(api.getKeyPairExtensionForZone("zone")).andReturn((Optional) Optional.of(keyApi)).atLeastOnce();
+
+ expect(uniqueIdSupplier.get()).andReturn("1");
+ expect(keyApi.create("group-1")).andThrow(new IllegalStateException());
+ expect(uniqueIdSupplier.get()).andReturn("2");
+ expect(keyApi.create("group-2")).andReturn(pair);
+
+ replay(api, keyApi, uniqueIdSupplier);
+
+ CreateUniqueKeyPair parser = Guice.createInjector(new AbstractModule() {
+
+ @Override
+ protected void configure() {
+ bind(new TypeLiteral<Supplier<String>>() {
+ }).toInstance(uniqueIdSupplier);
+ bind(NovaApi.class).toInstance(api);
+ }
+
+ }).getInstance(CreateUniqueKeyPair.class);
+
+ assertEquals(parser.load(ZoneAndName.fromZoneAndName("zone", "group")), pair);
+
+ verify(api, keyApi, uniqueIdSupplier);
+ }
+
+}
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/compute/loaders/FindSecurityGroupOrCreateTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java
new file mode 100644
index 0000000..62f45fd
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreateTest.java
@@ -0,0 +1,144 @@
+/*
+ * 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.compute.loaders;
+
+import static org.easymock.EasyMock.createMock;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.fail;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.SecurityGroupInZone;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndName;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAndPorts;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Function;
+import com.google.common.base.Functions;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Adrian Cole
+ */
+@Test(groups = "unit", singleThreaded = true, testName = "FindSecurityGroupOrCreateTest")
+public class FindSecurityGroupOrCreateTest {
+
+ @Test
+ public void testWhenNotFoundCreatesANewSecurityGroup() throws Exception {
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysFalse();
+
+ SecurityGroupInZone securityGroupInZone = createMock(SecurityGroupInZone.class);
+
+ ZoneSecurityGroupNameAndPorts input = new ZoneSecurityGroupNameAndPorts("zone", "groupName", ImmutableSet
+ .<Integer> of(22, 8080));
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = Functions.forMap(ImmutableMap
+ .<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> of(input, securityGroupInZone));
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ assertEquals(parser.load(input), securityGroupInZone);
+
+ }
+
+ @Test
+ public void testWhenFoundReturnsSecurityGroupFromAtomicReferenceValueUpdatedDuringPredicateCheck() throws Exception {
+ final SecurityGroupInZone securityGroupInZone = createMock(SecurityGroupInZone.class);
+
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = new Predicate<AtomicReference<ZoneAndName>>() {
+
+ @Override
+ public boolean apply(AtomicReference<ZoneAndName> input) {
+ input.set(securityGroupInZone);
+ return true;
+ }
+
+ };
+
+ ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
+
+ @Override
+ public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
+ fail();
+ return null;
+ }
+
+ };
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ assertEquals(parser.load(input), securityGroupInZone);
+
+ }
+
+
+ @Test(expectedExceptions = IllegalStateException.class)
+ public void testWhenFoundPredicateMustUpdateAtomicReference() throws Exception {
+
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysTrue();
+
+ ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
+
+ @Override
+ public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
+ fail();
+ return null;
+ }
+
+ };
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ parser.load(input);
+
+ }
+
+
+
+ @Test(expectedExceptions = IllegalStateException.class)
+ public void testWhenNotFoundInputMustBeZoneSecurityGroupNameAndPorts() throws Exception {
+ Predicate<AtomicReference<ZoneAndName>> returnSecurityGroupExistsInZone = Predicates.alwaysFalse();
+
+ ZoneAndName input = ZoneAndName.fromZoneAndName("zone", "groupName");
+
+ Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone> groupCreator = new Function<ZoneSecurityGroupNameAndPorts, SecurityGroupInZone>() {
+
+ @Override
+ public SecurityGroupInZone apply(ZoneSecurityGroupNameAndPorts input) {
+ fail();
+ return null;
+ }
+
+ };
+
+ FindSecurityGroupOrCreate parser = new FindSecurityGroupOrCreate(
+ returnSecurityGroupExistsInZone, groupCreator);
+
+ parser.load(input);
+
+ }
+}
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/compute/loaders/LoadFloatingIpsForInstanceTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java
new file mode 100644
index 0000000..771d63f
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/loaders/LoadFloatingIpsForInstanceTest.java
@@ -0,0 +1,108 @@
+/*
+ * 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.compute.loaders;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.testng.Assert.assertEquals;
+import static org.testng.AssertJUnit.assertFalse;
+
+
+import org.jclouds.openstack.nova.v2_0.NovaApi;
+import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneAndId;
+import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPApi;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", singleThreaded = true, testName = "LoadFloatingIpsForInstanceTest")
+public class LoadFloatingIpsForInstanceTest {
+
+ @Test
+ public void testReturnsPublicIpOnMatch() throws Exception {
+ NovaApi api = createMock(NovaApi.class);
+ FloatingIPApi ipApi = createMock(FloatingIPApi.class);
+ FloatingIP testIp = FloatingIP.builder().id("1").ip("1.1.1.1").fixedIp("10.1.1.1").instanceId("i-blah").build();
+
+ expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
+ expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(testIp)))
+ .atLeastOnce();
+
+ replay(api);
+ replay(ipApi);
+
+ LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
+
+ assertEquals(ImmutableSet.copyOf(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah"))), ImmutableSet.of(testIp));
+
+ verify(api);
+ verify(ipApi);
+ }
+
+ @Test
+ public void testReturnsNullWhenNotFound() throws Exception {
+ NovaApi api = createMock(NovaApi.class);
+ FloatingIPApi ipApi = createMock(FloatingIPApi.class);
+
+ expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
+
+ expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of()))
+ .atLeastOnce();
+
+ replay(api);
+ replay(ipApi);
+
+ LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
+
+ assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
+
+ verify(api);
+ verify(ipApi);
+
+ }
+
+ @Test
+ public void testReturnsNullWhenNotAssigned() throws Exception {
+ NovaApi api = createMock(NovaApi.class);
+ FloatingIPApi ipApi = createMock(FloatingIPApi.class);
+
+ expect(api.getFloatingIPExtensionForZone("Zone")).andReturn((Optional) Optional.of(ipApi)).atLeastOnce();
+
+ expect(ipApi.list()).andReturn((FluentIterable) FluentIterable.from(ImmutableSet.<FloatingIP> of(FloatingIP.builder().id("1").ip("1.1.1.1").build())))
+ .atLeastOnce();
+
+ replay(api);
+ replay(ipApi);
+
+ LoadFloatingIpsForInstance parser = new LoadFloatingIpsForInstance(api);
+
+ assertFalse(parser.load(ZoneAndId.fromZoneAndId("Zone", "i-blah")).iterator().hasNext());
+
+ verify(api);
+ verify(ipApi);
+
+ }
+
+}
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/compute/options/NovaTemplateOptionsTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptionsTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptionsTest.java
new file mode 100644
index 0000000..106da5b
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/compute/options/NovaTemplateOptionsTest.java
@@ -0,0 +1,263 @@
+/*
+ * 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.compute.options;
+
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.authorizePublicKey;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.autoAssignFloatingIp;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.blockOnPort;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.generateKeyPair;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.inboundPorts;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.installPrivateKey;
+import static org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions.Builder.securityGroupNames;
+import static org.testng.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.openstack.nova.v2_0.domain.Server;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Tests possible uses of NovaTemplateOptions and NovaTemplateOptions.Builder.*
+ *
+ * @author Adrian Cole
+ */
+@Test(testName = "NovaTemplateOptionsTest")
+public class NovaTemplateOptionsTest {
+
+ public void testAs() {
+ TemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.as(NovaTemplateOptions.class), options);
+ }
+
+ @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "all security groups must be non-empty")
+ public void testsecurityGroupNamesIterableBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames(ImmutableSet.of("group1", ""));
+ }
+
+ @Test
+ public void testsecurityGroupNamesIterable() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames(ImmutableSet.of("group1", "group2"));
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+
+ }
+
+ @Test
+ public void testsecurityGroupNamesIterableStatic() {
+ NovaTemplateOptions options = securityGroupNames(ImmutableSet.of("group1", "group2"));
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+ }
+
+ @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "all security groups must be non-empty")
+ public void testsecurityGroupNamesVarArgsBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames("mygroup", "");
+ }
+
+ @Test
+ public void testsecurityGroupNamesVarArgs() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.securityGroupNames("group1", "group2");
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+
+ }
+
+ @Test
+ public void testDefaultGroupsVarArgsEmpty() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getSecurityGroupNames(), Optional.absent());
+ }
+
+ @Test
+ public void testsecurityGroupNamesVarArgsStatic() {
+ NovaTemplateOptions options = securityGroupNames("group1", "group2");
+ assertEquals(options.getSecurityGroupNames(), Optional.of(ImmutableSet.of("group1", "group2")));
+ }
+
+ @Test
+ public void testautoAssignFloatingIpDefault() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assert !options.shouldAutoAssignFloatingIp();
+ }
+
+ @Test
+ public void testautoAssignFloatingIp() {
+ NovaTemplateOptions options = new NovaTemplateOptions().autoAssignFloatingIp(true);
+ assert options.shouldAutoAssignFloatingIp();
+ }
+
+ @Test
+ public void testautoAssignFloatingIpStatic() {
+ NovaTemplateOptions options = autoAssignFloatingIp(true);
+ assert options.shouldAutoAssignFloatingIp();
+ }
+
+ @Test
+ public void testGenerateKeyPairDefault() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assert !options.shouldGenerateKeyPair();
+ }
+
+ @Test
+ public void testGenerateKeyPair() {
+ NovaTemplateOptions options = new NovaTemplateOptions().generateKeyPair(true);
+ assert options.shouldGenerateKeyPair();
+ }
+
+ @Test
+ public void testGenerateKeyPairStatic() {
+ NovaTemplateOptions options = generateKeyPair(true);
+ assert options.shouldGenerateKeyPair();
+ }
+
+ // superclass tests
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testinstallPrivateKeyBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.installPrivateKey("whompy");
+ }
+
+ @Test
+ public void testinstallPrivateKey() throws IOException {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
+ assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
+ }
+
+ @Test
+ public void testNullinstallPrivateKey() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getPrivateKey(), null);
+ }
+
+ @Test
+ public void testinstallPrivateKeyStatic() throws IOException {
+ NovaTemplateOptions options = installPrivateKey("-----BEGIN RSA PRIVATE KEY-----");
+ assertEquals(options.getPrivateKey(), "-----BEGIN RSA PRIVATE KEY-----");
+ }
+
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testinstallPrivateKeyNPE() {
+ installPrivateKey(null);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testauthorizePublicKeyBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.authorizePublicKey("whompy");
+ }
+
+ @Test
+ public void testauthorizePublicKey() throws IOException {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.authorizePublicKey("ssh-rsa");
+ assertEquals(options.getPublicKey(), "ssh-rsa");
+ }
+
+ @Test
+ public void testNullauthorizePublicKey() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getPublicKey(), null);
+ }
+
+ @Test
+ public void testauthorizePublicKeyStatic() throws IOException {
+ NovaTemplateOptions options = authorizePublicKey("ssh-rsa");
+ assertEquals(options.getPublicKey(), "ssh-rsa");
+ }
+
+ @Test(expectedExceptions = NullPointerException.class)
+ public void testauthorizePublicKeyNPE() {
+ authorizePublicKey(null);
+ }
+
+ @Test
+ public void testUserData() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.userData("test".getBytes());
+ assertEquals(new String(options.getUserData()), "test");
+ }
+
+ @Test
+ public void testDiskConfig() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.diskConfig(Server.DISK_CONFIG_AUTO);
+ assertEquals(options.getDiskConfig(), Server.DISK_CONFIG_AUTO);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testblockOnPortBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.blockOnPort(-1, -1);
+ }
+
+ @Test
+ public void testblockOnPort() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.blockOnPort(22, 30);
+ assertEquals(options.getPort(), 22);
+ assertEquals(options.getSeconds(), 30);
+
+ }
+
+ @Test
+ public void testNullblockOnPort() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getPort(), -1);
+ assertEquals(options.getSeconds(), -1);
+ }
+
+ @Test
+ public void testblockOnPortStatic() {
+ NovaTemplateOptions options = blockOnPort(22, 30);
+ assertEquals(options.getPort(), 22);
+ assertEquals(options.getSeconds(), 30);
+ }
+
+ @Test(expectedExceptions = IllegalArgumentException.class)
+ public void testinboundPortsBadFormat() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.inboundPorts(-1, -1);
+ }
+
+ @Test
+ public void testinboundPorts() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ options.inboundPorts(22, 30);
+ assertEquals(options.getInboundPorts()[0], 22);
+ assertEquals(options.getInboundPorts()[1], 30);
+
+ }
+
+ @Test
+ public void testDefaultOpen22() {
+ NovaTemplateOptions options = new NovaTemplateOptions();
+ assertEquals(options.getInboundPorts()[0], 22);
+ }
+
+ @Test
+ public void testinboundPortsStatic() {
+ NovaTemplateOptions options = inboundPorts(22, 30);
+ assertEquals(options.getInboundPorts()[0], 22);
+ assertEquals(options.getInboundPorts()[1], 30);
+ }
+}
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/AdminActionsApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java
new file mode 100644
index 0000000..32c4617
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiExpectTest.java
@@ -0,0 +1,350 @@
+/*
+ * 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 javax.ws.rs.core.MediaType;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.domain.BackupType;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions;
+import org.jclouds.rest.AuthorizationException;
+import org.jclouds.rest.ResourceNotFoundException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests parsing and guice wiring of AdminActionsApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "AdminActionsApiExpectTest")
+public class AdminActionsApiExpectTest extends BaseNovaApiExpectTest {
+
+ public void testSuspend() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.suspend("1"));
+ }
+
+ public void testSuspendFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.suspend("1"));
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testSuspendFailsNotAuthorized() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "suspend").build(),
+ HttpResponse.builder().statusCode(403).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.suspend("1");
+ }
+
+ public void testResume() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.resume("1"));
+ }
+
+ public void testResumeFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.resume("1"));
+ }
+
+ @Test(expectedExceptions = AuthorizationException.class)
+ public void testResumeFailsNotAuthorized() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "resume").build(),
+ HttpResponse.builder().statusCode(403).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.resume("1");
+ }
+
+ public void testLock() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.lock("1"));
+ }
+
+ public void testLockFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "lock").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.lock("1"));
+ }
+
+ public void testUnlock() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.unlock("1"));
+ }
+
+ public void testUnlockFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "unlock").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.unlock("1"));
+ }
+
+ public void testPause() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.pause("1"));
+ }
+
+ public void testPauseFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "pause").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.pause("1"));
+ }
+
+ public void testUnpause() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.unpause("1"));
+ }
+
+ public void testUnpauseFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "unpause").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.unpause("1"));
+ }
+
+ public void testMigrateServer() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.migrate("1"));
+ }
+
+
+ public void testMigrateServerFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "migrate").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.migrate("1"));
+ }
+
+ public void testResetNetworkOfServer() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.resetNetwork("1"));
+ }
+
+ public void testResetNetworkOfServerFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "resetNetwork").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.resetNetwork("1"));
+ }
+
+ public void testInjectNetworkInfoIntoServer() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.injectNetworkInfo("1"));
+ }
+
+ public void testInjectNetworkInfoIntoServerFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "injectNetworkInfo").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.injectNetworkInfo("1"));
+ }
+
+ public void testBackupServer() {
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action").method("POST")
+ .payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(202).addHeader("Location", "http://172.16.89.149:8774/v2/images/1976b3b3-409a-468d-b16c-a9172c341b46").build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ String imageId = api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other")));
+ assertEquals(imageId, "1976b3b3-409a-468d-b16c-a9172c341b46");
+ }
+
+ @Test(expectedExceptions = ResourceNotFoundException.class)
+ public void testBackupServerFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("POST")
+ .payload(payloadFromStringWithContentType("{\"createBackup\":{\"backup_type\":\"weekly\",\"rotation\":3,\"name\":\"mybackup\",\"metadata\":{\"some\":\"data or other\"}}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ api.createBackup("1", "mybackup", BackupType.WEEKLY, 3, CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("some", "data or other")));
+ }
+
+ public void testLiveMigrateServer() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
+ .payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(202).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.liveMigrate("1", "bighost", true, false));
+ }
+
+ public void testLiveMigrateServerFailsNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/servers/1/action");
+ ServerAdminApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ standardActionRequestBuilderVoidResponse(endpoint, "GONNAOVERWRITE")
+ .payload(payloadFromStringWithContentType("{\"os-migrateLive\":{\"host\":\"bighost\",\"block_migration\":true,\"disk_over_commit\":false}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getServerAdminExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.liveMigrate("1", "bighost", true, false));
+ }
+
+ protected HttpRequest.Builder<?> standardActionRequestBuilderVoidResponse(URI endpoint, String actionName) {
+ return HttpRequest.builder()
+ .method("POST")
+ .addHeader("X-Auth-Token", authToken)
+ .payload(payloadFromStringWithContentType("{\"" + actionName + "\":null}", MediaType.APPLICATION_JSON))
+ .endpoint(endpoint);
+ }
+
+}
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/AdminActionsApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java
new file mode 100644
index 0000000..1d15058
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AdminActionsApiLiveTest.java
@@ -0,0 +1,195 @@
+/*
+ * 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 static org.testng.Assert.fail;
+
+import org.jclouds.http.HttpResponseException;
+import org.jclouds.openstack.nova.v2_0.domain.BackupType;
+import org.jclouds.openstack.nova.v2_0.domain.Image;
+import org.jclouds.openstack.nova.v2_0.domain.Server.Status;
+import org.jclouds.openstack.nova.v2_0.features.ImageApi;
+import org.jclouds.openstack.nova.v2_0.features.ServerApi;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.jclouds.openstack.nova.v2_0.options.CreateBackupOfServerOptions;
+import org.jclouds.openstack.v2_0.features.ExtensionApi;
+import org.testng.SkipException;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterMethod;
+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;
+
+/**
+ * Tests behavior of HostAdministrationApi
+ *
+ * TODO test migration methods
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "live", testName = "AdminActionsApiLiveTest", singleThreaded = true)
+public class AdminActionsApiLiveTest extends BaseNovaApiLiveTest {
+ private ImageApi imageApi;
+ private ServerApi serverApi;
+ private ExtensionApi extensionApi;
+ private Optional<? extends ServerAdminApi> apiOption;
+ private String zone;
+
+ private String testServerId;
+ private String backupImageId;
+
+ @BeforeClass(groups = {"integration", "live"})
+ @Override
+ public void setup() {
+ super.setup();
+ zone = Iterables.getLast(api.getConfiguredZones(), "nova");
+ serverApi = api.getServerApiForZone(zone);
+ extensionApi = api.getExtensionApiForZone(zone);
+ imageApi = api.getImageApiForZone(zone);
+ apiOption = api.getServerAdminExtensionForZone(zone);
+ if (apiOption.isPresent()) {
+ testServerId = createServerInZone(zone).getId();
+ }
+ }
+
+ @AfterClass(groups = { "integration", "live" })
+ @Override
+ protected void tearDown() {
+ if (apiOption.isPresent()) {
+ if (testServerId != null) {
+ assertTrue(api.getServerApiForZone(zone).delete(testServerId));
+ }
+ if (backupImageId != null) {
+ imageApi.delete(backupImageId);
+ }
+ }
+ super.tearDown();
+ }
+
+ protected void skipOnAdminExtensionAbsent() {
+ if (!apiOption.isPresent()) {
+ throw new SkipException("Test depends on ServerAdminApi extension");
+ }
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void ensureServerIsActiveAgain() {
+ if (apiOption.isPresent())
+ blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
+ }
+
+ public void testSuspendAndResume() {
+ skipOnAdminExtensionAbsent();
+ ServerAdminApi api = apiOption.get();
+
+ // Suspend-resume
+ try {
+ api.resume(testServerId);
+ fail("Resumed an active server!");
+ } catch (HttpResponseException e) {
+ }
+ assertTrue(api.suspend(testServerId));
+ blockUntilServerInState(testServerId, serverApi, Status.SUSPENDED);
+ try {
+ api.suspend(testServerId);
+ fail("Suspended an already suspended server!");
+ } catch (HttpResponseException e) {
+ }
+ assertTrue(api.resume(testServerId));
+ blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
+ try {
+ api.resume(testServerId);
+ fail("Resumed an already resumed server!");
+ } catch (HttpResponseException e) {
+ }
+
+ }
+
+ public void testLockAndUnlock() {
+ skipOnAdminExtensionAbsent();
+ ServerAdminApi api = apiOption.get();
+
+ // TODO should we be able to double-lock (as it were)
+ assertTrue(api.unlock(testServerId));
+ assertTrue(api.unlock(testServerId));
+ assertTrue(api.lock(testServerId));
+ assertTrue(api.lock(testServerId));
+ assertTrue(api.unlock(testServerId));
+ assertTrue(api.unlock(testServerId));
+
+ }
+
+ public void testResetNetworkAndInjectNetworkInfo() {
+ skipOnAdminExtensionAbsent();
+ ServerAdminApi api = apiOption.get();
+ assertTrue(api.resetNetwork(testServerId));
+ assertTrue(api.injectNetworkInfo(testServerId));
+ }
+
+ @Test
+ public void testPauseAndUnpause() {
+ skipOnAdminExtensionAbsent();
+ ServerAdminApi api = apiOption.get();
+
+ // Unlock and lock (double-checking error contitions too)
+ try {
+ api.unpause(testServerId);
+ fail("Unpaused active server!");
+ } catch (HttpResponseException e) {
+ }
+ assertTrue(api.pause(testServerId));
+ blockUntilServerInState(testServerId, serverApi, Status.PAUSED);
+ try {
+ api.pause(testServerId);
+ fail("paused a paused server!");
+ } catch (HttpResponseException e) {
+ }
+ assertTrue(api.unpause(testServerId));
+ blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
+ try {
+ api.unpause(testServerId);
+ fail("Unpaused a server we just unpaused!");
+ } catch (HttpResponseException e) {
+ }
+
+ }
+
+ @Test
+ public void testCreateBackupOfServer() throws InterruptedException {
+ skipOnAdminExtensionAbsent();
+ backupImageId = apiOption.get().createBackup(testServerId, "jclouds-test-backup", BackupType.DAILY, 0,
+ CreateBackupOfServerOptions.Builder.metadata(ImmutableMap.of("test", "metadata")));
+
+ assertNotNull(backupImageId);
+
+ // If we don't have extended task status, we'll have to wait here!
+ if (extensionApi.get("OS-EXT-STS") == null) {
+ Thread.sleep(30000);
+ }
+
+ blockUntilServerInState(testServerId, serverApi, Status.ACTIVE);
+
+ Image backupImage = imageApi.get(backupImageId);
+ assertEquals(backupImage.getId(), backupImageId);
+ }
+}
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/AvailabilityZoneApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApiExpectTest.java
new file mode 100644
index 0000000..f033a1b
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZoneApiExpectTest.java
@@ -0,0 +1,64 @@
+/**
+ * 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.nova.v2_0.extensions;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.FluentIterable;
+import com.google.common.collect.ImmutableSet;
+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.domain.zonescoped.AvailabilityZone;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * @author Inbar Stolberg
+ */
+@Test(groups = "unit", testName = "AvailabilityZoneApiExpectTest")
+public class AvailabilityZoneApiExpectTest extends BaseNovaApiExpectTest {
+
+ public void testLAvailabilityZonesList() throws Exception {
+ HttpRequest list = HttpRequest
+ .builder()
+ .method("GET")
+ .endpoint("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/os-availability-zone")
+ .addHeader("Accept", "application/json")
+ .addHeader("X-Auth-Token", authToken).build();
+
+ HttpResponse listResponse = HttpResponse.builder().statusCode(200)
+ .payload(payloadFromResource("/listAvailabilityZones.json")).build();
+
+ NovaApi availabilityZonesApi = requestsSendResponses(keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse, list, listResponse);
+
+ assertEquals(availabilityZonesApi.getConfiguredZones(), ImmutableSet.of("az-1.region-a.geo-1", "az-2.region-a.geo-1", "az-3.region-a.geo-1"));
+
+ FluentIterable<? extends AvailabilityZone> zones = availabilityZonesApi.getAvailabilityZoneApi("az-1.region-a.geo-1").list();
+
+ Optional<? extends AvailabilityZone> zone = zones.first();
+
+ assertTrue(zone.isPresent(), "Couldn't find zone");
+ assertTrue(zone.get().getName().equals("nova"), "Expected zone name to be nova but it was: " + zone.get().getName());
+ assertTrue(zone.get().getState().available(), "Zone: "+ zone.get().getName() + " is not available.");
+ }
+}
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/AvailabilityZonesApiLiveTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZonesApiLiveTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZonesApiLiveTest.java
new file mode 100644
index 0000000..a7ad44f
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/AvailabilityZonesApiLiveTest.java
@@ -0,0 +1,45 @@
+/**
+ * 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.nova.v2_0.extensions;
+
+import com.google.common.collect.FluentIterable;
+import org.jclouds.openstack.nova.v2_0.domain.zonescoped.AvailabilityZone;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiLiveTest;
+import org.testng.annotations.Test;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * @author inbar stolberg
+ */
+@Test(groups = "live", testName = "AvailabilityZonesApiLiveTest")
+public class AvailabilityZonesApiLiveTest extends BaseNovaApiLiveTest {
+
+ @Test
+ public void testListAvailabilityZones() throws Exception {
+
+ AvailabilityZoneAPI availabilityZoneApi = api.getAvailabilityZoneApi("RegionOne");
+ FluentIterable<? extends AvailabilityZone> zones = availabilityZoneApi.list();
+
+ for (AvailabilityZone zone : zones) {
+ assertNotNull(zone.getName());
+ assertTrue(zone.getState().available(), "zone: " + zone.getName() + " is not available.");
+ }
+ }
+}
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/FlavorExtraSpecsApiExpectTest.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiExpectTest.java b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiExpectTest.java
new file mode 100644
index 0000000..b04b5f2
--- /dev/null
+++ b/dependencies/jclouds/openstack-nova/1.7.1-stratos/src/test/java/org/jclouds/openstack/nova/v2_0/extensions/FlavorExtraSpecsApiExpectTest.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.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.http.HttpResponse;
+import org.jclouds.openstack.nova.v2_0.internal.BaseNovaApiExpectTest;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableMap;
+
+/**
+ * Tests guice wiring and parsing of FlavorExtraSpecsApi
+ *
+ * @author Adam Lowe
+ */
+@Test(groups = "unit", testName = "FlavorExtraSpecsApiExpectTest")
+public class FlavorExtraSpecsApiExpectTest extends BaseNovaApiExpectTest {
+
+ public void testGetAllExtraSpecs() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/9/os-extra_specs");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromResource("/volume_type_extra_specs.json")).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.getMetadata("9"), ImmutableMap.of("test", "value1"));
+ }
+
+ public void testGetAllExtraSpecsFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/9/os-extra_specs");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.getMetadata("9").isEmpty());
+ }
+
+ public void testSetAllExtraSpecs() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/9/os-extra_specs");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint)
+ .method("POST")
+ .payload(payloadFromStringWithContentType("{\"extra_specs\":{\"test1\":\"somevalue\"}}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.updateMetadata("9", ImmutableMap.of("test1", "somevalue")));
+ }
+
+ public void testSetExtraSpec() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/5/os-extra_specs/test1");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint)
+ .method("PUT")
+ .payload(payloadFromStringWithContentType("{\"test1\":\"somevalue\"}", MediaType.APPLICATION_JSON)).build(),
+ HttpResponse.builder().statusCode(200).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.updateMetadataEntry("5", "test1", "somevalue"));
+ }
+
+ public void testGetExtraSpec() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/5/os-extra_specs/test1");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(200).payload(payloadFromStringWithContentType("{\"test1\":\"another value\"}", MediaType.APPLICATION_JSON)).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertEquals(api.getMetadataKey("5", "test1"), "another value");
+ }
+
+ public void testGetExtraSpecFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/5/os-extra_specs/test1");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertNull(api.getMetadataKey("5", "test1"));
+ }
+
+ public void testDeleteExtraSpec() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/5/os-extra_specs/test1");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(200).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertTrue(api.deleteMetadataKey("5", "test1"));
+ }
+
+ public void testDeleteExtraSpecFailNotFound() {
+ URI endpoint = URI.create("https://az-1.region-a.geo-1.compute.hpcloudsvc.com/v1.1/3456/flavors/5/os-extra_specs/test1");
+ FlavorExtraSpecsApi api = requestsSendResponses(
+ keystoneAuthWithUsernameAndPasswordAndTenantName,
+ responseWithKeystoneAccess, extensionsOfNovaRequest, extensionsOfNovaResponse,
+ authenticatedGET().endpoint(endpoint).method("DELETE").build(),
+ HttpResponse.builder().statusCode(404).build()
+ ).getFlavorExtraSpecsExtensionForZone("az-1.region-a.geo-1").get();
+
+ assertFalse(api.deleteMetadataKey("5", "test1"));
+ }
+
+}