Skip to content

Commit

Permalink
test/e2e: enable tests for AWS
Browse files Browse the repository at this point in the history
Implemented the CloudAssert interface for AWS.

The following tests are enabled and passing:

 TestAwsCreateSimplePod
 TestAwsCreatePeerPodWithJob
 TestAwsCreatePeerPodAndCheckUserLogs
 TestAwsCreatePeerPodAndCheckWorkDirLogs
 TestAwsCreatePeerPodAndCheckEnvVariableLogsWithImageOnly
 TestAwsCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly
 TestAwsCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment
 TestAwsCreatePeerPodWithLargeImage
 TestAwsDeletePod

Those three are not passing, so kept them disabled:
 TestAwsCreatePodWithConfigMap
 TestAwsCreatePodWithSecret
 TestAwsCreatePeerPodContainerWithExternalIPAccess

And finally the following tests seem more complex and might require
changes, so I did not check whether they are passing or not:

 TestAwsCreatePeerPodWithPVC
 TestAwsCreatePeerPodWithAuthenticatedImagewithValidCredentials
 TestAwsCreatePeerPodWithAuthenticatedImageWithInvalidCredentials
 TestAwsCreatePeerPodWithAuthenticatedImageWithoutCredentials

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
  • Loading branch information
wainersm committed Oct 2, 2023
1 parent d942628 commit 7f29523
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 3 deletions.
139 changes: 138 additions & 1 deletion test/e2e/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,154 @@
package e2e

import (
"context"
"strings"
"testing"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/ec2"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
pv "github.com/confidential-containers/cloud-api-adaptor/test/provisioner"
)

// AWSAssert implements the CloudAssert interface.
type AWSAssert struct {
Vpc *pv.Vpc
}

func NewAWSAssert() AWSAssert {
return AWSAssert{
Vpc: pv.AWSProps.Vpc,
}
}

func (aa AWSAssert) HasPodVM(t *testing.T, id string) {
// The `id` parameter is not the instance ID but rather the pod's name, so
// it will need to scan all running pods on the subnet to find one that
// starts with the prefix.
podvmPrefix := "podvm-" + id

describeInstances, err := aa.Vpc.Client.DescribeInstances(context.TODO(),
&ec2.DescribeInstancesInput{
Filters: []ec2types.Filter{
{
Name: aws.String("subnet-id"),
Values: []string{aa.Vpc.SubnetId},
},
},
})
if err != nil {
t.Errorf("Podvm name=%s not found: %v", id, err)
}

found := false
for _, reservation := range describeInstances.Reservations {
for _, instance := range reservation.Instances {
// Code == 48 (terminated)
// Some podvm from previous tests might be on terminated stage
// so let's ignore them.
if instance.State.Code != aws.Int32(48) {
for _, tag := range instance.Tags {
if *tag.Key == "Name" &&
strings.HasPrefix(*tag.Value, podvmPrefix) {
found = true
}
}
}
}
}

if !found {
t.Errorf("Podvm name=%s not found", id)
}
}

func TestAwsCreateSimplePod(t *testing.T) {
assert := NewAWSAssert()

doTestCreateSimplePod(t, assert)
}

func TestAwsCreatePodWithConfigMap(t *testing.T) {
t.Skip("Test not passing")
assert := NewAWSAssert()

doTestCreatePodWithConfigMap(t, assert)
}

func TestAwsCreatePodWithSecret(t *testing.T) {
t.Skip("Test not passing")
assert := NewAWSAssert()

doTestCreatePodWithSecret(t, assert)
}

func TestAwsCreatePeerPodContainerWithExternalIPAccess(t *testing.T) {
t.Skip("Test not passing")
assert := NewAWSAssert()

doTestCreatePeerPodContainerWithExternalIPAccess(t, assert)
}

func TestAwsCreatePeerPodWithJob(t *testing.T) {
assert := NewAWSAssert()

doTestCreatePeerPodWithJob(t, assert)
}

func TestAwsCreatePeerPodAndCheckUserLogs(t *testing.T) {
assert := NewAWSAssert()

doTestCreatePeerPodAndCheckUserLogs(t, assert)
}

func TestAWSCreateSimplePod(t *testing.T) {
func TestAwsCreatePeerPodAndCheckWorkDirLogs(t *testing.T) {
assert := NewAWSAssert()

doTestCreatePeerPodAndCheckWorkDirLogs(t, assert)
}

func TestAwsCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t *testing.T) {
assert := NewAWSAssert()

doTestCreatePeerPodAndCheckEnvVariableLogsWithImageOnly(t, assert)
}

func TestAwsCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t *testing.T) {
assert := NewAWSAssert()

doTestCreatePeerPodAndCheckEnvVariableLogsWithDeploymentOnly(t, assert)
}

func TestAwsCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t *testing.T) {
assert := NewAWSAssert()

doTestCreatePeerPodAndCheckEnvVariableLogsWithImageAndDeployment(t, assert)
}

func TestAwsCreatePeerPodWithLargeImage(t *testing.T) {
assert := NewAWSAssert()

doTestCreatePeerPodWithLargeImage(t, assert)
}

func TestAwsCreatePeerPodWithPVC(t *testing.T) {
t.Skip("To be implemented")
}

func TestAwsCreatePeerPodWithAuthenticatedImagewithValidCredentials(t *testing.T) {
t.Skip("To be implemented")
}

func TestAwsCreatePeerPodWithAuthenticatedImageWithInvalidCredentials(t *testing.T) {
t.Skip("To be implemented")
}

func TestAwsCreatePeerPodWithAuthenticatedImageWithoutCredentials(t *testing.T) {
t.Skip("To be implemented")
}

func TestAwsDeletePod(t *testing.T) {
assert := NewAWSAssert()
doTestDeleteSimplePod(t, assert)
}
8 changes: 6 additions & 2 deletions test/provisioner/provision_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
EksVersion = "1.26"
)

var AWSProps = &AWSProvisioner{}

func init() {
// Add this implementation to the list of provisioners.
newProvisionerFunctions["aws"] = NewAWSProvisioner
Expand Down Expand Up @@ -150,7 +152,7 @@ func NewAWSProvisioner(properties map[string]string) (CloudProvisioner, error) {
properties["cluster_type"])
}

return &AWSProvisioner{
AWSProps = &AWSProvisioner{
AwsConfig: cfg,
iamClient: iam.NewFromConfig(cfg),
ec2Client: ec2.NewFromConfig(cfg),
Expand All @@ -166,7 +168,9 @@ func NewAWSProvisioner(properties map[string]string) (CloudProvisioner, error) {
Vpc: vpc,
VxlanPort: properties["vxlan_port"],
SshKpName: properties["ssh_kp_name"],
}, nil
}

return AWSProps, nil
}

func (a *AWSProvisioner) CreateCluster(ctx context.Context, cfg *envconf.Config) error {
Expand Down

0 comments on commit 7f29523

Please sign in to comment.