Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
Eutester4J test refactorings and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeckham committed Mar 27, 2015
1 parent 40a617d commit 8316a00
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 109 deletions.
1 change: 0 additions & 1 deletion eutester4j/com/eucalyptus/tests/awssdk/Eutester4j.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.net.InetAddress;

class Eutester4j {

Expand Down
106 changes: 52 additions & 54 deletions eutester4j/com/eucalyptus/tests/awssdk/TestAutoScalingEC2VPC.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.eucalyptus.tests.awssdk

import com.amazonaws.auth.AWSCredentials
import com.amazonaws.auth.AWSCredentialsProvider
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.internal.StaticCredentialsProvider
import com.amazonaws.services.autoscaling.AmazonAutoScaling
import com.amazonaws.services.autoscaling.AmazonAutoScalingClient
import com.amazonaws.services.autoscaling.model.CreateAutoScalingGroupRequest
Expand All @@ -25,6 +26,13 @@ import com.amazonaws.services.ec2.model.DescribeImagesRequest
import com.amazonaws.services.ec2.model.DetachInternetGatewayRequest
import com.amazonaws.services.ec2.model.Filter

import org.testng.annotations.Test;

import static com.eucalyptus.tests.awssdk.Eutester4j.ACCESS_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.HOST_IP
import static com.eucalyptus.tests.awssdk.Eutester4j.SECRET_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit

/**
* This application tests Auto Scaling use of EC2 VPC functionality.
*
Expand All @@ -35,44 +43,33 @@ import com.amazonaws.services.ec2.model.Filter
class TestAutoscalingEC2VPC {

private final String host;
private final String accessKey;
private final String secretKey;
private final AWSCredentialsProvider credentials

public static void main( String[] args ) throws Exception {
final TestAutoscalingEC2VPC test = new TestAutoscalingEC2VPC(
'10.111.5.64',
'AKI4YB4UYR1BRFUYPGHO',
'JbvmaFyUjehb56LOV0lmcUe3Tbc2LM5nIyWO6wDP'
);
final TestAutoscalingEC2VPC test = new TestAutoscalingEC2VPC();
test.test();
}

public TestAutoscalingEC2VPC( final String host,
final String accessKey,
final String secretKey ) {
this.host = host;
this.accessKey = accessKey;
this.secretKey = secretKey;
}

private AWSCredentials credentials() {
return new BasicAWSCredentials( accessKey, secretKey );
public TestAutoscalingEC2VPC() {
minimalInit()
this.host = HOST_IP;
this.credentials = new StaticCredentialsProvider( new BasicAWSCredentials( ACCESS_KEY, SECRET_KEY ) )
}

private String cloudUri( String servicePath ) {
URI.create( "http://" + host + ":8773/" )
.resolve( servicePath )
.toString()
.resolve( servicePath )
.toString()
}

private AmazonAutoScaling getAutoScalingClient( ) {
final AmazonAutoScaling asc = new AmazonAutoScalingClient( credentials( ) )
final AmazonAutoScaling asc = new AmazonAutoScalingClient( credentials )
asc.setEndpoint( cloudUri( "/services/AutoScaling/" ) )
asc
}

private AmazonEC2 getEc2Client( ) {
final AmazonEC2 ec2 = new AmazonEC2Client( credentials() )
final AmazonEC2 ec2 = new AmazonEC2Client( credentials )
ec2.setEndpoint( cloudUri( "/services/compute/" ) )
ec2
}
Expand All @@ -90,15 +87,16 @@ class TestAutoscalingEC2VPC {
System.out.println( text )
}

@Test
public void test() throws Exception{
final AmazonEC2 ec2 = getEc2Client()

// Find an image to use
final String imageId = ec2.describeImages( new DescribeImagesRequest(
filters: [
new Filter( name: "image-type", values: ["machine"] ),
new Filter( name: "root-device-type", values: ["instance-store"] ),
]
filters: [
new Filter( name: "image-type", values: ["machine"] ),
new Filter( name: "root-device-type", values: ["instance-store"] ),
]
) ).with {
images?.getAt( 0 )?.imageId
}
Expand All @@ -121,7 +119,7 @@ class TestAutoscalingEC2VPC {
// Create VPC to use
print('Creating VPC')
final String vpcId = createVpc(new CreateVpcRequest(
cidrBlock: '10.0.0.0/24'
cidrBlock: '10.0.0.0/24'
)).with {
vpc?.vpcId
}
Expand All @@ -145,14 +143,14 @@ class TestAutoscalingEC2VPC {

print("Attaching internet gateway ${internetGatewayId} to vpc ${vpcId}")
attachInternetGateway(new AttachInternetGatewayRequest(
internetGatewayId: internetGatewayId,
vpcId: vpcId
internetGatewayId: internetGatewayId,
vpcId: vpcId
))
cleanupTasks.add {
print("Detaching internet gateway ${internetGatewayId} from vpc ${vpcId}")
detachInternetGateway(new DetachInternetGatewayRequest(
internetGatewayId: internetGatewayId,
vpcId: vpcId
internetGatewayId: internetGatewayId,
vpcId: vpcId
))
}
vpcId
Expand All @@ -176,9 +174,9 @@ class TestAutoscalingEC2VPC {
final String securityGroupName = namePrefix + "EC2VPCTest"
print( "Creating a security group for test use: " + securityGroupName )
final String groupId = ec2.createSecurityGroup( new CreateSecurityGroupRequest(
groupName: securityGroupName,
description: securityGroupName,
vpcId: vpcId
groupName: securityGroupName,
description: securityGroupName,
vpcId: vpcId
) ).with {
groupId
}
Expand All @@ -201,23 +199,23 @@ class TestAutoscalingEC2VPC {
// Create launch configuration
print( "Creating launch configuration: " + configName )
createLaunchConfiguration( new CreateLaunchConfigurationRequest(
launchConfigurationName: configName,
imageId: imageId,
keyName: keyName,
securityGroups: [ groupId ],
instanceType: instanceType( ),
associatePublicIpAddress: true
launchConfigurationName: configName,
imageId: imageId,
keyName: keyName,
securityGroups: [ groupId ],
instanceType: instanceType( ),
associatePublicIpAddress: true
) )

print( "Verifying launch configuration public IP address association setting" )
describeLaunchConfigurations( new DescribeLaunchConfigurationsRequest(
launchConfigurationNames: [ configName ]
launchConfigurationNames: [ configName ]
) ).with {
assertThat( launchConfigurations != null && launchConfigurations.size()==1,
"Expected one launch configuration, but was: ${launchConfigurations?.size()}")
"Expected one launch configuration, but was: ${launchConfigurations?.size()}")
launchConfigurations[0].with {
assertThat( associatePublicIpAddress,
"Expected associatePublicIpAddress true, but was: ${associatePublicIpAddress}" )
"Expected associatePublicIpAddress true, but was: ${associatePublicIpAddress}" )
}
}

Expand All @@ -226,31 +224,31 @@ class TestAutoscalingEC2VPC {
cleanupTasks.add{
print( "Deleting group: " + groupName )
deleteAutoScalingGroup( new DeleteAutoScalingGroupRequest(
autoScalingGroupName: groupName,
forceDelete: true
autoScalingGroupName: groupName,
forceDelete: true
) )
}

// Create scaling group
print( "Creating auto scaling group: " + groupName )
createAutoScalingGroup( new CreateAutoScalingGroupRequest(
autoScalingGroupName: groupName,
launchConfigurationName: configName,
desiredCapacity: 0,
minSize: 0,
maxSize: 0,
VPCZoneIdentifier: subnetId
autoScalingGroupName: groupName,
launchConfigurationName: configName,
desiredCapacity: 0,
minSize: 0,
maxSize: 0,
VPCZoneIdentifier: subnetId
) )

print( "Verifying auto scaling group vpc zone identifier setting" )
describeAutoScalingGroups( new DescribeAutoScalingGroupsRequest(
autoScalingGroupNames: [ groupName ]
autoScalingGroupNames: [ groupName ]
) ).with {
assertThat( autoScalingGroups != null && autoScalingGroups.size()==1,
"Expected one auto scaling group, but was: ${autoScalingGroups?.size()}")
"Expected one auto scaling group, but was: ${autoScalingGroups?.size()}")
autoScalingGroups[0].with {
assertThat( VPCZoneIdentifier == subnetId,
"Expected vpc zone identifier ${subnetId}, but was: ${VPCZoneIdentifier}" )
"Expected vpc zone identifier ${subnetId}, but was: ${VPCZoneIdentifier}" )
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.testng.annotations.Test;

import static com.eucalyptus.tests.awssdk.Eutester4j.ACCESS_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.EC2_ENDPOINT
import static com.eucalyptus.tests.awssdk.Eutester4j.HOST_IP
import static com.eucalyptus.tests.awssdk.Eutester4j.SECRET_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit

Expand All @@ -23,7 +22,6 @@ import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit
*/
class TestEC2VPCModifyInstanceSecurityGroups {

private final String host;
private final AWSCredentialsProvider credentials

public static void main( String[] args ) throws Exception {
Expand All @@ -36,12 +34,6 @@ class TestEC2VPCModifyInstanceSecurityGroups {
this.credentials = new StaticCredentialsProvider( new BasicAWSCredentials( ACCESS_KEY, SECRET_KEY ) )
}

// private String cloudUri( String servicePath ) {
// URI.create( "http://" + host + ":8773/" )
// .resolve( servicePath )
// .toString()
// }

private AmazonEC2 getEC2Client( final AWSCredentialsProvider credentials ) {
final AmazonEC2 ec2 = new AmazonEC2Client( credentials )
ec2.setEndpoint( EC2_ENDPOINT )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit
*/
class TestEC2VPCNetworkAclEntryManagement {

private final String host;
private final AWSCredentialsProvider credentials
private final AWSCredentialsProvider credentials


public static void main( String[] args ) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.testng.annotations.Test;

import static com.eucalyptus.tests.awssdk.Eutester4j.ACCESS_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.HOST_IP
import static com.eucalyptus.tests.awssdk.Eutester4j.EC2_ENDPOINT
import static com.eucalyptus.tests.awssdk.Eutester4j.SECRET_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit

Expand All @@ -32,7 +33,7 @@ import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit
*/
class TestEC2VPCResourceConditionPolicy {

private final String host
private final String host;
private final AWSCredentialsProvider credentials

public static void main( String[] args ) throws Exception {
Expand All @@ -41,7 +42,7 @@ class TestEC2VPCResourceConditionPolicy {

public TestEC2VPCResourceConditionPolicy() {
minimalInit()

this.host=HOST_IP
this.credentials = new StaticCredentialsProvider( new BasicAWSCredentials( ACCESS_KEY, SECRET_KEY ) )
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ import com.amazonaws.services.ec2.model.*

import org.testng.annotations.Test

import static com.eucalyptus.tests.awssdk.Eutester4j.*
import static com.eucalyptus.tests.awssdk.Eutester4j.ACCESS_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.HOST_IP
import static com.eucalyptus.tests.awssdk.Eutester4j.SECRET_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit

/**
* This application tests EC2 VPC security group functionality.
Expand All @@ -44,30 +47,31 @@ import static com.eucalyptus.tests.awssdk.Eutester4j.*
*/
class TestEC2VPCSecurityGroupsInstancesAttributes {

// private final String host
private final String host
private final AWSCredentialsProvider credentials
private final List<String> imageOwners

public static void main( String[] args ) throws Exception {
new TestEC2VPCSecurityGroupsInstancesAttributes( null ).test( )
new TestEC2VPCSecurityGroupsInstancesAttributes( ).test( )
}

public TestEC2VPCSecurityGroupsInstancesAttributes(List<String> imageOwners ) {
public TestEC2VPCSecurityGroupsInstancesAttributes() {
minimalInit()
this.host=HOST_IP
this.credentials = new StaticCredentialsProvider(new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY))
this.imageOwners = imageOwners
this.imageOwners = imageOwners
}

// private String cloudUri( String servicePath ) {
// URI.create( "http://" + host + ":8773/" )
// .resolve( servicePath )
// .toString()
// }
private String cloudUri( String servicePath ) {
URI.create( "http://" + host + ":8773/" )
.resolve( servicePath )
.toString()
}

private AmazonEC2 getEC2Client( final AWSCredentialsProvider credentials ) {
final AmazonEC2 ec2 = new AmazonEC2Client( credentials )
if ( host ) {
ec2.setEndpoint( EC2_ENDPOINT )
ec2.setEndpoint( cloudUri("/services/compute") )
} else {
ec2.setRegion( com.amazonaws.regions.Region.getRegion( Regions.US_WEST_1 ) )
}
Expand All @@ -83,7 +87,8 @@ class TestEC2VPCSecurityGroupsInstancesAttributes {
private void print( String text ) {
System.out.println( text )
}
@Test

@Test
public void test( ) throws Exception {
final AmazonEC2 ec2 = getEC2Client( credentials )

Expand All @@ -98,8 +103,6 @@ class TestEC2VPCSecurityGroupsInstancesAttributes {
new Filter( name: "root-device-type", values: ["instance-store"] ),
new Filter( name: "is-public", values: ["true"] ),
new Filter( name: "virtualization-type", values: ["hvm"] ),
// new Filter( name: "description", values: ["*Linux*"] ),
// new Filter( name: "name", values: ["amzn-*"] ),
]
) ).with {
images?.getAt( 0 )?.with {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.amazonaws.services.ec2.model.*
import org.testng.annotations.Test;

import static com.eucalyptus.tests.awssdk.Eutester4j.ACCESS_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.HOST_IP
import static com.eucalyptus.tests.awssdk.Eutester4j.EC2_ENDPOINT
import static com.eucalyptus.tests.awssdk.Eutester4j.SECRET_KEY
import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit

Expand All @@ -22,7 +22,6 @@ import static com.eucalyptus.tests.awssdk.Eutester4j.minimalInit
*/
class TestEC2VPCStartStop {

private final String host
private final AWSCredentialsProvider credentials
private final String cidrPrefix = '172.26.64'

Expand All @@ -32,16 +31,9 @@ class TestEC2VPCStartStop {

public TestEC2VPCStartStop( ) {
minimalInit()

this.credentials = new StaticCredentialsProvider( new BasicAWSCredentials( ACCESS_KEY, SECRET_KEY ) )
}

private String cloudUri( String servicePath ) {
URI.create( "http://" + host + ":8773/" )
.resolve( servicePath )
.toString()
}

private AmazonEC2 getEC2Client( final AWSCredentialsProvider credentials ) {
final AmazonEC2 ec2 = new AmazonEC2Client( credentials )
ec2.setEndpoint( EC2_ENDPOINT )
Expand Down
Loading

0 comments on commit 8316a00

Please sign in to comment.