diff --git a/test/e2e/aws_test.go b/test/e2e/aws_test.go index deb264b74..ff08da812 100644 --- a/test/e2e/aws_test.go +++ b/test/e2e/aws_test.go @@ -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) } diff --git a/test/provisioner/provision_aws.go b/test/provisioner/provision_aws.go index c24c76370..c74d1d57d 100644 --- a/test/provisioner/provision_aws.go +++ b/test/provisioner/provision_aws.go @@ -37,6 +37,8 @@ const ( EksVersion = "1.26" ) +var AWSProps = &AWSProvisioner{} + func init() { // Add this implementation to the list of provisioners. newProvisionerFunctions["aws"] = NewAWSProvisioner @@ -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), @@ -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 {