Skip to content

Commit

Permalink
Prevent flaky copy_ami_driver tests
Browse files Browse the repository at this point in the history
Currently copy_ami_driver_test depends on the kms_driver_test since the
kms_driver_test replicates a key that is used in the copy_ami_driver_test
This can result in flakey tests.
  • Loading branch information
mvach committed Dec 6, 2023
1 parent f55e385 commit 0928693
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions driver/copy_ami_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var _ = Describe("CopyAmiDriver", func() {

Context("when kms_key_id is provided", func() {
It("encrypts destination AMI using the kms key in the destination region", func() {
destinationRegionKmsKeyId := strings.Replace(multiregionKmsKeyId, creds.Region, destinationRegion, 1)
destinationRegionKmsKeyId := strings.ReplaceAll(multiRegionKey, creds.Region, destinationRegion)
copyAmi(
AmiCopyConfig{
amiId: privateAmiFixtureID,
Expand All @@ -102,7 +102,7 @@ var _ = Describe("CopyAmiDriver", func() {

Context("when shared_with_accounts is provided", func() {
It("shares the AMI with other accounts", func() {
destinationRegionKmsKeyId := strings.Replace(multiregionKmsKeyId, creds.Region, destinationRegion, 1)
destinationRegionKmsKeyId := strings.ReplaceAll(multiRegionKey, creds.Region, destinationRegion)
copyAmi(AmiCopyConfig{
amiId: privateAmiFixtureID,
encrypted: true,
Expand Down
9 changes: 6 additions & 3 deletions driver/driver_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var ebsVolumeID, ebsSnapshotID string
var machineImagePath, machineImageFormat string
var s3MachineImageUrl, s3MachineImageFormat string

var kmsKeyId, multiregionKmsKeyId string
var kmsKeyId, multiRegionKey, multiRegionKeyReplicationTest string

var awsAccount string

Expand Down Expand Up @@ -78,8 +78,11 @@ var _ = SynchronizedBeforeSuite(
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")
multiRegionKey = os.Getenv("MULTI_REGION_KEY")
Expect(multiRegionKey).ToNot(BeEmpty(), "MULTI_REGION_KEY must be set")

multiRegionKeyReplicationTest = os.Getenv("MULTI_REGION_KEY_REPLICATION_TEST")
Expect(multiRegionKeyReplicationTest).ToNot(BeEmpty(), "MULTI_REGION_KEY_REPLICATION_TEST must be set")

awsAccount = os.Getenv("AWS_ACCOUNT")
Expect(awsAccount).ToNot(BeEmpty(), "AWS_ACCOUNT must be set")
Expand Down
4 changes: 2 additions & 2 deletions 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: multiregionKmsKeyId,
KmsKeyId: multiRegionKeyReplicationTest,
SourceRegion: creds.Region,
TargetRegion: destinationRegion,
}
Expand All @@ -74,7 +74,7 @@ var _ = Describe("KmsDriver", func() {
//defer cleanup of the created key replica, sadly we can only schedule it to be deleted after 7 days
//therefore this test will reuse the replicated key for 7 days and only afterward create a new one
defer func(aliasCreationResult resources.KmsKey) {
destinationKeyId := strings.ReplaceAll(kmsKeyId, originalRegion, destinationRegion)
destinationKeyId := strings.ReplaceAll(multiRegionKeyReplicationTest, originalRegion, destinationRegion)
awsSession, _ := session.NewSession(creds.GetAwsConfig())
kmsClient := kms.New(awsSession)

Expand Down

0 comments on commit 0928693

Please sign in to comment.