Skip to content

Commit

Permalink
Validate subnet and availability zone in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
spangenberg committed Nov 6, 2018
1 parent 2de9c39 commit 205838d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/machines/awsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,25 @@ func (client *awsClientWrapper) GetTags(machine *clusterv1alpha1.Machine) (map[s
}
return tags, nil
}

func (client *awsClientWrapper) GetSubnet(machine *clusterv1alpha1.Machine) (string, error) {
instance, err := machineutils.GetRunningInstance(machine, client.client)
if err != nil {
return "", err
}
if instance.SubnetId == nil {
return "", err
}
return *instance.SubnetId, nil
}

func (client *awsClientWrapper) GetAvailabilityZone(machine *clusterv1alpha1.Machine) (string, error) {
instance, err := machineutils.GetRunningInstance(machine, client.client)
if err != nil {
return "", err
}
if instance.Placement == nil {
return "", err
}
return *instance.Placement.AvailabilityZone, nil
}
35 changes: 35 additions & 0 deletions test/machines/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"

awsclient "sigs.k8s.io/cluster-api-provider-aws/pkg/cloud/aws/client"
)

Expand Down Expand Up @@ -132,6 +135,38 @@ var _ = framework.SigKubeDescribe("Machines", func() {
f.CreateMachineAndWait(testMachine, acw)
machinesToDelete.AddMachine(testMachine, f, acw)

var subnetID string
{
describeSubnetsInput := &ec2.DescribeSubnetsInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag:Name"),
Values: []*string{
aws.String(fmt.Sprintf("%s-*", clusterID)),
},
},
{
Name: aws.String("availabilityZone"),
Values: []*string{
aws.String("us-east-1a"),
},
},
},
}
describeSubnetsResult, err := awsClient.DescribeSubnets(describeSubnetsInput)
Expect(err).NotTo(HaveOccurred())
Expect(len(describeSubnetsResult.Subnets)).
To(Equal(1), "Test criteria not met. Only one Subnet should match the given Tag.")
subnetID = *describeSubnetsResult.Subnets[0].SubnetId
}
subnet, err := acw.GetSubnet(testMachine)
Expect(err).NotTo(HaveOccurred())
Expect(subnet).To(Equal(subnetID))

availabilityZone, err := acw.GetAvailabilityZone(testMachine)
Expect(err).NotTo(HaveOccurred())
Expect(availabilityZone).To(Equal("us-east-1a"))

securityGroups, err := acw.GetSecurityGroups(testMachine)
Expect(err).NotTo(HaveOccurred())
Expect(securityGroups).To(Equal([]string{fmt.Sprintf("%s-default", clusterID)}))
Expand Down

0 comments on commit 205838d

Please sign in to comment.