From 318e110b5e6549fc5f563eaa0e9dbc97c617c749 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Tue, 29 Mar 2016 15:55:26 +0100 Subject: [PATCH 1/8] converged infrastructure rework reflects the Azure Resource Manager template model --- pom.xml | 2 +- .../dasein/cloud/test/DaseinTestManager.java | 8 - .../dasein/cloud/test/StatefulTestSuite.java | 4 - .../dasein/cloud/test/StatelessTestSuite.java | 6 +- .../org/dasein/cloud/test/ci/CIResources.java | 406 ++++++----------- .../org/dasein/cloud/test/ci/CITestSuite.java | 5 +- .../dasein/cloud/test/ci/StatefulCITests.java | 196 +++------ .../ci/StatefulHttpLoadBalancerTests.java | 408 ------------------ .../cloud/test/ci/StatefulTopologyTests.java | 238 ---------- .../cloud/test/ci/StatelessCITests.java | 267 ++++++++++++ .../ci/StatelessHttpLoadBalancerTests.java | 90 ---- .../cloud/test/ci/StatelessTopologyTests.java | 307 ------------- .../cloud/test/compute/ComputeResources.java | 9 +- .../cloud/test/compute/ComputeTestSuite.java | 1 - .../test/identity/IdentityResources.java | 14 +- .../cloud/test/network/NetworkResources.java | 4 +- .../test/platform/PlatformResources.java | 2 +- .../storage/StatefulObjectStoreTests.java | 4 +- .../parameterContent.json | 17 + .../templateContent.json | 218 ++++++++++ 20 files changed, 712 insertions(+), 1494 deletions(-) delete mode 100644 src/main/java/org/dasein/cloud/test/ci/StatefulHttpLoadBalancerTests.java delete mode 100644 src/main/java/org/dasein/cloud/test/ci/StatefulTopologyTests.java create mode 100644 src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java delete mode 100644 src/main/java/org/dasein/cloud/test/ci/StatelessHttpLoadBalancerTests.java delete mode 100644 src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java create mode 100644 src/main/resources/convergedInfrastructure/parameterContent.json create mode 100644 src/main/resources/convergedInfrastructure/templateContent.json diff --git a/pom.xml b/pom.xml index 6070068..9da5f14 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ org.dasein dasein-cloud-core - 0.9.0 + 0.9.5-SNAPSHOT org.dasein diff --git a/src/main/java/org/dasein/cloud/test/DaseinTestManager.java b/src/main/java/org/dasein/cloud/test/DaseinTestManager.java index 7b1947c..d7022e8 100644 --- a/src/main/java/org/dasein/cloud/test/DaseinTestManager.java +++ b/src/main/java/org/dasein/cloud/test/DaseinTestManager.java @@ -622,18 +622,10 @@ else if( support.getCapabilities().supportsFirewallCreation(true) ) { return (platformResources == null ? null : platformResources.getTestTopicId(label, provisionIfNull)); } - public @Nullable String getTestTopologyId(@Nonnull String label, boolean provisionIfNull) { - return (ciResources == null ? null : ciResources.getTestTopologyId(label, provisionIfNull)); - } - public @Nullable String getTestCIId(@Nonnull String label, boolean provisionIfNull) { return (ciResources == null ? null : ciResources.getTestCIId(label, provisionIfNull)); } - public @Nullable String getTestHttpLoadBalancerId(@Nonnull String label, boolean provisionIfNull) { - return (ciResources == null ? null : ciResources.getTestConvergedHttpLoadBalancerId(label, provisionIfNull)); - } - public @Nullable String getTestUserId(@Nonnull String label, boolean provisionIfNull, @Nullable String preferredGroupId) { return (identityResources == null ? null : identityResources.getTestUserId(label, provisionIfNull, preferredGroupId)); } diff --git a/src/main/java/org/dasein/cloud/test/StatefulTestSuite.java b/src/main/java/org/dasein/cloud/test/StatefulTestSuite.java index 5d93674..8af871a 100644 --- a/src/main/java/org/dasein/cloud/test/StatefulTestSuite.java +++ b/src/main/java/org/dasein/cloud/test/StatefulTestSuite.java @@ -20,8 +20,6 @@ package org.dasein.cloud.test; import org.dasein.cloud.test.ci.StatefulCITests; -import org.dasein.cloud.test.ci.StatefulHttpLoadBalancerTests; -import org.dasein.cloud.test.ci.StatefulTopologyTests; import org.dasein.cloud.test.compute.StatefulImageTests; import org.dasein.cloud.test.compute.StatefulSnapshotTests; import org.dasein.cloud.test.compute.StatefulVMTests; @@ -70,9 +68,7 @@ StatefulDNSTests.class, StatefulCDNTests.class, StatefulPushNotificationTests.class, - StatefulTopologyTests.class, StatefulCITests.class, - StatefulHttpLoadBalancerTests.class, StatefulVpnTests.class }) public class StatefulTestSuite { diff --git a/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java b/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java index e0fd805..9f3a305 100644 --- a/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java +++ b/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java @@ -19,6 +19,7 @@ package org.dasein.cloud.test; +import org.dasein.cloud.test.ci.StatelessCITests; import org.dasein.cloud.test.cloud.StatelessAuthenticationTests; import org.dasein.cloud.test.cloud.StatelessDCTests; import org.dasein.cloud.test.compute.StatelessAffinityGroupTests; @@ -27,8 +28,6 @@ import org.dasein.cloud.test.compute.StatelessVMMonitoringTests; import org.dasein.cloud.test.compute.StatelessVMTests; import org.dasein.cloud.test.compute.StatelessVolumeTests; -import org.dasein.cloud.test.ci.StatelessHttpLoadBalancerTests; -import org.dasein.cloud.test.ci.StatelessTopologyTests; import org.dasein.cloud.test.identity.StatelessIAMTests; import org.dasein.cloud.test.identity.StatelessKeypairTests; import org.dasein.cloud.test.network.StatelessDNSTests; @@ -79,8 +78,7 @@ StatelessMonitoringTests.class, StatelessNotificationsTests.class, StatelessVMMonitoringTests.class, - StatelessTopologyTests.class, - StatelessHttpLoadBalancerTests.class + StatelessCITests.class }) public class StatelessTestSuite { } diff --git a/src/main/java/org/dasein/cloud/test/ci/CIResources.java b/src/main/java/org/dasein/cloud/test/ci/CIResources.java index d7bc85a..e11e3a9 100644 --- a/src/main/java/org/dasein/cloud/test/ci/CIResources.java +++ b/src/main/java/org/dasein/cloud/test/ci/CIResources.java @@ -20,27 +20,27 @@ package org.dasein.cloud.test.ci; import org.apache.log4j.Logger; +import org.dasein.cloud.CloudException; import org.dasein.cloud.CloudProvider; -import org.dasein.cloud.ci.CIProvisionOptions; -import org.dasein.cloud.ci.CIServices; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancer; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancerSupport; +import org.dasein.cloud.InternalException; +import org.dasein.cloud.Requirement; import org.dasein.cloud.ci.ConvergedInfrastructure; +import org.dasein.cloud.ci.ConvergedInfrastructureProvisionOptions; +import org.dasein.cloud.ci.ConvergedInfrastructureServices; import org.dasein.cloud.ci.ConvergedInfrastructureState; import org.dasein.cloud.ci.ConvergedInfrastructureSupport; -import org.dasein.cloud.ci.Topology; -import org.dasein.cloud.ci.TopologyProvisionOptions; -import org.dasein.cloud.ci.TopologyState; -import org.dasein.cloud.ci.TopologySupport; +import org.dasein.cloud.dc.DataCenterServices; +import org.dasein.cloud.dc.ResourcePool; import org.dasein.cloud.test.DaseinTestManager; import org.dasein.cloud.test.compute.ComputeResources; -import org.dasein.cloud.test.network.NetworkResources; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.ArrayList; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Random; @@ -57,42 +57,63 @@ public class CIResources { private CloudProvider provider; private final HashMap testInfrastructures = new HashMap(); - private final HashMap testTopologies = new HashMap(); - private final HashMap testHttpLoadBalancers = new HashMap(); + + public String getTestTemplateContent() { + if (testTemplateContent.equals("")) { + populateTemplateContent(); + } + return testTemplateContent; + } + + public String getTestParametersContent() { + if (testParametersContent.equals("")) { + populateTemplateContent(); + } + return testParametersContent; + } + + public void populateTemplateContent() { + try { + String templateContentFile = "/convergedInfrastructure/templateContent.json"; + String parameterContentFile = "/convergedInfrastructure/parameterContent.json"; + InputStream input = StatelessCITests.class.getResourceAsStream(templateContentFile); + BufferedReader templateReader = new BufferedReader(new InputStreamReader(input)); + StringBuilder templateJson = new StringBuilder(); + String templateLine; + while ((templateLine = templateReader.readLine()) != null) { + templateJson.append(templateLine); + templateJson.append("\n"); + } + testTemplateContent = templateJson.toString(); + + InputStream input2 = StatelessCITests.class.getResourceAsStream(parameterContentFile); + BufferedReader parameterReader = new BufferedReader(new InputStreamReader(input2)); + StringBuilder parameterJson = new StringBuilder(); + String parameterLine; + while ((parameterLine = parameterReader.readLine()) != null) { + parameterJson.append(parameterLine); + parameterJson.append("\n"); + } + testParametersContent = parameterJson.toString(); + } + catch ( IOException e ) { + logger.warn("Unable to read files for template content: "+e.getMessage()); + } + + } + + private String testTemplateContent = ""; + private String testParametersContent = ""; public CIResources(@Nonnull CloudProvider provider) { this.provider = provider; } public int close() { - CIServices ciServices = provider.getCIServices(); + ConvergedInfrastructureServices ciServices = provider.getConvergedInfrastructureServices(); int count = 0; if( ciServices != null ) { - ConvergedHttpLoadBalancerSupport hlbSupport = ciServices.getConvergedHttpLoadBalancerSupport(); - - if( hlbSupport != null ) { - List hlbIds = new ArrayList(); - for( Map.Entry entry : testHttpLoadBalancers.entrySet() ) { - if ( !entry.getKey().equals(DaseinTestManager.STATELESS) ) { - try { - ConvergedHttpLoadBalancer hlb = hlbSupport.getConvergedHttpLoadBalancer(entry.getValue()); - - if( hlb != null ) { - hlbSupport.removeConvergedHttpLoadBalancers(entry.getValue()); - count++; - } - else { - count++; - } - } - catch( Throwable t ) { - logger.warn("Failed to de-provision test ConvergedHttpLoadBlancer " + entry.getValue() + ": " + t.getMessage()); - } - } - } - } - ConvergedInfrastructureSupport ciSupport = ciServices.getConvergedInfrastructureSupport(); if( ciSupport != null ) { @@ -115,191 +136,12 @@ public int close() { } } } - - TopologySupport tSupport = ciServices.getTopologySupport(); - - if( tSupport != null ) { - List topologyIds = new ArrayList(); - for( Map.Entry entry : testTopologies.entrySet() ) { - if ( !entry.getKey().equals(DaseinTestManager.STATELESS) ) { - topologyIds.add(entry.getValue()); - count++; - } - } - try { - tSupport.removeTopologies(topologyIds.toArray(new String[topologyIds.size()])); - } - catch( Throwable e ) { - logger.warn("Failed to de-provision test topology " + e.getMessage()); - } - } } return count; } - public @Nullable String getTestTopologyId(@Nonnull String label, boolean provisionIfNull) { - String id = testTopologies.get(label); - if (id == null) { - if ( label.equals(DaseinTestManager.STATELESS) ) { - for (Map.Entry entry : testTopologies.entrySet()) { - if ( !entry.getKey().startsWith(DaseinTestManager.REMOVED) ) { - id = entry.getValue(); - - if ( id != null ) { - return id; - } - } - } - id = findStatelessTopology(); - } - } - - - if( id != null ) { - return id; - } - if( !provisionIfNull ) { - return null; - } - CIServices services = provider.getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - try { - NetworkResources networkResources = DaseinTestManager.getNetworkResources(); - String testNetworkId = networkResources.getTestVLANId(DaseinTestManager.STATELESS, false, null); - ComputeResources computeResources = DaseinTestManager.getComputeResources(); - String testImageId = computeResources.getTestImageId(DaseinTestManager.STATELESS, false); - String testProductId = computeResources.getTestVMProductId(); - - TopologyProvisionOptions withTopologyOptions = TopologyProvisionOptions.getInstance("dsn-topology"+String.valueOf(random.nextInt(10000)), "description", testProductId, true); - - withTopologyOptions = withTopologyOptions.withAutomaticRestart(false); - withTopologyOptions = withTopologyOptions.withMaintenanceOption(TopologyProvisionOptions.MaintenanceOption.TERMINATE_VM_INSTANCE); - - withTopologyOptions = withTopologyOptions.withNetworkInterface(testNetworkId, null, true); // ,accessConfigs); - withTopologyOptions = withTopologyOptions.withAttachedDisk("dsn-topology-disk"+String.valueOf(random.nextInt(1000)), TopologyProvisionOptions.DiskType.STANDARD_PERSISTENT_DISK, testImageId, true, true); - boolean result = support.createTopology(withTopologyOptions); - if (result) { - id = withTopologyOptions.getProductName(); - testTopologies.put(DaseinTestManager.STATEFUL, id); - return id; - } - } - catch( Throwable ignore ) { - return null; - } - } - } - return null; - } - - public @Nullable String getTestConvergedHttpLoadBalancerId(@Nonnull String label, boolean provisionIfNull) { - String id = testHttpLoadBalancers.get(label); - if (id == null) { - if ( label.equals(DaseinTestManager.STATELESS) ) { - for (Map.Entry entry : testHttpLoadBalancers.entrySet()) { - if ( !entry.getKey().startsWith(DaseinTestManager.REMOVED) ) { - id = entry.getValue(); - - if ( id != null ) { - return id; - } - } - } - id = findStatelessConvergedHttpLoadBalancer(); - } - } - - - if( id != null ) { - return id; - } - if( !provisionIfNull ) { - return null; - } - CIServices services = provider.getCIServices(); - - if( services != null ) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - ConvergedInfrastructureSupport ciSupport = services.getConvergedInfrastructureSupport(); - - if( support != null ) { - try { - String ciId = getTestCIId(DaseinTestManager.STATELESS, true); - ConvergedInfrastructure ci = ciSupport.getConvergedInfrastructure(ciId); - String ciSource = ci.getProviderConvergedInfrastructureId(); - //horrible hack to try keep tests generic but work for google - if (provider.getCloudName().equals("GCE")) { - ciSource = ci.getTag("instanceGroupLink").toString(); - } - Map pathMap = new HashMap(); - String defaultBackend = "test-backend-1"+random.nextInt(1000); - pathMap.put("/*", defaultBackend); - String healthCheck1 = "test-health-check"+random.nextInt(1000); - String targetProxy1 = "target-proxy-"+random.nextInt(1000); - ConvergedHttpLoadBalancer withExperimentalConvergedHttpLoadbalancerOptions = ConvergedHttpLoadBalancer - .getInstance("test-http-load-balancer" + random.nextInt(1000), "test-http-load-balancer-description", defaultBackend) - .withHealthCheck(healthCheck1, healthCheck1 + "-description", null, 80, "/", 5, 5, 2, 2) //ONLY ONE ALLOWED - .withBackendService(defaultBackend, defaultBackend + "-description", 80, "http", "HTTP", new String[]{healthCheck1}, new String[]{ciSource}, 30) - .withUrlSet("url-map-1", "url-map-description", "*", pathMap) - .withTargetHttpProxy(targetProxy1, targetProxy1 + "-description") - .withForwardingRule(targetProxy1 + "-fr", targetProxy1 + "-fr-description", null, "TCP", "80", targetProxy1); - - id = support.createConvergedHttpLoadBalancer(withExperimentalConvergedHttpLoadbalancerOptions); - if (id != null) { - if (!label.equals(DaseinTestManager.REMOVED)) { - testHttpLoadBalancers.put(DaseinTestManager.STATEFUL, id); - } - return id; - } - } - catch( Throwable ignore ) { - return null; - } - } - } - return null; - } - - private @Nullable String findStatelessTopology() { - CIServices services = provider.getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - try { - if( support != null && support.isSubscribed() ) { - Topology defaultTopology = null; - - for( Topology t : support.listTopologies(null) ) { - if( t.getCurrentState().equals(TopologyState.ACTIVE) ) { - defaultTopology = t; - break; - } - if( defaultTopology == null ) { - defaultTopology = t; - } - } - if( defaultTopology != null ) { - String id = defaultTopology.getProviderTopologyId(); - - testTopologies.put(DaseinTestManager.STATELESS, id); - return id; - } - } - } - catch( Throwable ignore ) { - // ignore - } - } - return null; - } - private @Nullable String findStatelessCI() { - CIServices services = provider.getCIServices(); + ConvergedInfrastructureServices services = provider.getConvergedInfrastructureServices(); if( services != null ) { ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); @@ -309,7 +151,7 @@ public int close() { ConvergedInfrastructure defaultCI = null; for( ConvergedInfrastructure ci : support.listConvergedInfrastructures(null) ) { - if( ci.getCurrentState().equals(ConvergedInfrastructureState.RUNNING) ) { + if( ci.getCiState().equals(ConvergedInfrastructureState.READY) ) { defaultCI = ci; break; } @@ -318,7 +160,7 @@ public int close() { } } if( defaultCI != null ) { - String id = defaultCI.getProviderConvergedInfrastructureId(); + String id = defaultCI.getProviderCIId(); testInfrastructures.put(DaseinTestManager.STATELESS, id); return id; @@ -332,37 +174,11 @@ public int close() { return null; } - private @Nullable String findStatelessConvergedHttpLoadBalancer() { - CIServices services = provider.getCIServices(); - - if( services != null ) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - - try { - if( support != null && support.isSubscribed() ) { - String defaultHLB = null; - - for( String hlb : support.listConvergedHttpLoadBalancers() ) { - if( defaultHLB == null ) { - defaultHLB = hlb; - } - } - if( defaultHLB != null ) { - testHttpLoadBalancers.put(DaseinTestManager.STATELESS, defaultHLB); - return defaultHLB; - } - } - } - catch( Throwable ignore ) { - // ignore - } - } - return null; - } - - public @Nullable String getTestCIId(@Nonnull String label, boolean provisionIfNull) { + public + @Nullable + String getTestCIId(@Nonnull String label, boolean provisionIfNull) { String id = testInfrastructures.get(label); - if (id == null) { + if ( id == null ) { if ( label.equals(DaseinTestManager.STATELESS) ) { for (Map.Entry entry : testInfrastructures.entrySet()) { if ( !entry.getKey().startsWith(DaseinTestManager.REMOVED) ) { @@ -378,30 +194,52 @@ public int close() { } - if( id != null ) { + if ( id != null ) { return id; } - if( !provisionIfNull ) { + if ( !provisionIfNull ) { return null; } - CIServices services = provider.getCIServices(); + ConvergedInfrastructureServices services = provider.getConvergedInfrastructureServices(); - if( services != null ) { + if ( services != null ) { ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); - if( support != null ) { + if ( support != null ) { try { - String testTopologyId = getTestTopologyId(DaseinTestManager.STATELESS, true); - String testDataCenterId = DaseinTestManager.getDefaultDataCenterId(true); - CIProvisionOptions options = CIProvisionOptions.getInstance("dsn-ci", "test-description", testDataCenterId, 1, testTopologyId); - ConvergedInfrastructure ci = support.provision(options); - if (ci != null) { - id = ci.getName(); - testInfrastructures.put(DaseinTestManager.STATEFUL, id); - return id; + String testResourcePoolId = null; + DataCenterServices dc = provider.getDataCenterServices(); + if ( dc.getCapabilities().supportsResourcePools() ) { + if ( support.getCapabilities().identifyResourcePoolLaunchRequirement().equals(Requirement.REQUIRED) ) { + ComputeResources computeResources = DaseinTestManager.getComputeResources(); + Iterable testRPList = dc.listResourcePools(computeResources.getTestDataCenterId(true)); + if ( testRPList != null && testRPList.iterator().hasNext() ) { + ResourcePool rp = testRPList.iterator().next(); + testResourcePoolId = rp.getProvideResourcePoolId(); + } + if ( testResourcePoolId == null ) { + return null; + } + } } - } - catch( Throwable ignore ) { + boolean supportsTemplateContent = false; + try { + Requirement templateContentLaunchRequirement = support.getCapabilities().identifyTemplateContentLaunchRequirement(); + supportsTemplateContent = !templateContentLaunchRequirement.equals(Requirement.NONE); + if ( supportsTemplateContent ) { + populateTemplateContent(); + } else { + //todo get a test template/parameters id for clouds that don't support content + } + } catch ( Exception e ) { + } + ConvergedInfrastructureProvisionOptions options = ConvergedInfrastructureProvisionOptions.getInstance("dsntest-ci" + label, + testResourcePoolId, null, testTemplateContent, testParametersContent, supportsTemplateContent); + String ciId = provisionConvergedInfrastructure(options, label); + if ( ciId != null ) { + return ciId; + } + } catch ( Throwable ignore ) { return null; } } @@ -420,23 +258,29 @@ public int report() { count += testInfrastructures.size(); DaseinTestManager.out(logger, null, "---> Infrastructures", testInfrastructures.size() + " " + testInfrastructures); } - testTopologies.remove(DaseinTestManager.STATELESS); - if( !testTopologies.isEmpty() ) { - if( !header ) { - logger.info("Provisioned CI Resources:"); - header = true; - } - count += testTopologies.size(); - DaseinTestManager.out(logger, null, "---> Topologies", testTopologies.size() + " " + testTopologies); - } - testHttpLoadBalancers.remove(DaseinTestManager.STATELESS); - if( !testHttpLoadBalancers.isEmpty() ) { - if( !header ) { - logger.info("Provisioned CI Resources:"); + return count; + } + + public String provisionConvergedInfrastructure(ConvergedInfrastructureProvisionOptions options, String label) throws CloudException, InternalException { + String id = null; + ConvergedInfrastructureServices services = provider.getConvergedInfrastructureServices(); + + if( services != null ) { + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + + if ( support != null ) { + ConvergedInfrastructure ci = support.provision(options); + if ( ci != null ) { + id = ci.getProviderCIId(); + synchronized (testInfrastructures) { + while (testInfrastructures.containsKey(label)) { + label = label + random.nextInt(9); + } + testInfrastructures.put(label, id); + } + } } - count += testHttpLoadBalancers.size(); - DaseinTestManager.out(logger, null, "---> ConvergedHttpLoadBalancers", testHttpLoadBalancers.size() + " " + testHttpLoadBalancers); } - return count; + return id; } } diff --git a/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java b/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java index adb163c..44bedb3 100644 --- a/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java +++ b/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java @@ -31,11 +31,8 @@ */ @RunWith(Suite.class) @Suite.SuiteClasses({ - StatelessTopologyTests.class, - StatefulTopologyTests.class, StatefulCITests.class, - StatelessHttpLoadBalancerTests.class, - StatefulHttpLoadBalancerTests.class + StatelessCITests.class }) public class CITestSuite { @BeforeClass diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java index ffb7b68..da23390 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java @@ -21,11 +21,12 @@ import org.dasein.cloud.CloudException; import org.dasein.cloud.InternalException; -import org.dasein.cloud.ResourceStatus; -import org.dasein.cloud.ci.CIProvisionOptions; -import org.dasein.cloud.ci.CIServices; -import org.dasein.cloud.ci.ConvergedInfrastructure; +import org.dasein.cloud.Requirement; +import org.dasein.cloud.ci.ConvergedInfrastructureProvisionOptions; +import org.dasein.cloud.ci.ConvergedInfrastructureServices; import org.dasein.cloud.ci.ConvergedInfrastructureSupport; +import org.dasein.cloud.dc.DataCenterServices; +import org.dasein.cloud.dc.ResourcePool; import org.dasein.cloud.test.DaseinTestManager; import org.junit.After; import org.junit.AfterClass; @@ -35,7 +36,8 @@ import org.junit.Test; import org.junit.rules.TestName; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; /** @@ -43,6 +45,7 @@ */ public class StatefulCITests { static private DaseinTestManager tm; + private String testResourcePoolId = null; @BeforeClass static public void configure() { @@ -59,9 +62,8 @@ static public void cleanUp() { @Rule public final TestName name = new TestName(); - private String testTopologyId; private String testCIId; - private String testDataCenterId; + private ConvergedInfrastructureProvisionOptions options; public StatefulCITests() { } @@ -69,54 +71,65 @@ public StatefulCITests() { } public void before() { tm.begin(name.getMethodName()); assumeTrue(!tm.isTestSkipped()); - testTopologyId = tm.getTestTopologyId(DaseinTestManager.STATELESS, true); - testDataCenterId = tm.getTestDataCenterId(true); - - if (name.getMethodName().startsWith("listConvergedInfrastructures") || - name.getMethodName().startsWith("listVLANs") || - name.getMethodName().startsWith("listVirtualMachines") || - name.getMethodName().startsWith("listConvergedInfrastructureStatus") || - name.getMethodName().startsWith("deleteCIFromTopology")) { - try { - CIProvisionOptions options = CIProvisionOptions.getInstance(name.getMethodName().toLowerCase(), "test-description", testDataCenterId, 1, testTopologyId); - if( tm.getProvider().getCIServices() != null && tm.getProvider().getCIServices().getConvergedInfrastructureSupport() != null ) { - ConvergedInfrastructure ci = tm.getProvider().getCIServices().getConvergedInfrastructureSupport().provision(options); - testCIId = ci.getName(); + + try { + testResourcePoolId = null; + if (tm.getProvider().getDataCenterServices().getCapabilities().supportsResourcePools()) { + DataCenterServices dc = tm.getProvider().getDataCenterServices(); + + Iterable testRPList = dc.listResourcePools(tm.getDefaultDataCenterId(true)); + if (testRPList != null && testRPList.iterator().hasNext()) { + ResourcePool rp = testRPList.iterator().next(); + testResourcePoolId = rp.getProvideResourcePoolId(); } - } catch ( Exception e ) { } - } - } - @After - public void after() { - tm.end(); - try { - if (name.getMethodName().startsWith("listConvergedInfrastructures") || - name.getMethodName().startsWith("listVLANs") || - name.getMethodName().startsWith("listConvergedInfrastructureStatus") || - name.getMethodName().startsWith("listVirtualMachines")) { - if( tm.getProvider().getCIServices() != null && tm.getProvider().getCIServices().getConvergedInfrastructureSupport() != null ) { - tm.getProvider().getCIServices().getConvergedInfrastructureSupport().terminate(name.getMethodName().toLowerCase(), "test over"); + String testTemplateContent = "", testParametersContent = ""; + boolean supportsTemplateContent = false; + CIResources ciResources = DaseinTestManager.getCiResources(); + testTemplateContent = ciResources.getTestTemplateContent(); + testParametersContent = ciResources.getTestParametersContent(); + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + if ( services != null ) { + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + if ( support != null ) { + try { + Requirement templateContentLaunchRequirement = support.getCapabilities().identifyTemplateContentLaunchRequirement(); + supportsTemplateContent = !templateContentLaunchRequirement.equals(Requirement.NONE); + } catch ( Exception e ) {} } } - if (name.getMethodName().startsWith("createCIFromTopology")) { - if( tm.getProvider().getCIServices() != null && tm.getProvider().getCIServices().getConvergedInfrastructureSupport() != null ) { - tm.getProvider().getCIServices().getConvergedInfrastructureSupport().terminate(name.getMethodName().toLowerCase(), "test over"); + if ( testTemplateContent != null ) { + options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci" + System.currentTimeMillis(), + testResourcePoolId, null, testTemplateContent, testParametersContent, supportsTemplateContent); + } else { + tm.warn("Unable to find converged infrastructure template for testing. Test invalid"); + return; + } + + if (name.getMethodName().startsWith("deleteCIFromTopology")) { + if( tm.getProvider().getConvergedInfrastructureServices() != null && tm.getProvider().getConvergedInfrastructureServices().getConvergedInfrastructureSupport() != null ) { + testCIId = tm.getTestCIId(DaseinTestManager.REMOVED, true); } + } } catch ( Exception e ) { } } + @After + public void after() { + tm.end(); + } + /* * create new CI and verify it. */ @Test public void createCIFromTopology() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); if( services == null ) { - tm.ok("No compute services in this cloud"); + tm.ok("No converged infrastructure services in this cloud"); return; } @@ -125,10 +138,13 @@ public void createCIFromTopology() throws CloudException, InternalException { tm.ok("No CI support in this cloud"); return; } - String description = "create-test"; - String zone = testDataCenterId; - CIProvisionOptions options = CIProvisionOptions.getInstance(name.getMethodName().toLowerCase(), description , zone , 2, testTopologyId ); // is testTopologyId the url? - ConvergedInfrastructure result = support.provision(options); + if (support.getCapabilities().identifyResourcePoolLaunchRequirement().equals(Requirement.REQUIRED) ) { + if (testResourcePoolId == null) { + fail("Unable to find test resource pool id in validateConvergedInfratrcture for cloud which has resource pool requirement"); + } + } + String result = DaseinTestManager.getCiResources().provisionConvergedInfrastructure(options, DaseinTestManager.STATEFUL); + assertNotNull(result); } /* @@ -136,9 +152,9 @@ public void createCIFromTopology() throws CloudException, InternalException { */ @Test public void deleteCIFromTopology() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); if( services == null ) { - tm.ok("No compute services in this cloud"); + tm.ok("No converged infrastructure services in this cloud"); return; } @@ -147,96 +163,8 @@ public void deleteCIFromTopology() throws CloudException, InternalException { tm.ok("No CI support in this cloud"); return; } - - support.terminate(testCIId, "die"); - } - - @Test - public void listConvergedInfrastructures() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - if( services == null ) { - tm.ok("No Converged Infrastructure services in this cloud"); - return; - } - - ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); - if( support == null ) { - tm.ok("No CI support in this cloud"); - } - - int count = 0; - Iterable convergedInfrastructures = support.listConvergedInfrastructures(null); - for (ConvergedInfrastructure ci : convergedInfrastructures) { - count++; - // testTopologyId - } - assertTrue("listConvergedInfrastructures must return more than one result.", count > 0); - } - - @Test - public void listVirtualMachines() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - if (services == null) { - tm.ok("No Converged Infrastructure services in this cloud"); - return; - } - - ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); - if( support == null ) { - tm.ok("No CI support in this cloud"); - return; - } - - int count = 0; - Iterable virtualMachines = support.listVirtualMachines(testCIId); - for (String vm : virtualMachines) { - count++; - } - assertTrue("listVirtualMachines must return more than one result.", count > 0); - } - - @Test - public void listVLANs() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - if (services == null) { - tm.ok("No Converged Infrastructure services in this cloud"); - return; - } - - ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); - if( support == null ) { - tm.ok("No CI support in this cloud"); - return; - } - - int count = 0; - Iterable virtualMachines = support.listVLANs(testCIId); - for (String vlan : virtualMachines) { - count++; - } - assertTrue("listVLANs must return more than one result.", count > 0); - } - - @Test - public void listConvergedInfrastructureStatus() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if (services == null) { - tm.ok("No Converged Infrastructure services in this cloud"); - return; - } - ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); - - if( support == null ) { - tm.ok("No CI support in this cloud"); - return; - } - int count = 0; - - Iterable ciStatus = support.listConvergedInfrastructureStatus(); - for (ResourceStatus status : ciStatus) { - count++; + if (testCIId != null) { + support.terminate(testCIId, "die"); } - assertTrue("listConvergedInfrastructureStatus must return more than one result.", count > 0); } } \ No newline at end of file diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulHttpLoadBalancerTests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulHttpLoadBalancerTests.java deleted file mode 100644 index 6879d09..0000000 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulHttpLoadBalancerTests.java +++ /dev/null @@ -1,408 +0,0 @@ -/** - * Copyright (C) 2009-2015 Dell, Inc. - * See annotations for authorship information - * - * ==================================================================== - * Licensed 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.dasein.cloud.test.ci; - -import org.dasein.cloud.CloudException; -import org.dasein.cloud.InternalException; -import org.dasein.cloud.ci.CIServices; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancer; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancer.BackendService; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancer.ForwardingRule; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancer.TargetHttpProxy; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancer.UrlSet; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancerFilterOptions; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancerSupport; -import org.dasein.cloud.ci.ConvergedInfrastructure; -import org.dasein.cloud.test.DaseinTestManager; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; - -/** - * Tests support for Dasein Cloud Replicapools which represent complex, multi-resource groups. - */ -public class StatefulHttpLoadBalancerTests { - static private DaseinTestManager tm; - static private final Random random = new Random(); - private String ciSource; - private String testHttpLoadBalancerId; - - @BeforeClass - static public void configure() { - tm = new DaseinTestManager(StatefulHttpLoadBalancerTests.class); - } - - @AfterClass - static public void cleanUp() { - if( tm != null ) { - tm.close(); - } - } - - @Rule - public final TestName name = new TestName(); - - public StatefulHttpLoadBalancerTests() { } - - @Before - public void before() { - tm.begin(name.getMethodName()); - assumeTrue(!tm.isTestSkipped()); - String testCIId = tm.getTestCIId(DaseinTestManager.STATELESS, true); - try { - ConvergedInfrastructure ci = tm.getProvider().getCIServices().getConvergedInfrastructureSupport().getConvergedInfrastructure(testCIId); - ciSource = ci.getProviderConvergedInfrastructureId(); - //horrible hack to try keep tests generic but work for google - if (tm.getProvider().getCloudName().equals("GCE")) { - ciSource = ci.getTag("instanceGroupLink").toString(); - } - } - catch (Exception e) { - - } - - //create testHttpLoadBalancer - if (name.getMethodName().equals("removeHttpLoadBalancers")) { - testHttpLoadBalancerId = tm.getTestHttpLoadBalancerId(DaseinTestManager.REMOVED, true); - } - else { - testHttpLoadBalancerId = tm.getTestHttpLoadBalancerId(DaseinTestManager.STATELESS, true); - } - } - - @After - public void after() { - if (name.getMethodName().startsWith("create")) { - CIServices services = tm.getProvider().getCIServices(); - - if (services != null) { - if (services.hasConvergedHttpLoadBalancerSupport()) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - if (support != null) { - - try { - tm.out("Removing "+name.getMethodName().toLowerCase()); - support.removeConvergedHttpLoadBalancers(name.getMethodName().toLowerCase()); - } - catch ( Throwable t ) { - tm.warn("Unable to remove test load balancer from create test"); - } - } - } - } - } - tm.end(); - } - - private void verifyConvergedHttpLoadBalancerNameDescription(ConvergedHttpLoadBalancer createdHttpLoadBalancer, String name, String description, String convergedHttpLoadBalancerSelfUrl) { - assertTrue("ConvergedHttpLoadBalancer name does not match expected.", createdHttpLoadBalancer.getName().equals(name)); - assertTrue("ConvergedHttpLoadBalancer description does not match expected.", createdHttpLoadBalancer.getDescription().equals(description)); - assertTrue("ConvergedHttpLoadBalancer selfUrl does not match expected.", createdHttpLoadBalancer.getSelfLink().equals(convergedHttpLoadBalancerSelfUrl)); - } - - private void verifyConvergedHttpLoadBalancerUrlSetPresent(ConvergedHttpLoadBalancer createdHttpLoadBalancer, String name, String description, String hostMatchPatterns, Map pathMap) { - boolean found = false; - List urlSets = createdHttpLoadBalancer.getUrlSets(); - if (null != urlSets) { - for (UrlSet urlSet : urlSets) { - if (urlSet.getName().equals(name)) { - found = true; - //assertTrue("urlSet description does not match.", urlSet.getDescription().equals(description)); //GCE does not support - assertTrue("urlSet hostMatchPatterns does not match.", urlSet.getHostMatchPatterns().equals(hostMatchPatterns)); - for (String key : pathMap.keySet()) { - assertTrue(key + " not present in urlSet pathMap.", (urlSet.getPathMap().get(key).equals(pathMap.get(key)))); - } - } - } - } - assertTrue("urlSet not found.", found); - } - - private void verifyConvergedHttpLoadBalancerBackendServicePresent(ConvergedHttpLoadBalancer createdHttpLoadBalancer, String name, String description, String selfUrl) { - boolean found = false; - List backendServices = createdHttpLoadBalancer.getBackendServices(); - if (null != backendServices) { - for (BackendService backendService : backendServices) { - if (backendService.getName().equals(name)) { - found = true; - assertEquals(description, backendService.getDescription()); - if (selfUrl != null) { - assertEquals(selfUrl, backendService.getSelfLink()); - } - } - } - } - assertTrue("BackendService not found.", found); - } - - private void verifyConvergedHttpLoadBalancerTargetHttpProxyPresent(ConvergedHttpLoadBalancer createdHttpLoadBalancer, String name, String description) { - boolean found = false; - List targetHttpProxies = createdHttpLoadBalancer.getTargetHttpProxies(); - if (null != targetHttpProxies) { - for (TargetHttpProxy targetHttpProxy : targetHttpProxies) { - if (targetHttpProxy.getName().equals(name)) { - found = true; - assertTrue("targetHttpProxy description does not match.", targetHttpProxy.getDescription().equals(description)); - } - } - } - assertTrue("TargetHttpProxy not found.", found); - } - - private void verifyConvergedHttpLoadBalancerForwardingRulePresent(ConvergedHttpLoadBalancer createdHttpLoadBalancer, String name, String description, String ipAddress, String ipProtocol, String portRange, String target) { - boolean found = false; - List forwardingRules = createdHttpLoadBalancer.getForwardingRules(); - if (null != forwardingRules) { - for (ForwardingRule forwardingRule : forwardingRules) { - if (forwardingRule.getName().equals(name)) { - found = true; - assertTrue("forwardingRule description does not match.", forwardingRule.getDescription().equals(description)); - //assertTrue("forwardingRule ipAddress does not match.", forwardingRule.getIpAddress().equals(ipAddress)); - assertTrue("forwardingRule ipProtocol does not match.", forwardingRule.getIpProtocol().equals(ipProtocol)); - assertTrue("forwardingRule portRange does not match.", forwardingRule.getPortRange().equals(portRange)); - assertTrue("forwardingRule target does not match.", forwardingRule.getTarget().equals(target)); - } - } - } - assertTrue("forwardingRule not found.", found); - } - - @Test - public void listHttpLoadBalancers() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if (services != null) { - if (services.hasConvergedHttpLoadBalancerSupport()) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - if (support != null) { - ConvergedHttpLoadBalancerFilterOptions options = new ConvergedHttpLoadBalancerFilterOptions(); - - Iterable result = support.listConvergedHttpLoadBalancers(); - - // ConvergedHttpLoadBalancer likely will need to be populated with data from other calls... - - tm.out("Subscribed", support.isSubscribed()); - //tm.out("Public Library", support.supportsPublicLibrary()); - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support topologies"); - } - } - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support compute services"); - } - } - - @Test - public void getConvergedHttpLoadBalancer() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if (services != null) { - if (services.hasConvergedHttpLoadBalancerSupport()) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - if (support != null) { - - ConvergedHttpLoadBalancer result = support.getConvergedHttpLoadBalancer(testHttpLoadBalancerId); - } - } - } - } - - @Test - public void removeHttpLoadBalancers() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if (services != null) { - if (services.hasConvergedHttpLoadBalancerSupport()) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - if (support != null) { - tm.out("Trying to remove load balancer "+testHttpLoadBalancerId); - support.removeConvergedHttpLoadBalancers(testHttpLoadBalancerId); - } - } - } - } - - - // withExistingXXXXX() - @Test - public void createHttpLoadBalancer() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if (services != null) { - if (services.hasConvergedHttpLoadBalancerSupport()) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - if (support != null) { - String instanceGroup1 = ciSource; - Map pathMap = new HashMap(); - String defaultBackend = "test-backend-1"; - pathMap.put("/*", defaultBackend); - String healthCheck1 = "test-new-health-check"; - String targetProxy1 = "target-proxy-"+random.nextInt(1000); - String targetProxy2 = "target-proxy-"+random.nextInt(1000); - ConvergedHttpLoadBalancer withExperimentalConvergedHttpLoadbalancerOptions = ConvergedHttpLoadBalancer - .getInstance(name.getMethodName().toLowerCase(), "test-http-load-balancer-description", defaultBackend) - .withHealthCheck(healthCheck1, healthCheck1 + "-description", null, 80, "/", 5, 5, 2, 2) //ONLY ONE ALLOWED - .withBackendService(defaultBackend, defaultBackend + "-description", 80, "http", "HTTP", new String[] {healthCheck1}, new String[] {instanceGroup1}, 30) - .withUrlSet("url-map-1", "url-map-description", "*", pathMap) - .withUrlSet("url-map-2", "url-map-2-description", "*.net", pathMap) - .withTargetHttpProxy(targetProxy1, targetProxy1 + "-description") - .withTargetHttpProxy(targetProxy2, targetProxy2 + "-description") - .withForwardingRule(targetProxy1 + "-fr", targetProxy1 + "-fr-description", null, "TCP", "80", targetProxy1) - .withForwardingRule(targetProxy2 + "-fr", targetProxy2 + "-fr-description", null, "TCP", "8080", targetProxy2); - - String convergedHttpLoadBalancerSelfUrl = support.createConvergedHttpLoadBalancer(withExperimentalConvergedHttpLoadbalancerOptions); - ConvergedHttpLoadBalancer createdHttpLoadBalancer = support.getConvergedHttpLoadBalancer(convergedHttpLoadBalancerSelfUrl); - - verifyConvergedHttpLoadBalancerNameDescription(createdHttpLoadBalancer, name.getMethodName().toLowerCase(), "test-http-load-balancer-description", convergedHttpLoadBalancerSelfUrl); - verifyConvergedHttpLoadBalancerUrlSetPresent(createdHttpLoadBalancer, "url-map-1", "url-map-description", "*", pathMap); // why no description - verifyConvergedHttpLoadBalancerBackendServicePresent(createdHttpLoadBalancer, defaultBackend, defaultBackend+"-description", null); - verifyConvergedHttpLoadBalancerTargetHttpProxyPresent(createdHttpLoadBalancer, targetProxy1, targetProxy1 + "-description"); - verifyConvergedHttpLoadBalancerForwardingRulePresent(createdHttpLoadBalancer, targetProxy1 + "-fr", targetProxy1 + "-fr-description", null, "TCP", "80-80", targetProxy1); - - tm.ok("createHttpLoadBalancer"); - tm.out("Subscribed", support.isSubscribed()); - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support converged http load balancers"); - } - } - else { - tm.ok(tm.getProvider().getCloudName() + " does not support converged http load balancer"); - } - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support converged infrastructure services"); - } - } - - @Test - public void createHttpLoadBalancerUsingExistingHealthCheck() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if (services != null) { - if (services.hasConvergedHttpLoadBalancerSupport()) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - if (support != null) { - - //get health check from test http load balancer - ConvergedHttpLoadBalancer hlb = support.getConvergedHttpLoadBalancer(testHttpLoadBalancerId); - ConvergedHttpLoadBalancer.HealthCheck hc = hlb.getHealthChecks().iterator().next(); - Map pathMap = new HashMap(); - String instanceGroup1 = ciSource; - String defaultBackend = "test-backend-4"; - pathMap.put("/*", defaultBackend); - String targetProxy = "target-proxy-3"; - ConvergedHttpLoadBalancer withExperimentalConvergedHttpLoadbalancerOptions = ConvergedHttpLoadBalancer - .getInstance(name.getMethodName().toLowerCase(), "test-http-load-balancer-description", defaultBackend) - .withUrlSet("url-map-1", "url-map-description", "*", pathMap) - .withExistingHealthCheck(hc.getSelfLink()) - .withBackendService(defaultBackend, defaultBackend + "-description", 80, "http", "HTTP", new String[] {hc.getName()}, new String[] {instanceGroup1}, 30) - .withTargetHttpProxy(targetProxy, targetProxy + "-description") - .withForwardingRule(targetProxy + "-fr", targetProxy + "-fr-description", null, "TCP", "80", targetProxy); - - String convergedHttpLoadBalancerSelfUrl = support.createConvergedHttpLoadBalancer(withExperimentalConvergedHttpLoadbalancerOptions); - - ConvergedHttpLoadBalancer createdHttpLoadBalancer = support.getConvergedHttpLoadBalancer(convergedHttpLoadBalancerSelfUrl); - verifyConvergedHttpLoadBalancerNameDescription(createdHttpLoadBalancer, name.getMethodName().toLowerCase(), "test-http-load-balancer-description", convergedHttpLoadBalancerSelfUrl); - verifyConvergedHttpLoadBalancerUrlSetPresent(createdHttpLoadBalancer, "url-map-1", "url-map-description", "*", pathMap); // why no description - verifyConvergedHttpLoadBalancerBackendServicePresent(createdHttpLoadBalancer, defaultBackend, defaultBackend+"-description", null); - verifyConvergedHttpLoadBalancerTargetHttpProxyPresent(createdHttpLoadBalancer, targetProxy, targetProxy + "-description"); - verifyConvergedHttpLoadBalancerForwardingRulePresent(createdHttpLoadBalancer, targetProxy + "-fr", targetProxy + "-fr-description", null, "TCP", "80-80", targetProxy); - - tm.ok("createHttpLoadBalancer"); - - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support topologies"); - } - } - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support compute services"); - } - } - - @Test - public void createHttpLoadBalancerUsingExistingBackendService() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if (services != null) { - if (services.hasConvergedHttpLoadBalancerSupport()) { - ConvergedHttpLoadBalancerSupport support = services.getConvergedHttpLoadBalancerSupport(); - if (support != null) { - if (support.getCapabilities().supportsHealthChecks() && - support.getCapabilities().supportsBackendServices() && - support.getCapabilities().supportsUrlSets() && - support.getCapabilities().supportsTargetHttpProxies() && - support.getCapabilities().supportsForwardingRules() && - support.getCapabilities().supportsUsingExistingBackendService()) { - //get backend service from test http load balancer - ConvergedHttpLoadBalancer hlb = support.getConvergedHttpLoadBalancer(testHttpLoadBalancerId); - ConvergedHttpLoadBalancer.BackendService bs = hlb.getBackendServices().get(0); - - Map pathMap = new HashMap(); - String defaultBackend = bs.getName(); - pathMap.put("/*", defaultBackend); - String targetProxy = "target-proxy-4"; - ConvergedHttpLoadBalancer withExperimentalConvergedHttpLoadbalancerOptions = ConvergedHttpLoadBalancer - .getInstance(name.getMethodName().toLowerCase(), "test-http-load-balancer-description", defaultBackend) - .withUrlSet("url-map-1", "url-map-description", "*", pathMap) - .withExistingBackendService(bs.getSelfLink()) - .withTargetHttpProxy(targetProxy, targetProxy + "-description") - .withForwardingRule(targetProxy + "-fr", targetProxy + "-fr-description", null, "TCP", "80", targetProxy); - - String convergedHttpLoadBalancerSelfUrl = support.createConvergedHttpLoadBalancer(withExperimentalConvergedHttpLoadbalancerOptions); - // VERIFY IT WAS CREATED CORRECTLY - - ConvergedHttpLoadBalancer createdHttpLoadBalancer = support.getConvergedHttpLoadBalancer(convergedHttpLoadBalancerSelfUrl); - - verifyConvergedHttpLoadBalancerNameDescription(createdHttpLoadBalancer, name.getMethodName().toLowerCase(), "test-http-load-balancer-description", convergedHttpLoadBalancerSelfUrl); - verifyConvergedHttpLoadBalancerUrlSetPresent(createdHttpLoadBalancer, "url-map-1", "url-map-description", "*", pathMap); // why no description - verifyConvergedHttpLoadBalancerBackendServicePresent(createdHttpLoadBalancer, defaultBackend, defaultBackend+"-description", bs.getSelfLink()); - verifyConvergedHttpLoadBalancerTargetHttpProxyPresent(createdHttpLoadBalancer, targetProxy, targetProxy + "-description"); - verifyConvergedHttpLoadBalancerForwardingRulePresent(createdHttpLoadBalancer, targetProxy + "-fr", targetProxy + "-fr-description", null, "TCP", "80-80", targetProxy); - - tm.ok("createHttpLoadBalancerUsingExistingBackendService"); - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support required HttpLoadBalancer methods"); - } - tm.out("Subscribed", support.isSubscribed()); - } else { - fail(tm.getProvider().getCloudName() + " returned null for getConvergedHttpLoadBalancerSupport"); - } - } else { - tm.ok(tm.getProvider().getCloudName() + " does not have ConvergedHttpLoadBalancerSupport"); - } - } else { - tm.ok(tm.getProvider().getCloudName() + " does not support combined infrastructure"); - } - } - -} \ No newline at end of file diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulTopologyTests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulTopologyTests.java deleted file mode 100644 index add249f..0000000 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulTopologyTests.java +++ /dev/null @@ -1,238 +0,0 @@ -/** - * Copyright (C) 2009-2015 Dell, Inc. - * See annotations for authorship information - * - * ==================================================================== - * Licensed 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.dasein.cloud.test.ci; - -import org.dasein.cloud.CloudException; -import org.dasein.cloud.InternalException; -import org.dasein.cloud.ci.CIServices; -import org.dasein.cloud.ci.Topology; -import org.dasein.cloud.ci.TopologyProvisionOptions; -import org.dasein.cloud.ci.TopologyProvisionOptions.DiskType; -import org.dasein.cloud.ci.TopologyProvisionOptions.MaintenanceOption; -import org.dasein.cloud.ci.TopologySupport; -import org.dasein.cloud.test.DaseinTestManager; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -import javax.annotation.Nonnull; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assume.assumeTrue; - -/** - * Tests support for Dasein Cloud topologies which represent complex, multi-resource templates that can be provisioned into - * running resources. - *

Created by George Reese: 5/31/13 10:57 AM

- * @author George Reese - * @version 2013.07 initial version - * @since 2013.07 - */ - -public class StatefulTopologyTests { - static private DaseinTestManager tm; - static private final Random random = new Random(); - private String testNetworkId; - private String testImageId; - private String testProductId; - static private List testTopologyIds = new ArrayList(); - - @BeforeClass - static public void configure() { - tm = new DaseinTestManager(StatefulTopologyTests.class); - } - - @AfterClass - static public void cleanUp() { - if( tm != null ) { - tm.close(); - } - } - - @Rule - public final TestName name = new TestName(); - - public StatefulTopologyTests() { } - - @Before - public void before() { - tm.begin(name.getMethodName()); - assumeTrue(!tm.isTestSkipped()); - testNetworkId = tm.getTestVLANId(DaseinTestManager.STATELESS, false, null); - testImageId = tm.getTestImageId(DaseinTestManager.STATELESS, false); - testProductId = tm.getTestVMProductId(); - } - - @After - public void after() { - tm.end(); - } - - private void assertTopology(@Nonnull Topology topology) { - assertNotNull("Topology ID may not be null", topology.getProviderTopologyId()); - assertNotNull("Topology name may not be null", topology.getName()); - assertNotNull("Topology description may not be null", topology.getDescription()); - assertNotNull("Topology state may not be null", topology.getCurrentState()); - assertTrue("Topology creation timestamp may not be negative", topology.getCreationTimestamp() >= 0L); - assertNotNull("Topology tags may not be null", topology.getTags()); - assertNotNull("Owner ID may not be null", topology.getProviderOwnerId()); - //assertNotNull("Region ID may not be null", topology.getProviderRegionId()); - Iterable vms = topology.getVirtualMachines(); - - assertNotNull("VM list may not be null", vms); - for( Topology.VMDevice vm : vms ) { - assertNotNull("VM device ID may not be null", vm.getDeviceId()); - assertNotNull("VM name may not be null", vm.getName()); - assertTrue("VM CPU count must be non-negative and non-zero", vm.getCpuCount() > 0); - assertNotNull("VM memory must not be null", vm.getMemory()); - assertNotNull("VM architecture must not be null", vm.getArchitecture()); - assertNotNull("VM platform must not be null", vm.getPlatform()); - assertTrue("VM capacity must be non-negative and non-zero", vm.getCapacity() > 0); - } - Iterable vlans = topology.getVLANs(); - - assertNotNull("VLAN list may not be null", vlans); - for( Topology.VLANDevice vlan : vlans ) { - assertNotNull("VLAN device ID may not be null", vlan.getDeviceId()); - assertNotNull("VLAN name may not be null", vlan.getName()); - } - } - - /* - * set and get metadata in a template - */ - @Test - public void checkMetaData() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - tm.out("Subscribed", support.isSubscribed()); - tm.out("Public Library", support.supportsPublicLibrary()); - } - else { - tm.ok(tm.getProvider().getCloudName() + " does not support topologies"); - } - } - else { - tm.ok(tm.getProvider().getCloudName() + " does not support compute services"); - } - } - - /* - * create new topology and verify it. - */ - @Test - public void createTopology() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - - String name = "dsn-topology"+String.valueOf(random.nextInt(1000)); - TopologyProvisionOptions withTopologyOptions = TopologyProvisionOptions.getInstance(name, "description", testProductId, true); - - List tags = new ArrayList(); - tags.add("http-server"); - tags.add("https-server"); - tags.add("generic-tag"); - - List sshKeys = new ArrayList(); - sshKeys.add("user.name:ssh-rsa BLah2blah34BL44jdshdudiIEJKEBNu4494hfjs9w94jksdn user.name@test.test"); - withTopologyOptions = withTopologyOptions.withSshKeys(sshKeys.toArray(new String[sshKeys.size()])); - - Map metadata = new HashMap(); - metadata.put("key", "value"); - withTopologyOptions = withTopologyOptions.withMetadata(metadata); - - withTopologyOptions = withTopologyOptions.withAutomaticRestart(false); - withTopologyOptions = withTopologyOptions.withMaintenanceOption(MaintenanceOption.TERMINATE_VM_INSTANCE); - - withTopologyOptions = withTopologyOptions.withTags(tags); - withTopologyOptions = withTopologyOptions.withNetworkInterface(testNetworkId, null, true); // ,accessConfigs); - withTopologyOptions = withTopologyOptions.withAttachedDisk("dsn-topology-disk"+String.valueOf(random.nextInt(1000)), DiskType.STANDARD_PERSISTENT_DISK, testImageId, true, true); - boolean result = support.createTopology(withTopologyOptions); - if (result) { - testTopologyIds.add(name); - } - - Topology t = support.getTopology(name); - assertTopology(t); - } else { - tm.ok("No topology support in this cloud"); - } - } else { - tm.ok("No compute services in this cloud"); - } - } - - /* - * delete a topology - */ - @Test - public void deletePrivateTopologies() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - if (testTopologyIds == null || testTopologyIds.isEmpty()) { - - TopologyProvisionOptions withTopologyOptions = TopologyProvisionOptions.getInstance("dsn-remove-topology", "description", testProductId, true); - withTopologyOptions = withTopologyOptions.withNetworkInterface(testNetworkId, null, false); - withTopologyOptions = withTopologyOptions.withAttachedDisk("dsn-remove-topology-disk", DiskType.SSD_PERSISTENT_DISK, testImageId, true, true); - - withTopologyOptions = withTopologyOptions.withAutomaticRestart(true); - withTopologyOptions = withTopologyOptions.withMaintenanceOption(MaintenanceOption.MIGRATE_VM_INSTANCE); - - boolean result = support.createTopology(withTopologyOptions); - if (result) { - testTopologyIds.add("dsn-remove-topology"); - } - } - boolean result2 = support.removeTopologies(testTopologyIds.toArray(new String[testTopologyIds.size()])); - for (String id : testTopologyIds) { - Topology t = support.getTopology(id); - assertNull("Topology "+id+" should have been removed", t); - } - } else { - tm.ok("No topology support in this cloud"); - } - } else { - tm.ok("No compute services in this cloud"); - } - } -} diff --git a/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java new file mode 100644 index 0000000..3503888 --- /dev/null +++ b/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java @@ -0,0 +1,267 @@ +/** + * Copyright (C) 2009-2016 Dell, Inc. + * See annotations for authorship information + *

+ * ==================================================================== + * Licensed 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.dasein.cloud.test.ci; + +import org.dasein.cloud.CloudException; +import org.dasein.cloud.InternalException; +import org.dasein.cloud.Requirement; +import org.dasein.cloud.ResourceStatus; +import org.dasein.cloud.ci.ConvergedInfrastructure; +import org.dasein.cloud.ci.ConvergedInfrastructureProvisionOptions; +import org.dasein.cloud.ci.ConvergedInfrastructureResource; +import org.dasein.cloud.ci.ConvergedInfrastructureServices; +import org.dasein.cloud.ci.ConvergedInfrastructureSupport; +import org.dasein.cloud.dc.DataCenterServices; +import org.dasein.cloud.dc.ResourcePool; +import org.dasein.cloud.test.DaseinTestManager; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Map; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +/** + * User: daniellemayne + * Date: 21/03/2016 + * Time: 09:54 + */ +public class StatelessCITests { + static private DaseinTestManager tm; + + private ConvergedInfrastructureProvisionOptions options; + private String testResourcePoolId = null; + private String testConvergedInfrastructureID = null; + + @BeforeClass + static public void configure() { + tm = new DaseinTestManager(StatelessCITests.class); + } + + @AfterClass + static public void cleanUp() { + if( tm != null ) { + tm.close(); + } + } + + @Rule + public final TestName name = new TestName(); + + + public StatelessCITests() {} + + @Before + public void before() { + tm.begin(name.getMethodName()); + assumeTrue(!tm.isTestSkipped()); + testConvergedInfrastructureID = tm.getTestCIId(DaseinTestManager.STATELESS, false); + + if ( name.getMethodName().startsWith("validate") ) { + try { + testResourcePoolId = null; + if ( tm.getProvider().getDataCenterServices().getCapabilities().supportsResourcePools() ) { + DataCenterServices dc = tm.getProvider().getDataCenterServices(); + + Iterable testRPList = dc.listResourcePools(tm.getDefaultDataCenterId(true)); + if ( testRPList != null && testRPList.iterator().hasNext() ) { + ResourcePool rp = testRPList.iterator().next(); + testResourcePoolId = rp.getProvideResourcePoolId(); + } + } + + String testTemplateContent = "", testParametersContent = ""; + boolean supportsTemplateContent = false; + CIResources ciResources = DaseinTestManager.getCiResources(); + testTemplateContent = ciResources.getTestTemplateContent(); + testParametersContent = ciResources.getTestParametersContent(); + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + if ( services != null ) { + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + if ( support != null ) { + try { + Requirement templateContentLaunchRequirement = support.getCapabilities().identifyTemplateContentLaunchRequirement(); + supportsTemplateContent = !templateContentLaunchRequirement.equals(Requirement.NONE); + } catch ( Exception e ) {} + } + } + + if ( testTemplateContent != null ) { + options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci", + testResourcePoolId, null, testTemplateContent, testParametersContent, supportsTemplateContent); + } else { + tm.warn("Unable to find converged infrastructure template for testing. Test invalid"); + return; + } + } catch ( Exception e ) { + } + } + } + + @After + public void after() { + tm.end(); + } + + private void assertConvergedInfrastructure(ConvergedInfrastructure ci) { + assertNotNull("Converged Infrastucture id should not be null", ci.getProviderCIId()); + tm.out("Id", ci.getProviderCIId()); + assertNotNull("Converged Infrastructure name should not be null", ci.getName()); + tm.out("Name", ci.getName()); + tm.out("Description", ci.getDescription()); + assertNotNull("Converged Infrastructure state should not be null", ci.getCiState()); + tm.out("State", ci.getCiState()); + + Calendar calendar = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); + calendar.setTimeInMillis(ci.getProvisioningTimestamp()); + String t = sdf.format(calendar.getTime()); + tm.out("Timestamp", t); + + assertNotNull("List of resources can be empty but should not be null", ci.getResources()); + for (ConvergedInfrastructureResource resource : ci.getResources()) { + tm.out("Resource", resource.getResourceType().toString()+": "+resource.getResourceId()); + } + assertNotNull("Datacenter id should not be null", ci.getProviderDatacenterId()); + tm.out("Datacenter id", ci.getProviderDatacenterId()); + assertNotNull("Region id should not be null", ci.getProviderRegionId()); + tm.out("Region id", ci.getProviderRegionId()); + tm.out("Resource pool id", ci.getProviderResourcePoolId()); + assertNotNull("Tags may be empty list but should not be null", ci.getTags()); + for( Map.Entry entry : ci.getTags().entrySet() ) { + tm.out("Tag " + entry.getKey(), entry.getValue()); + } + } + + @Test + public void getConvergedInfrastructure() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + if( services == null ) { + tm.ok("No Converged Infrastructure services in this cloud"); + return; + } + + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + if( support == null ) { + tm.ok("No CI support in this cloud"); + return; + } + if (testConvergedInfrastructureID != null) { + ConvergedInfrastructure ci = support.getConvergedInfrastructure(testConvergedInfrastructureID); + assertNotNull("Test converged infrastructure "+testConvergedInfrastructureID+" not found", ci); + assertConvergedInfrastructure(ci); + } + else { + tm.warn("Unable to find test converged infrastructure object for getConvergedInfrastructure. Test may not be valid"); + } + } + + @Test + public void listConvergedInfrastructures() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + if( services == null ) { + tm.ok("No Converged Infrastructure services in this cloud"); + return; + } + + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + if( support == null ) { + tm.ok("No CI support in this cloud"); + return; + } + + int count = 0; + Iterable convergedInfrastructures = support.listConvergedInfrastructures(null); + assertNotNull("Converged infrastructure list may be empty but should not be null", convergedInfrastructures); + for (ConvergedInfrastructure ci : convergedInfrastructures) { + assertConvergedInfrastructure(ci); + count++; + } + if (count == 0) { + tm.warn("No converged infrastructure resources found. Test may not be valid"); + } + } + + @Test + public void listConvergedInfrastructureStatus() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + + if (services == null) { + tm.ok("No Converged Infrastructure services in this cloud"); + return; + } + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + + if( support == null ) { + tm.ok("No CI support in this cloud"); + return; + } + int count = 0; + + Iterable ciStatus = support.listConvergedInfrastructureStatus(); + assertNotNull("Converged infrastructure list may be empty but should not be null", ciStatus); + for (ResourceStatus status : ciStatus) { + tm.out(status.getProviderResourceId()+": "+status.getResourceStatus().toString()); + count++; + } + if (count == 0) { + tm.warn("No converged infrastructure resources found. Test may not be valid"); + } + } + + /* + * verify the provided converged infrastructure request would be accepted by the cloud. + */ + @Test + public void validateConvergedInfrastructure() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + if( services == null ) { + tm.ok("No converged infrastructure services in this cloud"); + return; + } + + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + if( support == null ) { + tm.ok("No CI support in this cloud"); + return; + } + if (support.getCapabilities().identifyResourcePoolLaunchRequirement().equals(Requirement.REQUIRED) ) { + if (testResourcePoolId == null) { + fail("Unable to find test resource pool id in validateConvergedInfratrcture for cloud which has resource pool requirement"); + } + } + try { + support.validateDeployment(options); + } + catch ( Exception e ) { + fail("Deployment validation failed: "+e.getMessage()); + } + + } +} diff --git a/src/main/java/org/dasein/cloud/test/ci/StatelessHttpLoadBalancerTests.java b/src/main/java/org/dasein/cloud/test/ci/StatelessHttpLoadBalancerTests.java deleted file mode 100644 index d63aec0..0000000 --- a/src/main/java/org/dasein/cloud/test/ci/StatelessHttpLoadBalancerTests.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright (C) 2009-2015 Dell, Inc. - * See annotations for authorship information - * - * ==================================================================== - * Licensed 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.dasein.cloud.test.ci; - -import static org.junit.Assume.assumeTrue; - -import java.util.HashMap; -import java.util.Map; - -import org.dasein.cloud.test.DaseinTestManager; -import org.dasein.cloud.CloudException; -import org.dasein.cloud.InternalException; -import org.dasein.cloud.ci.CIServices; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancer; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancerFilterOptions; -import org.dasein.cloud.ci.ConvergedHttpLoadBalancerSupport; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -/** - * Tests support for Dasein Cloud topologies which represent complex, multi-resource templates that can be provisioned into - * running resources. - *

Created by George Reese: 5/31/13 10:57 AM

- * @author George Reese - * @version 2013.07 initial version - * @since 2013.07 - */ -public class StatelessHttpLoadBalancerTests { - static private DaseinTestManager tm; - - @BeforeClass - static public void configure() { - tm = new DaseinTestManager(StatelessHttpLoadBalancerTests.class); - } - - @AfterClass - static public void cleanUp() { - if( tm != null ) { - tm.close(); - } - } - - @Rule - public final TestName name = new TestName(); - - private String testTopologyId; - - public StatelessHttpLoadBalancerTests() { } - - @Before - public void before() { - tm.begin(name.getMethodName()); - assumeTrue(!tm.isTestSkipped()); - testTopologyId = tm.getTestTopologyId(DaseinTestManager.STATELESS, false); - } - - @After - public void after() { - tm.end(); - } - - @Test - public void dummyTest() { - - } - - -} diff --git a/src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java b/src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java deleted file mode 100644 index 7569a2f..0000000 --- a/src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java +++ /dev/null @@ -1,307 +0,0 @@ -/** - * Copyright (C) 2009-2015 Dell, Inc. - * See annotations for authorship information - * - * ==================================================================== - * Licensed 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.dasein.cloud.test.ci; - -import org.dasein.cloud.CloudException; -import org.dasein.cloud.InternalException; -import org.dasein.cloud.ci.CIServices; -import org.dasein.cloud.ci.Topology; -import org.dasein.cloud.ci.TopologySupport; -import org.dasein.cloud.test.DaseinTestManager; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestName; - -import javax.annotation.Nonnull; -import java.util.Date; -import java.util.Map; -import java.util.UUID; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; - -/** - * Tests support for Dasein Cloud topologies which represent complex, multi-resource templates that can be provisioned into - * running resources. - *

Created by George Reese: 5/31/13 10:57 AM

- * @author George Reese - * @version 2013.07 initial version - * @since 2013.07 - */ -public class StatelessTopologyTests { - static private DaseinTestManager tm; - - @BeforeClass - static public void configure() { - tm = new DaseinTestManager(StatelessTopologyTests.class); - } - - @AfterClass - static public void cleanUp() { - if( tm != null ) { - tm.close(); - } - } - - @Rule - public final TestName name = new TestName(); - - private String testTopologyId; - - public StatelessTopologyTests() { } - - @Before - public void before() { - tm.begin(name.getMethodName()); - assumeTrue(!tm.isTestSkipped()); - testTopologyId = tm.getTestTopologyId(DaseinTestManager.STATELESS, false); - } - - @After - public void after() { - tm.end(); - } - - private void assertTopology(@Nonnull Topology topology) { - assertNotNull("Topology ID may not be null", topology.getProviderTopologyId()); - assertNotNull("Topology name may not be null", topology.getName()); - assertNotNull("Topology description may not be null", topology.getDescription()); - assertNotNull("Topology state may not be null", topology.getCurrentState()); - assertTrue("Topology creation timestamp may not be negative", topology.getCreationTimestamp() >= 0L); - assertNotNull("Topology tags may not be null", topology.getTags()); - assertNotNull("Owner ID may not be null", topology.getProviderOwnerId()); - //assertNotNull("Region ID may not be null", topology.getProviderRegionId()); - Iterable vms = topology.getVirtualMachines(); - - assertNotNull("VM list may not be null", vms); - for( Topology.VMDevice vm : vms ) { - assertNotNull("VM device ID may not be null", vm.getDeviceId()); - assertNotNull("VM name may not be null", vm.getName()); - assertTrue("VM CPU count must be non-negative and non-zero", vm.getCpuCount() > 0); - assertNotNull("VM memory must not be null", vm.getMemory()); - assertNotNull("VM architecture must not be null", vm.getArchitecture()); - assertNotNull("VM platform must not be null", vm.getPlatform()); - assertTrue("VM capacity must be non-negative and non-zero", vm.getCapacity() > 0); - } - Iterable vlans = topology.getVLANs(); - - assertNotNull("VLAN list may not be null", vlans); - for( Topology.VLANDevice vlan : vlans ) { - assertNotNull("VLAN device ID may not be null", vlan.getDeviceId()); - assertNotNull("VLAN name may not be null", vlan.getName()); - } - } - - @Test - public void checkMetaData() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - tm.out("Subscribed", support.isSubscribed()); - tm.out("Public Library", support.supportsPublicLibrary()); - } - else { - tm.ok(tm.getProvider().getCloudName() + " does not support topologies"); - } - } - else { - tm.ok(tm.getProvider().getCloudName() + " does not support compute services"); - } - } - - @Test - public void getBogusTopology() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - Topology t = support.getTopology(UUID.randomUUID().toString()); - - tm.out("Bogus Topology", t); - assertNull("Bogus topology was supposed to be none, but got a valid topology.", t); - } - else { - tm.ok("No topology support in this cloud"); - } - } - else { - tm.ok("No compute services in this cloud"); - } - } - - @Test - public void getTopology() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - if( testTopologyId != null ) { - Topology t = support.getTopology(testTopologyId); - - tm.out("Topology", t); - assertNotNull("Failed to find the test topology among possible images", t); - } - else { - if( !support.isSubscribed() ) { - tm.warn("No topology ID was identified, so this test is not valid"); - } - else { - fail("No test topology exists for the getTopology test"); - } - } - } - else { - tm.ok("No topology support in this cloud"); - } - } - else { - tm.ok("No compute services in this cloud"); - } - } - - @Test - public void topologyContent() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - if( testTopologyId != null ) { - Topology t = support.getTopology(testTopologyId); - - assertNotNull("Failed to find the test topology among possible topologies", t); - tm.out("Topology ID", t.getProviderTopologyId()); - tm.out("Current State", t.getCurrentState()); - tm.out("Name", t.getName()); - tm.out("Created", new Date(t.getCreationTimestamp())); - tm.out("Owner Account", t.getProviderOwnerId()); - tm.out("Region ID", t.getProviderRegionId()); - tm.out("Data Center ID", t.getProviderDataCenterId()); - - Iterable vms = t.getVirtualMachines(); - - //noinspection ConstantConditions - if( vms != null ) { - int i = 1; - - for( Topology.VMDevice vm : vms ) { - tm.out("VM " + i + " Device ID", vm.getDeviceId()); - tm.out("VM " + i + " Name", vm.getName()); - tm.out("VM " + i + " Capacity", vm.getCapacity()); - tm.out("VM " + i + " Architecture", vm.getArchitecture()); - tm.out("VM " + i + " Platform", vm.getPlatform()); - tm.out("VM " + i + " CPU Count", vm.getCpuCount()); - tm.out("VM " + i + " Memory", vm.getMemory()); - i++; - } - } - Iterable vlans = t.getVLANs(); - - //noinspection ConstantConditions - if( vlans != null ) { - int i = 1; - - for( Topology.VLANDevice vlan : vlans ) { - tm.out("VLAN " + i + " Device ID", vlan.getDeviceId()); - tm.out("VLAN " + i + " Name", vlan.getName()); - i++; - } - } - - Map tags = t.getTags(); - - //noinspection ConstantConditions - if( tags != null ) { - for( Map.Entry entry : tags.entrySet() ) { - tm.out("Tag " + entry.getKey(), entry.getValue()); - } - } - - tm.out("Description", t.getDescription()); - - assertTopology(t); - - } - else { - if( !support.isSubscribed() ) { - tm.warn("No topology ID was identified, so this test is not valid"); - } - else { - fail("No test topology exists for the topologyContent test"); - } - } - } - else { - tm.ok("No topology support in this cloud"); - } - } - else { - tm.ok("No compute services in this cloud"); - } - } - - @Test - public void listPrivateTopologies() throws CloudException, InternalException { - CIServices services = tm.getProvider().getCIServices(); - - if( services != null ) { - TopologySupport support = services.getTopologySupport(); - - if( support != null ) { - Iterable topologies = support.listTopologies(null); - int count = 0; - - assertNotNull("listTopologies() must return a non-null list of topologies even if a private library is not supported", topologies); - for( Topology t : topologies ) { - count++; - tm.out("Topology", t); - } - tm.out("Total Topology Count", count); - for( Topology t : topologies ) { - assertTopology(t); - } - if( count < 1 ) { - tm.warn("No topologies were provided so this test may not be valid"); - } - } - else { - tm.ok("No topology support in this cloud"); - } - } - else { - tm.ok("No compute services in this cloud"); - } - } -} diff --git a/src/main/java/org/dasein/cloud/test/compute/ComputeResources.java b/src/main/java/org/dasein/cloud/test/compute/ComputeResources.java index 5af5a99..7127a80 100644 --- a/src/main/java/org/dasein/cloud/test/compute/ComputeResources.java +++ b/src/main/java/org/dasein/cloud/test/compute/ComputeResources.java @@ -20,7 +20,6 @@ package org.dasein.cloud.test.compute; import org.apache.log4j.Logger; -import org.dasein.cloud.CloudErrorType; import org.dasein.cloud.CloudException; import org.dasein.cloud.CloudProvider; import org.dasein.cloud.GeneralCloudException; @@ -69,7 +68,11 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Random; import static org.junit.Assert.fail; @@ -1015,7 +1018,7 @@ else if( !support.getCapabilities().identifyLocalBundlingRequirement().equals(Re String id = options.build(provider); if( id == null ) { - throw new GeneralCloudException("Unable to create a snapshot", CloudErrorType.GENERAL); + throw new GeneralCloudException("Unable to create a snapshot"); } synchronized ( testSnapshots ) { while( testSnapshots.containsKey(label) ) { diff --git a/src/main/java/org/dasein/cloud/test/compute/ComputeTestSuite.java b/src/main/java/org/dasein/cloud/test/compute/ComputeTestSuite.java index 42de5bd..a4d4432 100644 --- a/src/main/java/org/dasein/cloud/test/compute/ComputeTestSuite.java +++ b/src/main/java/org/dasein/cloud/test/compute/ComputeTestSuite.java @@ -20,7 +20,6 @@ package org.dasein.cloud.test.compute; import org.dasein.cloud.test.DaseinTestManager; -import org.dasein.cloud.test.ci.StatelessTopologyTests; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.runner.RunWith; diff --git a/src/main/java/org/dasein/cloud/test/identity/IdentityResources.java b/src/main/java/org/dasein/cloud/test/identity/IdentityResources.java index 465e17c..90c2b83 100644 --- a/src/main/java/org/dasein/cloud/test/identity/IdentityResources.java +++ b/src/main/java/org/dasein/cloud/test/identity/IdentityResources.java @@ -21,7 +21,11 @@ import org.apache.commons.codec.binary.Base64; import org.apache.log4j.Logger; -import org.dasein.cloud.*; +import org.dasein.cloud.CloudException; +import org.dasein.cloud.CloudProvider; +import org.dasein.cloud.GeneralCloudException; +import org.dasein.cloud.InternalException; +import org.dasein.cloud.Requirement; import org.dasein.cloud.identity.CloudGroup; import org.dasein.cloud.identity.CloudUser; import org.dasein.cloud.identity.IdentityAndAccessSupport; @@ -36,10 +40,8 @@ import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import java.security.KeyPair; import java.security.KeyPairGenerator; -import java.security.NoSuchAlgorithmException; import java.security.interfaces.RSAPublicKey; import java.util.HashMap; import java.util.Iterator; @@ -401,7 +403,7 @@ public int report() { String id = support.createGroup(namePrefix + " " + System.currentTimeMillis(), "/dsntest", false).getProviderGroupId(); if( id == null ) { - throw new GeneralCloudException("No group was created", CloudErrorType.GENERAL); + throw new GeneralCloudException("No group was created"); } synchronized( testGroups ) { while( testGroups.containsKey(label) ) { @@ -425,7 +427,7 @@ public int report() { id = support.createKeypair(namePrefix + (System.currentTimeMillis()%10000)).getProviderKeypairId(); } if( id == null ) { - throw new GeneralCloudException("No keypair was generated", CloudErrorType.GENERAL); + throw new GeneralCloudException("No keypair was generated"); } synchronized( testKeys ) { while( testKeys.containsKey(label) ) { @@ -440,7 +442,7 @@ public int report() { String id = support.createUser(namePrefix + (System.currentTimeMillis()%10000), "/dsntest", preferredGroups == null ? new String[0] : preferredGroups).getProviderUserId(); if( id == null ) { - throw new GeneralCloudException("No user was created", CloudErrorType.GENERAL); + throw new GeneralCloudException("No user was created"); } synchronized( testUsers ) { while( testUsers.containsKey(label) ) { diff --git a/src/main/java/org/dasein/cloud/test/network/NetworkResources.java b/src/main/java/org/dasein/cloud/test/network/NetworkResources.java index d7847b1..d20824a 100644 --- a/src/main/java/org/dasein/cloud/test/network/NetworkResources.java +++ b/src/main/java/org/dasein/cloud/test/network/NetworkResources.java @@ -2169,7 +2169,7 @@ public int close() { //} id = support.createVlan("192.168.1.0/24", namePrefix + ( System.currentTimeMillis() % 10000 ), "Test VLAN for the Dasein Cloud Integration tests", "example.com", new String[]{"192.168.1.1"}, new String[]{"192.168.1.1"}).getProviderVlanId(); if( id == null ) { - throw new GeneralCloudException("No VLAN was created", CloudErrorType.GENERAL); + throw new GeneralCloudException("No VLAN was created"); } synchronized ( testVLANs ) { while( testVLANs.containsKey(label) ) { @@ -2183,7 +2183,7 @@ public int close() { public @Nonnull String provisionRoutingTable(@Nonnull VLANSupport support, @Nonnull String vlanId, @Nonnull String label, @Nonnull String namePrefix) throws CloudException, InternalException { String id = support.createRoutingTable(vlanId, namePrefix + ( System.currentTimeMillis() % 10000 ), "Test Routing Table for the Dasein Cloud Integration tests"); if( id == null ) { - throw new GeneralCloudException("No Routing Table was created", CloudErrorType.GENERAL); + throw new GeneralCloudException("No Routing Table was created"); } synchronized ( testRouteTables ) { while( testRouteTables.containsKey(label) ) { diff --git a/src/main/java/org/dasein/cloud/test/platform/PlatformResources.java b/src/main/java/org/dasein/cloud/test/platform/PlatformResources.java index f5653c5..be984ae 100644 --- a/src/main/java/org/dasein/cloud/test/platform/PlatformResources.java +++ b/src/main/java/org/dasein/cloud/test/platform/PlatformResources.java @@ -626,7 +626,7 @@ else if( product.getStandardHourlyRate() > afterThis.getStandardHourlyRate() } while( id == null ); if( id == null ) { - throw new GeneralCloudException("No database was generated", CloudErrorType.GENERAL); + throw new GeneralCloudException("No database was generated"); } synchronized( testRDBMS ) { diff --git a/src/main/java/org/dasein/cloud/test/storage/StatefulObjectStoreTests.java b/src/main/java/org/dasein/cloud/test/storage/StatefulObjectStoreTests.java index 8fcfa73..da2c17a 100644 --- a/src/main/java/org/dasein/cloud/test/storage/StatefulObjectStoreTests.java +++ b/src/main/java/org/dasein/cloud/test/storage/StatefulObjectStoreTests.java @@ -480,7 +480,7 @@ public void downloadRoot() throws CloudException, InternalException, IOException } //noinspection ThrowableResultOfMethodCallIgnored if( task.getTransferError() != null ) { - throw new GeneralCloudException("Download of "+targetFile+" had an error.", task.getTransferError(), CloudErrorType.GENERAL); + throw new GeneralCloudException("Download of "+targetFile+" had an error.", task.getTransferError()); } tm.out("Downloaded", targetFile.length() + " bytes"); assertFile(targetFile); @@ -534,7 +534,7 @@ public void downloadChild() throws CloudException, InternalException, IOExceptio } //noinspection ThrowableResultOfMethodCallIgnored if( task.getTransferError() != null ) { - throw new GeneralCloudException("Download of "+targetFile+" had an error.", task.getTransferError(), CloudErrorType.GENERAL); + throw new GeneralCloudException("Download of "+targetFile+" had an error.", task.getTransferError()); } tm.out("Downloaded", targetFile.length() + " bytes"); assertFile(targetFile); diff --git a/src/main/resources/convergedInfrastructure/parameterContent.json b/src/main/resources/convergedInfrastructure/parameterContent.json new file mode 100644 index 0000000..da31a17 --- /dev/null +++ b/src/main/resources/convergedInfrastructure/parameterContent.json @@ -0,0 +1,17 @@ +{ + "dnsLabelPrefix": { + "value": "test-dns" + }, + "vmName": { + "value": "rdpVM" + }, + "adminUsername": { + "value": "azureUser" + }, + "adminPassword": { + "value": "p@ssw0rd!" + }, + "rdpPort": { + "value": 50001 + } +} \ No newline at end of file diff --git a/src/main/resources/convergedInfrastructure/templateContent.json b/src/main/resources/convergedInfrastructure/templateContent.json new file mode 100644 index 0000000..7757d6a --- /dev/null +++ b/src/main/resources/convergedInfrastructure/templateContent.json @@ -0,0 +1,218 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "dnsLabelPrefix": { + "type": "string", + "metadata": { + "description": "Unique public DNS prefix for the deployment. The fqdn will look something like '.westus.cloudapp.azure.com'. Up to 62 chars, digits or dashes, lowercase, should start with a letter: must conform to '^[a-z][a-z0-9-]{1,61}[a-z0-9]$'." + } + }, + "vmName": { + "type": "string", + "defaultValue": "vm", + "metadata": { + "description": "The name of the VM" + } + }, + "adminUsername": { + "type": "string", + "defaultValue": "cloudguy", + "metadata": { + "description": "The name of the administrator of the new VM. Exclusion list: 'admin','administrator'" + } + }, + "adminPassword": { + "type": "securestring", + "metadata": { + "description": "The password for the administrator account of the new VM" + } + }, + "rdpPort": { + "type": "int", + "defaultValue": 50001, + "metadata": { + "description": "Public port number for RDP" + } + } + }, + "variables": { + "storageAccountName": "[concat(uniquestring(resourceGroup().id), 'sardpvm')]", + "location": "[resourceGroup().location]", + "virtualNetworkName": "rdpVNET", + "vnetAddressRange": "10.0.0.0/16", + "subnetAddressRange": "10.0.0.0/24", + "subnetName": "Subnet", + "subnet-id": "[concat(resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName')),'/subnets/',variables('subnetName'))]", + "imagePublisher": "MicrosoftWindowsServer", + "imageOffer": "WindowsServer", + "imageSku": "2012-R2-Datacenter", + "apiVersion": "2015-06-15" + }, + "resources": [ + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Network/publicIPAddresses", + "name": "publicIp", + "location": "[variables('location')]", + "properties": { + "publicIPAllocationMethod": "Dynamic", + "dnsSettings": { + "domainNameLabel": "[parameters('dnsLabelPrefix')]" + } + } + }, + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Storage/storageAccounts", + "name": "[variables('storageAccountName')]", + "location": "[variables('location')]", + "properties": { + "accountType": "Standard_LRS" + } + }, + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Network/virtualNetworks", + "name": "[variables('virtualNetworkName')]", + "location": "[variables('location')]", + "properties": { + "addressSpace": { + "addressPrefixes": [ + "[variables('vnetAddressRange')]" + ] + }, + "subnets": [ + { + "name": "Subnet", + "properties": { + "addressPrefix": "[variables('subnetAddressRange')]" + } + } + ] + } + }, + { + "apiVersion": "[variables('apiVersion')]", + "name": "loadBalancer", + "type": "Microsoft.Network/loadBalancers", + "location": "[variables('location')]", + "dependsOn": [ + "Microsoft.Network/publicIPAddresses/publicIp" + ], + "properties": { + "frontendIPConfigurations": [ + { + "name": "LBFE", + "properties": { + "publicIPAddress": { + "id": "[resourceId('Microsoft.Network/publicIPAddresses','publicIp')]" + } + } + } + ], + "backendAddressPools": [ + { + "name": "LBBAP" + } + ], + "inboundNatRules": [ + { + "name": "rdp", + "properties": { + "frontendIPConfiguration": { + "id": "[concat(resourceId('Microsoft.Network/loadBalancers','loadBalancer'),'/frontendIPConfigurations/LBFE')]" + }, + "protocol": "tcp", + "frontendPort": "[parameters('rdpPort')]", + "backendPort": 3389, + "enableFloatingIP": false + } + } + ] + } + }, + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Network/networkInterfaces", + "name": "[concat(parameters('vmName'),'-nic')]", + "location": "[variables('location')]", + "dependsOn": [ + "[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]", + "Microsoft.Network/loadBalancers/loadBalancer" + ], + "properties": { + "ipConfigurations": [ + { + "name": "ipconfig", + "properties": { + "privateIPAllocationMethod": "Dynamic", + "subnet": { + "id": "[variables('subnet-id')]" + }, + "loadBalancerBackendAddressPools": [ + { + "id": "[concat(resourceId('Microsoft.Network/loadBalancers','loadBalancer'),'/backendAddressPools/LBBAP')]" + } + ], + "loadBalancerInboundNatRules": [ + { + "id": "[concat(resourceId('Microsoft.Network/loadBalancers','loadBalancer'),'/inboundNatRules/rdp')]" + } + ] + } + } + ] + } + }, + { + "apiVersion": "[variables('apiVersion')]", + "type": "Microsoft.Compute/virtualMachines", + "name": "vm", + "location": "[variables('location')]", + "dependsOn": [ + "[resourceId('Microsoft.Storage/storageAccounts',variables('storageAccountName'))]", + "[concat('Microsoft.Network/networkInterfaces/',parameters('vmName'),'-nic')]" + ], + "properties": { + "hardwareProfile": { + "vmSize": "Standard_D2" + }, + "osProfile": { + "computerName": "[parameters('vmName')]", + "adminUsername": "[parameters('adminUsername')]", + "adminPassword": "[parameters('adminPassword')]" + }, + "storageProfile": { + "imageReference": { + "publisher": "[variables('imagePublisher')]", + "offer": "[variables('imageOffer')]", + "sku": "[variables('imageSku')]", + "version": "latest" + }, + "osDisk": { + "name": "osdisk", + "vhd": { + "uri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net/vhds/',parameters('vmName'),'-osdisk.vhd')]" + }, + "caching": "ReadWrite", + "createOption": "FromImage" + } + }, + "networkProfile": { + "networkInterfaces": [ + { + "id": "[resourceId('Microsoft.Network/networkInterfaces',concat(parameters('vmName'),'-nic'))]" + } + ] + }, + "diagnosticsProfile": { + "bootDiagnostics": { + "enabled": "true", + "storageUri": "[concat('http://',variables('storageAccountName'),'.blob.core.windows.net')]" + } + } + } + } + ] +} \ No newline at end of file From 51e62fe317da547dca832ad56a6f655255c93847 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Tue, 29 Mar 2016 15:59:25 +0100 Subject: [PATCH 2/8] fix test names --- src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java index da23390..84a1ac9 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java @@ -107,7 +107,7 @@ public void before() { return; } - if (name.getMethodName().startsWith("deleteCIFromTopology")) { + if (name.getMethodName().startsWith("deleteConvergedInfrastructure")) { if( tm.getProvider().getConvergedInfrastructureServices() != null && tm.getProvider().getConvergedInfrastructureServices().getConvergedInfrastructureSupport() != null ) { testCIId = tm.getTestCIId(DaseinTestManager.REMOVED, true); } @@ -126,7 +126,7 @@ public void after() { * create new CI and verify it. */ @Test - public void createCIFromTopology() throws CloudException, InternalException { + public void createConvergedInfrastructure() throws CloudException, InternalException { ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); if( services == null ) { tm.ok("No converged infrastructure services in this cloud"); @@ -151,7 +151,7 @@ public void createCIFromTopology() throws CloudException, InternalException { * delete a CI */ @Test - public void deleteCIFromTopology() throws CloudException, InternalException { + public void deleteConvergedInfrastructure() throws CloudException, InternalException { ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); if( services == null ) { tm.ok("No converged infrastructure services in this cloud"); From 588c237ebf101e99a28c441cd42b5c0f16d51cb9 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Tue, 5 Apr 2016 12:40:04 +0100 Subject: [PATCH 3/8] improved tests to handle clouds that don't support literal content --- .../org/dasein/cloud/test/ci/CIResources.java | 34 +++++++++------ .../dasein/cloud/test/ci/StatefulCITests.java | 43 ++++++++----------- .../cloud/test/ci/StatelessCITests.java | 12 +++--- 3 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/dasein/cloud/test/ci/CIResources.java b/src/main/java/org/dasein/cloud/test/ci/CIResources.java index e11e3a9..3632dc3 100644 --- a/src/main/java/org/dasein/cloud/test/ci/CIResources.java +++ b/src/main/java/org/dasein/cloud/test/ci/CIResources.java @@ -58,21 +58,34 @@ public class CIResources { private final HashMap testInfrastructures = new HashMap(); - public String getTestTemplateContent() { + public String getTestTemplateContent(boolean supportsLiteralContent) { if (testTemplateContent.equals("")) { - populateTemplateContent(); + if (supportsLiteralContent) { + populateTemplateContent(); + } + else { + //todo get template link/id for clouds that don't support content + testTemplateContent = ""; + } } return testTemplateContent; } - public String getTestParametersContent() { + public String getTestParametersContent(boolean supportsLiteralContent) { if (testParametersContent.equals("")) { - populateTemplateContent(); + if (supportsLiteralContent) { + populateTemplateContent(); + } + else { + //todo get parameter link/id for clouds that don't support content + testParametersContent = ""; + } } return testParametersContent; } public void populateTemplateContent() { + /**************************AZURE RESOURCE MANAGER SPECIFIC***********************/ try { String templateContentFile = "/convergedInfrastructure/templateContent.json"; String parameterContentFile = "/convergedInfrastructure/parameterContent.json"; @@ -222,19 +235,16 @@ String getTestCIId(@Nonnull String label, boolean provisionIfNull) { } } } - boolean supportsTemplateContent = false; + boolean supportsLiteralContent = false; try { Requirement templateContentLaunchRequirement = support.getCapabilities().identifyTemplateContentLaunchRequirement(); - supportsTemplateContent = !templateContentLaunchRequirement.equals(Requirement.NONE); - if ( supportsTemplateContent ) { - populateTemplateContent(); - } else { - //todo get a test template/parameters id for clouds that don't support content - } + supportsLiteralContent = !templateContentLaunchRequirement.equals(Requirement.NONE); + getTestTemplateContent(supportsLiteralContent); + getTestParametersContent(supportsLiteralContent); } catch ( Exception e ) { } ConvergedInfrastructureProvisionOptions options = ConvergedInfrastructureProvisionOptions.getInstance("dsntest-ci" + label, - testResourcePoolId, null, testTemplateContent, testParametersContent, supportsTemplateContent); + testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); String ciId = provisionConvergedInfrastructure(options, label); if ( ciId != null ) { return ciId; diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java index 84a1ac9..5d36f55 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java @@ -63,7 +63,6 @@ static public void cleanUp() { public final TestName name = new TestName(); private String testCIId; - private ConvergedInfrastructureProvisionOptions options; public StatefulCITests() { } @@ -84,29 +83,6 @@ public void before() { } } - String testTemplateContent = "", testParametersContent = ""; - boolean supportsTemplateContent = false; - CIResources ciResources = DaseinTestManager.getCiResources(); - testTemplateContent = ciResources.getTestTemplateContent(); - testParametersContent = ciResources.getTestParametersContent(); - ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); - if ( services != null ) { - ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); - if ( support != null ) { - try { - Requirement templateContentLaunchRequirement = support.getCapabilities().identifyTemplateContentLaunchRequirement(); - supportsTemplateContent = !templateContentLaunchRequirement.equals(Requirement.NONE); - } catch ( Exception e ) {} - } - } - if ( testTemplateContent != null ) { - options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci" + System.currentTimeMillis(), - testResourcePoolId, null, testTemplateContent, testParametersContent, supportsTemplateContent); - } else { - tm.warn("Unable to find converged infrastructure template for testing. Test invalid"); - return; - } - if (name.getMethodName().startsWith("deleteConvergedInfrastructure")) { if( tm.getProvider().getConvergedInfrastructureServices() != null && tm.getProvider().getConvergedInfrastructureServices().getConvergedInfrastructureSupport() != null ) { testCIId = tm.getTestCIId(DaseinTestManager.REMOVED, true); @@ -143,6 +119,25 @@ public void createConvergedInfrastructure() throws CloudException, InternalExcep fail("Unable to find test resource pool id in validateConvergedInfratrcture for cloud which has resource pool requirement"); } } + + String testTemplateContent = "", testParametersContent = ""; + boolean supportsLiteralContent = false; + try { + Requirement templateContentLaunchRequirement = support.getCapabilities().identifyTemplateContentLaunchRequirement(); + supportsLiteralContent = !templateContentLaunchRequirement.equals(Requirement.NONE); + } catch ( Exception e ) {} + CIResources ciResources = DaseinTestManager.getCiResources(); + testTemplateContent = ciResources.getTestTemplateContent(supportsLiteralContent); + testParametersContent = ciResources.getTestParametersContent(supportsLiteralContent); + + ConvergedInfrastructureProvisionOptions options; + if ( testTemplateContent != null ) { + options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci" + System.currentTimeMillis(), + testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); + } else { + tm.warn("Unable to find converged infrastructure template for testing. Test invalid"); + return; + } String result = DaseinTestManager.getCiResources().provisionConvergedInfrastructure(options, DaseinTestManager.STATEFUL); assertNotNull(result); } diff --git a/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java index 3503888..93b205e 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java @@ -97,24 +97,24 @@ public void before() { } String testTemplateContent = "", testParametersContent = ""; - boolean supportsTemplateContent = false; - CIResources ciResources = DaseinTestManager.getCiResources(); - testTemplateContent = ciResources.getTestTemplateContent(); - testParametersContent = ciResources.getTestParametersContent(); + boolean supportsLiteralContent = false; ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); if ( services != null ) { ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); if ( support != null ) { try { Requirement templateContentLaunchRequirement = support.getCapabilities().identifyTemplateContentLaunchRequirement(); - supportsTemplateContent = !templateContentLaunchRequirement.equals(Requirement.NONE); + supportsLiteralContent = !templateContentLaunchRequirement.equals(Requirement.NONE); } catch ( Exception e ) {} } } + CIResources ciResources = DaseinTestManager.getCiResources(); + testTemplateContent = ciResources.getTestTemplateContent(supportsLiteralContent); + testParametersContent = ciResources.getTestParametersContent(supportsLiteralContent); if ( testTemplateContent != null ) { options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci", - testResourcePoolId, null, testTemplateContent, testParametersContent, supportsTemplateContent); + testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); } else { tm.warn("Unable to find converged infrastructure template for testing. Test invalid"); return; From c242c8e186e2a93977a7f24fcf9df085d28e0bdc Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Tue, 5 Apr 2016 14:57:30 +0100 Subject: [PATCH 4/8] integration test for cancelling the deployment of a converged infrastructure resource --- .../dasein/cloud/test/ci/StatefulCITests.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java index 5d36f55..d7e047d 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java @@ -89,6 +89,13 @@ public void before() { } } + else if (name.getMethodName().startsWith("cancelConvergedInfrastructure")) { + + if( tm.getProvider().getConvergedInfrastructureServices() != null && tm.getProvider().getConvergedInfrastructureServices().getConvergedInfrastructureSupport() != null ) { + testCIId = tm.getTestCIId(DaseinTestManager.STATEFUL, true); + } + } + } catch ( Exception e ) { } } @@ -162,4 +169,25 @@ public void deleteConvergedInfrastructure() throws CloudException, InternalExcep support.terminate(testCIId, "die"); } } + + /* + * cancel a currently running CI deployment + */ + @Test + public void cancelConvergedInfrastructure() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + if( services == null ) { + tm.ok("No converged infrastructure services in this cloud"); + return; + } + + ConvergedInfrastructureSupport support = services.getConvergedInfrastructureSupport(); + if( support == null ) { + tm.ok("No CI support in this cloud"); + return; + } + if (testCIId != null) { + support.cancelDeployment(testCIId, "die"); + } + } } \ No newline at end of file From 7d113115fc13341eafe49c330acb51b4e378dec1 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Thu, 7 Apr 2016 10:43:19 +0100 Subject: [PATCH 5/8] make CI tests a bit more generic --- .../org/dasein/cloud/test/ci/CIResources.java | 71 ++++++++++--------- .../dasein/cloud/test/ci/StatefulCITests.java | 1 - 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/dasein/cloud/test/ci/CIResources.java b/src/main/java/org/dasein/cloud/test/ci/CIResources.java index 3632dc3..fb42960 100644 --- a/src/main/java/org/dasein/cloud/test/ci/CIResources.java +++ b/src/main/java/org/dasein/cloud/test/ci/CIResources.java @@ -56,6 +56,9 @@ public class CIResources { private CloudProvider provider; + private String testTemplateContent = ""; + private String testParametersContent = ""; + private final HashMap testInfrastructures = new HashMap(); public String getTestTemplateContent(boolean supportsLiteralContent) { @@ -84,39 +87,39 @@ public String getTestParametersContent(boolean supportsLiteralContent) { return testParametersContent; } - public void populateTemplateContent() { - /**************************AZURE RESOURCE MANAGER SPECIFIC***********************/ - try { - String templateContentFile = "/convergedInfrastructure/templateContent.json"; - String parameterContentFile = "/convergedInfrastructure/parameterContent.json"; - InputStream input = StatelessCITests.class.getResourceAsStream(templateContentFile); - BufferedReader templateReader = new BufferedReader(new InputStreamReader(input)); - StringBuilder templateJson = new StringBuilder(); - String templateLine; - while ((templateLine = templateReader.readLine()) != null) { - templateJson.append(templateLine); - templateJson.append("\n"); - } - testTemplateContent = templateJson.toString(); - - InputStream input2 = StatelessCITests.class.getResourceAsStream(parameterContentFile); - BufferedReader parameterReader = new BufferedReader(new InputStreamReader(input2)); - StringBuilder parameterJson = new StringBuilder(); - String parameterLine; - while ((parameterLine = parameterReader.readLine()) != null) { - parameterJson.append(parameterLine); - parameterJson.append("\n"); - } - testParametersContent = parameterJson.toString(); + private void populateTemplateContent() { + String templateContentFile = null; + String parameterContentFile = null; + if ( provider.getCloudName().equals("Azure") ) { + /**************************AZURE RESOURCE MANAGER SPECIFIC***********************/ + templateContentFile = "/convergedInfrastructure/templateContent.json"; + parameterContentFile = "/convergedInfrastructure/parameterContent.json"; } - catch ( IOException e ) { - logger.warn("Unable to read files for template content: "+e.getMessage()); + if (templateContentFile != null) { + testTemplateContent = getFileAsJsonString(templateContentFile); } + if (parameterContentFile != null) { + testParametersContent = getFileAsJsonString(parameterContentFile); + } } - private String testTemplateContent = ""; - private String testParametersContent = ""; + private String getFileAsJsonString(String fileUri) { + try { + InputStream input = StatelessCITests.class.getResourceAsStream(fileUri); + BufferedReader fileReader = new BufferedReader(new InputStreamReader(input)); + StringBuilder json = new StringBuilder(); + String templateLine; + while ((templateLine = fileReader.readLine()) != null) { + json.append(templateLine); + json.append("\n"); + } + return json.toString(); + } catch ( IOException e ) { + logger.warn("Unable to read files for template content: " + e.getMessage()); + } + return null; + } public CIResources(@Nonnull CloudProvider provider) { this.provider = provider; @@ -243,11 +246,13 @@ String getTestCIId(@Nonnull String label, boolean provisionIfNull) { getTestParametersContent(supportsLiteralContent); } catch ( Exception e ) { } - ConvergedInfrastructureProvisionOptions options = ConvergedInfrastructureProvisionOptions.getInstance("dsntest-ci" + label, - testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); - String ciId = provisionConvergedInfrastructure(options, label); - if ( ciId != null ) { - return ciId; + if (testTemplateContent != null) { + ConvergedInfrastructureProvisionOptions options = ConvergedInfrastructureProvisionOptions.getInstance("dsntest-ci" + label, + testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); + String ciId = provisionConvergedInfrastructure(options, label); + if ( ciId != null ) { + return ciId; + } } } catch ( Throwable ignore ) { return null; diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java index d7e047d..405f64d 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java @@ -87,7 +87,6 @@ public void before() { if( tm.getProvider().getConvergedInfrastructureServices() != null && tm.getProvider().getConvergedInfrastructureServices().getConvergedInfrastructureSupport() != null ) { testCIId = tm.getTestCIId(DaseinTestManager.REMOVED, true); } - } else if (name.getMethodName().startsWith("cancelConvergedInfrastructure")) { From 9dc4aff5d1d34e0728d70f99fb06ba5e60b8292b Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Wed, 13 Apr 2016 10:45:57 +0100 Subject: [PATCH 6/8] fixed nope --- .../java/org/dasein/cloud/test/network/StatefulVpnTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dasein/cloud/test/network/StatefulVpnTests.java b/src/main/java/org/dasein/cloud/test/network/StatefulVpnTests.java index 4d793ad..2e46b2d 100644 --- a/src/main/java/org/dasein/cloud/test/network/StatefulVpnTests.java +++ b/src/main/java/org/dasein/cloud/test/network/StatefulVpnTests.java @@ -166,8 +166,8 @@ public void removeVpn() throws InternalException, CloudException { @Test public void createInternalVpn() throws CloudException, InternalException { - CloudProvider provider = tm.getProvider(); - VpnSupport vpnSupport = provider.getNetworkServices().getVpnSupport(); + assumeNotNull(networkServices); + assumeNotNull(vpnSupport); VpnCapabilities vpnCapabilities = vpnSupport.getCapabilities(); if (null != vpnCapabilities) { From 7d4f9112b0b8673892c51ec477d9d0111022dc13 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Tue, 19 Apr 2016 14:51:44 +0100 Subject: [PATCH 7/8] core updates --- src/main/java/org/dasein/cloud/test/ci/CIResources.java | 2 +- src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java | 2 +- src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/dasein/cloud/test/ci/CIResources.java b/src/main/java/org/dasein/cloud/test/ci/CIResources.java index fb42960..4ea3f43 100644 --- a/src/main/java/org/dasein/cloud/test/ci/CIResources.java +++ b/src/main/java/org/dasein/cloud/test/ci/CIResources.java @@ -248,7 +248,7 @@ String getTestCIId(@Nonnull String label, boolean provisionIfNull) { } if (testTemplateContent != null) { ConvergedInfrastructureProvisionOptions options = ConvergedInfrastructureProvisionOptions.getInstance("dsntest-ci" + label, - testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); + "dsntest-ci description", testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); String ciId = provisionConvergedInfrastructure(options, label); if ( ciId != null ) { return ciId; diff --git a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java index 405f64d..ff41d25 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatefulCITests.java @@ -138,7 +138,7 @@ public void createConvergedInfrastructure() throws CloudException, InternalExcep ConvergedInfrastructureProvisionOptions options; if ( testTemplateContent != null ) { - options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci" + System.currentTimeMillis(), + options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci" + System.currentTimeMillis(), "dsnci-description", testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); } else { tm.warn("Unable to find converged infrastructure template for testing. Test invalid"); diff --git a/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java b/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java index 93b205e..4db17d5 100644 --- a/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java +++ b/src/main/java/org/dasein/cloud/test/ci/StatelessCITests.java @@ -114,7 +114,7 @@ public void before() { if ( testTemplateContent != null ) { options = ConvergedInfrastructureProvisionOptions.getInstance("dsn-ci", - testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); + "dsnci-description", testResourcePoolId, null, testTemplateContent, testParametersContent, supportsLiteralContent); } else { tm.warn("Unable to find converged infrastructure template for testing. Test invalid"); return; From 28b94d727947e940caff8c9a25ef1519a291e050 Mon Sep 17 00:00:00 2001 From: Danielle Mayne Date: Wed, 27 Apr 2016 09:06:40 +0100 Subject: [PATCH 8/8] topology tests --- .../dasein/cloud/test/DaseinTestManager.java | 4 + .../dasein/cloud/test/StatelessTestSuite.java | 4 +- .../org/dasein/cloud/test/ci/CIResources.java | 59 ++++- .../org/dasein/cloud/test/ci/CITestSuite.java | 3 +- .../cloud/test/ci/StatelessTopologyTests.java | 235 ++++++++++++++++++ 5 files changed, 301 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java diff --git a/src/main/java/org/dasein/cloud/test/DaseinTestManager.java b/src/main/java/org/dasein/cloud/test/DaseinTestManager.java index d7022e8..0a1367a 100644 --- a/src/main/java/org/dasein/cloud/test/DaseinTestManager.java +++ b/src/main/java/org/dasein/cloud/test/DaseinTestManager.java @@ -622,6 +622,10 @@ else if( support.getCapabilities().supportsFirewallCreation(true) ) { return (platformResources == null ? null : platformResources.getTestTopicId(label, provisionIfNull)); } + public @Nullable String getTestTopologyId(@Nonnull String label, boolean provisionIfNull) { + return (ciResources == null ? null : ciResources.getTestTopologyId(label, provisionIfNull)); + } + public @Nullable String getTestCIId(@Nonnull String label, boolean provisionIfNull) { return (ciResources == null ? null : ciResources.getTestCIId(label, provisionIfNull)); } diff --git a/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java b/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java index 9f3a305..2781026 100644 --- a/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java +++ b/src/main/java/org/dasein/cloud/test/StatelessTestSuite.java @@ -20,6 +20,7 @@ package org.dasein.cloud.test; import org.dasein.cloud.test.ci.StatelessCITests; +import org.dasein.cloud.test.ci.StatelessTopologyTests; import org.dasein.cloud.test.cloud.StatelessAuthenticationTests; import org.dasein.cloud.test.cloud.StatelessDCTests; import org.dasein.cloud.test.compute.StatelessAffinityGroupTests; @@ -78,7 +79,8 @@ StatelessMonitoringTests.class, StatelessNotificationsTests.class, StatelessVMMonitoringTests.class, - StatelessCITests.class + StatelessCITests.class, + StatelessTopologyTests.class }) public class StatelessTestSuite { } diff --git a/src/main/java/org/dasein/cloud/test/ci/CIResources.java b/src/main/java/org/dasein/cloud/test/ci/CIResources.java index 4ea3f43..60c4d7d 100644 --- a/src/main/java/org/dasein/cloud/test/ci/CIResources.java +++ b/src/main/java/org/dasein/cloud/test/ci/CIResources.java @@ -29,6 +29,8 @@ import org.dasein.cloud.ci.ConvergedInfrastructureServices; import org.dasein.cloud.ci.ConvergedInfrastructureState; import org.dasein.cloud.ci.ConvergedInfrastructureSupport; +import org.dasein.cloud.ci.Topology; +import org.dasein.cloud.ci.TopologySupport; import org.dasein.cloud.dc.DataCenterServices; import org.dasein.cloud.dc.ResourcePool; import org.dasein.cloud.test.DaseinTestManager; @@ -60,6 +62,7 @@ public class CIResources { private String testParametersContent = ""; private final HashMap testInfrastructures = new HashMap(); + private final HashMap testTopologies = new HashMap(); public String getTestTemplateContent(boolean supportsLiteralContent) { if (testTemplateContent.equals("")) { @@ -67,8 +70,7 @@ public String getTestTemplateContent(boolean supportsLiteralContent) { populateTemplateContent(); } else { - //todo get template link/id for clouds that don't support content - testTemplateContent = ""; + testTemplateContent = getTestTopologyId(DaseinTestManager.STATELESS, true); } } return testTemplateContent; @@ -262,6 +264,59 @@ String getTestCIId(@Nonnull String label, boolean provisionIfNull) { return null; } + public @Nullable String getTestTopologyId(@Nonnull String label, boolean provisionIfNull) { + String id = testTopologies.get(label); + if (id == null) { + if ( label.equals(DaseinTestManager.STATELESS) ) { + for (Map.Entry entry : testTopologies.entrySet()) { + if ( !entry.getKey().startsWith(DaseinTestManager.REMOVED) ) { + id = entry.getValue(); + + if ( id != null ) { + return id; + } + } + } + id = findStatelessTopology(); + } + } + + + if( id != null ) { + return id; + } + return null; + } + + private @Nullable String findStatelessTopology() { + ConvergedInfrastructureServices services = provider.getConvergedInfrastructureServices(); + + if( services != null ) { + TopologySupport support = services.getTopologySupport(); + + try { + if( support != null && support.isSubscribed() ) { + Topology defaultTopology = null; + + for( Topology t : support.listTopologies(null) ) { + defaultTopology = t; + break; + } + if( defaultTopology != null ) { + String id = defaultTopology.getProviderTopologyId(); + + testTopologies.put(DaseinTestManager.STATELESS, id); + return id; + } + } + } + catch( Throwable ignore ) { + // ignore + } + } + return null; + } + public int report() { boolean header = false; int count = 0; diff --git a/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java b/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java index 44bedb3..443e650 100644 --- a/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java +++ b/src/main/java/org/dasein/cloud/test/ci/CITestSuite.java @@ -32,7 +32,8 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ StatefulCITests.class, - StatelessCITests.class + StatelessCITests.class, + StatelessTopologyTests.class }) public class CITestSuite { @BeforeClass diff --git a/src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java b/src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java new file mode 100644 index 0000000..02035bb --- /dev/null +++ b/src/main/java/org/dasein/cloud/test/ci/StatelessTopologyTests.java @@ -0,0 +1,235 @@ +/** + * Copyright (C) 2009-2016 Dell, Inc. + * See annotations for authorship information + *

+ * ==================================================================== + * Licensed 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.dasein.cloud.test.ci; + +import org.dasein.cloud.CloudException; +import org.dasein.cloud.InternalException; +import org.dasein.cloud.ci.ConvergedInfrastructureServices; +import org.dasein.cloud.ci.Topology; +import org.dasein.cloud.ci.TopologySupport; +import org.dasein.cloud.test.DaseinTestManager; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; + +import javax.annotation.Nonnull; +import java.util.Date; +import java.util.Map; +import java.util.UUID; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +/** + * Tests support for Dasein Cloud topologies which represent complex, multi-resource templates that can be provisioned into + * running resources. + *

Created by George Reese: 5/31/13 10:57 AM

+ * @author George Reese + * @version 2013.07 initial version + * @since 2013.07 + */ +public class StatelessTopologyTests { + static private DaseinTestManager tm; + + @BeforeClass + static public void configure() { + tm = new DaseinTestManager(StatelessTopologyTests.class); + } + + @AfterClass + static public void cleanUp() { + if( tm != null ) { + tm.close(); + } + } + + @Rule + public final TestName name = new TestName(); + + private String testTopologyId; + + public StatelessTopologyTests() { } + + @Before + public void before() { + tm.begin(name.getMethodName()); + assumeTrue(!tm.isTestSkipped()); + testTopologyId = tm.getTestTopologyId(DaseinTestManager.STATELESS, false); + } + + @After + public void after() { + tm.end(); + } + + private void assertTopology(@Nonnull Topology topology) { + assertNotNull("Topology ID may not be null", topology.getProviderTopologyId()); + assertNotNull("Topology name may not be null", topology.getName()); + assertNotNull("Topology description may not be null", topology.getDescription()); + assertTrue("Topology creation timestamp may not be negative", topology.getCreationTimestamp() >= 0L); + assertNotNull("Topology tags may not be null", topology.getTags()); + assertNotNull("Owner ID may not be null", topology.getProviderOwnerId()); + } + + @Test + public void getBogusTopology() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + + if( services != null ) { + TopologySupport support = services.getTopologySupport(); + + if( support != null ) { + Topology t = support.getTopology(UUID.randomUUID().toString()); + + tm.out("Bogus Topology", t); + assertNull("Bogus topology was supposed to be none, but got a valid topology.", t); + } + else { + tm.ok("No topology support in this cloud"); + } + } + else { + tm.ok("No compute services in this cloud"); + } + } + + @Test + public void getTopology() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + + if( services != null ) { + TopologySupport support = services.getTopologySupport(); + + if( support != null ) { + if( testTopologyId != null ) { + Topology t = support.getTopology(testTopologyId); + + tm.out("Topology", t); + assertNotNull("Failed to find the test topology among possible images", t); + } + else { + if( !support.isSubscribed() ) { + tm.warn("No topology ID was identified, so this test is not valid"); + } + else { + fail("No test topology exists for the getTopology test"); + } + } + } + else { + tm.ok("No topology support in this cloud"); + } + } + else { + tm.ok("No compute services in this cloud"); + } + } + + @Test + public void topologyContent() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + + if( services != null ) { + TopologySupport support = services.getTopologySupport(); + + if( support != null ) { + if( testTopologyId != null ) { + Topology t = support.getTopology(testTopologyId); + + assertNotNull("Failed to find the test topology among possible topologies", t); + tm.out("Topology ID", t.getProviderTopologyId()); + tm.out("Name", t.getName()); + tm.out("Created", new Date(t.getCreationTimestamp())); + tm.out("Owner Account", t.getProviderOwnerId()); + tm.out("Region ID", t.getProviderRegionId()); + tm.out("Data Center ID", t.getProviderDataCenterId()); + + Map tags = t.getTags(); + + //noinspection ConstantConditions + if( tags != null ) { + for( Map.Entry entry : tags.entrySet() ) { + tm.out("Tag " + entry.getKey(), entry.getValue()); + } + } + + tm.out("Description", t.getDescription()); + + assertTopology(t); + + } + else { + if( !support.isSubscribed() ) { + tm.warn("No topology ID was identified, so this test is not valid"); + } + else { + fail("No test topology exists for the topologyContent test"); + } + } + } + else { + tm.ok("No topology support in this cloud"); + } + } + else { + tm.ok("No compute services in this cloud"); + } + } + + @Test + public void listPrivateTopologies() throws CloudException, InternalException { + ConvergedInfrastructureServices services = tm.getProvider().getConvergedInfrastructureServices(); + + if( services != null ) { + TopologySupport support = services.getTopologySupport(); + + if( support != null ) { + Iterable topologies = support.listTopologies(null); + int count = 0; + + assertNotNull("listTopologies() must return a non-null list of topologies even if a private library is not supported", topologies); + for( Topology t : topologies ) { + count++; + tm.out("Topology", t); + } + tm.out("Total Topology Count", count); + for( Topology t : topologies ) { + assertTopology(t); + } + if( count < 1 ) { + tm.warn("No topologies were provided so this test may not be valid"); + } + } + else { + tm.ok("No topology support in this cloud"); + } + } + else { + tm.ok("No compute services in this cloud"); + } + } +} \ No newline at end of file