Skip to content

Commit

Permalink
Fix failing drivertest
Browse files Browse the repository at this point in the history
  • Loading branch information
mvach committed Nov 30, 2023
1 parent fa0cf9a commit 7747a1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 7 additions & 7 deletions driver/copy_ami_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

var _ = Describe("CopyAmiDriver", func() {
It("copies an existing AMI to a new region while preserving its properties", func() {
copyAmi(false, "", func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
copyAmi(false, "", amiFixtureID, func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
snapshotIDptr := getSnapshotID(reqOutput)

snapshotAttributes, err := ec2Client.DescribeSnapshotAttribute(&ec2.DescribeSnapshotAttributeInput{
Expand All @@ -34,7 +34,7 @@ var _ = Describe("CopyAmiDriver", func() {

Context("when encrypted flag is set to true", func() {
It("does NOT make snapshot public", func() {
copyAmi(true, "", func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
copyAmi(true, "", amiFixtureID, func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
snapshotIDptr := getSnapshotID(reqOutput)

snapshotAttributes, err := ec2Client.DescribeSnapshotAttribute(&ec2.DescribeSnapshotAttributeInput{
Expand All @@ -48,7 +48,7 @@ var _ = Describe("CopyAmiDriver", func() {
})

It("encrypts destination AMI using default AWS KMS key", func() {
copyAmi(true, "", func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
copyAmi(true, "", amiFixtureID, func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
respSnapshots, err := ec2Client.DescribeSnapshots(&ec2.DescribeSnapshotsInput{SnapshotIds: []*string{reqOutput.Images[0].BlockDeviceMappings[0].Ebs.SnapshotId}})
Expect(err).ToNot(HaveOccurred())

Expand All @@ -58,7 +58,7 @@ var _ = Describe("CopyAmiDriver", func() {

Context("when kms_key_id is provided", func() {
It("encrypts destination AMI using provided kms key", func() {
copyAmi(true, kmsKeyId, func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
copyAmi(true, kmsKeyId, amiFixtureID, func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
respSnapshots, err := ec2Client.DescribeSnapshots(&ec2.DescribeSnapshotsInput{SnapshotIds: []*string{reqOutput.Images[0].BlockDeviceMappings[0].Ebs.SnapshotId}})
Expect(err).ToNot(HaveOccurred())

Expand All @@ -71,7 +71,7 @@ var _ = Describe("CopyAmiDriver", func() {

Context("when shared_with_accounts is provided", func() {
It("shares the AMI with other accounts", func() {
copyAmi(true, kmsKeyId, func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
copyAmi(true, multiregionKmsKeyId, privateAmiFixtureID, func(ec2Client *ec2.EC2, reqOutput *ec2.DescribeImagesOutput) {
attribute := "launchPermission"
output, err := ec2Client.DescribeImageAttribute(&ec2.DescribeImageAttributeInput{
ImageId: reqOutput.Images[0].ImageId,
Expand All @@ -84,7 +84,7 @@ var _ = Describe("CopyAmiDriver", func() {
})
})

func copyAmi(encrypted bool, kmsKeyId string, cb ...func(*ec2.EC2, *ec2.DescribeImagesOutput)) {
func copyAmi(encrypted bool, kmsKeyId string, amiId string, cb ...func(*ec2.EC2, *ec2.DescribeImagesOutput)) {
accessibility := resources.PublicAmiAccessibility
if encrypted {
accessibility = resources.PrivateAmiAccessibility
Expand All @@ -98,7 +98,7 @@ func copyAmi(encrypted bool, kmsKeyId string, cb ...func(*ec2.EC2, *ec2.Describe
}

amiDriverConfig := resources.AmiDriverConfig{
ExistingAmiID: amiFixtureID,
ExistingAmiID: amiId,
DestinationRegion: destinationRegion,
AmiProperties: resources.AmiProperties{
Name: fmt.Sprintf("BOSH-%s", strings.ToUpper(uuid.NewV4().String())),
Expand Down
11 changes: 9 additions & 2 deletions driver/driver_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ var ebsVolumeID, ebsSnapshotID string
var machineImagePath, machineImageFormat string
var s3MachineImageUrl, s3MachineImageFormat string

var kmsKeyId string
var kmsKeyId, multiregionKmsKeyId string

var awsAccount string

var amiFixtureID string
var amiFixtureID, privateAmiFixtureID string

func TestDrivers(t *testing.T) {
RegisterFailHandler(Fail)
Expand Down Expand Up @@ -70,10 +70,17 @@ var _ = SynchronizedBeforeSuite(
amiFixtureID = os.Getenv("AMI_FIXTURE_ID")
Expect(amiFixtureID).ToNot(BeEmpty(), "AMI_FIXTURE_ID must be set")

// private AMI fixture
privateAmiFixtureID = os.Getenv("PRIVATE_AMI_FIXTURE_ID")
Expect(amiFixtureID).ToNot(BeEmpty(), "PRIVATE_AMI_FIXTURE_ID must be set")

// KMS Key info
kmsKeyId = os.Getenv("AWS_KMS_KEY_ID")
Expect(kmsKeyId).ToNot(BeEmpty(), "AWS_KMS_KEY_ID must be set")

multiregionKmsKeyId = os.Getenv("MULTI_REGION_AWS_KMS_KEY_ID")
Expect(multiregionKmsKeyId).ToNot(BeEmpty(), "MULTI_REGION_AWS_KMS_KEY_ID must be set")

awsAccount = os.Getenv("AWS_ACCOUNT")
Expect(awsAccount).ToNot(BeEmpty(), "AWS_ACCOUNT must be set")
},
Expand Down
2 changes: 1 addition & 1 deletion driver/kms_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var _ = Describe("KmsDriver", func() {

It("replicates a given kms key to another region", func() {
driverConfig := resources.KmsReplicateKeyDriverConfig{
KmsKeyId: kmsKeyId,
KmsKeyId: multiregionKmsKeyId,
SourceRegion: creds.Region,
TargetRegion: destinationRegion,
}
Expand Down

0 comments on commit 7747a1d

Please sign in to comment.