Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/r/fsx: Add sweeper concurrency #18626

Merged
merged 3 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions aws/resource_aws_fsx_lustre_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"log"
"regexp"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/service/fsx"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand All @@ -24,49 +24,52 @@ func init() {

func testSweepFSXLustreFileSystems(region string) error {
client, err := sharedClientForRegion(region)

if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

conn := client.(*AWSClient).fsxconn
sweepResources := make([]*testSweepResource, 0)
var errs *multierror.Error
input := &fsx.DescribeFileSystemsInput{}

err = conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool {
err = conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, isLast bool) bool {
Copy link
Contributor

@bflad bflad Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Prevalent convention for anonymous paginator functions is to name the 2nd parameter lastPage

Of course there's no enforcement so it is murky:

$ ag --stats-only 'Pages\(.*lastPage'
227 matches

$ ag --stats-only 'Pages\(.*isLast'  
84 matches

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no!!! I was just going on the contributing docs and changed all the WAFs the wrong way!

if page == nil {
return !isLast
}

for _, fs := range page.FileSystems {
if aws.StringValue(fs.FileSystemType) != fsx.FileSystemTypeLustre {
continue
}

input := &fsx.DeleteFileSystemInput{
FileSystemId: fs.FileSystemId,
}

log.Printf("[INFO] Deleting FSx lustre filesystem: %s", aws.StringValue(fs.FileSystemId))
_, err := conn.DeleteFileSystem(input)

if err != nil {
log.Printf("[ERROR] Error deleting FSx filesystem: %s", err)
continue
}
r := resourceAwsFsxLustreFileSystem()
d := r.Data(nil)
d.SetId(aws.StringValue(fs.FileSystemId))

if err := waitForFsxFileSystemDeletion(conn, aws.StringValue(fs.FileSystemId), 30*time.Minute); err != nil {
log.Printf("[ERROR] Error waiting for filesystem (%s) to delete: %s", aws.StringValue(fs.FileSystemId), err)
}
sweepResources = append(sweepResources, NewTestSweepResource(r, d, client))
}

return !lastPage
return !isLast
})

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping FSx Lustre Filesystem sweep for %s: %s", region, err)
return nil
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error listing FSx Lustre Filesystems for %s: %w", region, err))
}

if err != nil {
return fmt.Errorf("error listing FSx Lustre Filesystems: %s", err)
if len(sweepResources) > 0 {
if err := testSweepResourceOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping FSx Lustre Filesystems for %s: %w", region, err))
}
}

return nil
if testSweepSkipSweepError(errs.ErrorOrNil()) {
log.Printf("[WARN] Skipping FSx Lustre Filesystems sweep for %s: %s", region, errs)
return nil
}

return errs.ErrorOrNil()
}

func TestAccAWSFsxLustreFileSystem_basic(t *testing.T) {
Expand Down
54 changes: 27 additions & 27 deletions aws/resource_aws_fsx_windows_file_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"log"
"regexp"
"testing"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/fsx"
multierror "github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
Expand All @@ -22,53 +22,53 @@ func init() {

func testSweepFSXWindowsFileSystems(region string) error {
client, err := sharedClientForRegion(region)

if err != nil {
return fmt.Errorf("error getting client: %s", err)
}

conn := client.(*AWSClient).fsxconn
sweepResources := make([]*testSweepResource, 0)
var errs *multierror.Error
input := &fsx.DescribeFileSystemsInput{}

err = conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, lastPage bool) bool {
err = conn.DescribeFileSystemsPages(input, func(page *fsx.DescribeFileSystemsOutput, isLast bool) bool {
if page == nil {
return !isLast
}

for _, fs := range page.FileSystems {
if aws.StringValue(fs.FileSystemType) != fsx.FileSystemTypeWindows {
continue
}

input := &fsx.DeleteFileSystemInput{
ClientRequestToken: aws.String(resource.UniqueId()),
FileSystemId: fs.FileSystemId,
WindowsConfiguration: &fsx.DeleteFileSystemWindowsConfiguration{
SkipFinalBackup: aws.Bool(true),
},
}

log.Printf("[INFO] Deleting FSx windows filesystem: %s", aws.StringValue(fs.FileSystemId))
_, err := conn.DeleteFileSystem(input)

if err != nil {
log.Printf("[ERROR] Error deleting FSx filesystem: %s", err)
continue
}
r := resourceAwsFsxWindowsFileSystem()
d := r.Data(nil)
d.SetId(aws.StringValue(fs.FileSystemId))
d.Set("skip_final_backup", true)

if err := waitForFsxFileSystemDeletion(conn, aws.StringValue(fs.FileSystemId), 30*time.Minute); err != nil {
log.Printf("[ERROR] Error waiting for filesystem (%s) to delete: %s", aws.StringValue(fs.FileSystemId), err)
}
sweepResources = append(sweepResources, NewTestSweepResource(r, d, client))
}

return !lastPage
return !isLast
})

if testSweepSkipSweepError(err) {
log.Printf("[WARN] Skipping FSx Windows Filesystem sweep for %s: %s", region, err)
return nil
if err != nil {
errs = multierror.Append(errs, fmt.Errorf("error listing FSx Windows Filesystems for %s: %w", region, err))
}

if err != nil {
return fmt.Errorf("error listing FSx Windows Filesystems: %s", err)
if len(sweepResources) > 0 {
if err := testSweepResourceOrchestrator(sweepResources); err != nil {
errs = multierror.Append(errs, fmt.Errorf("error sweeping FSx Windows Filesystems for %s: %w", region, err))
}
}

return nil
if testSweepSkipSweepError(errs.ErrorOrNil()) {
log.Printf("[WARN] Skipping FSx Windows Filesystems sweep for %s: %s", region, errs)
return nil
}

return errs.ErrorOrNil()
}

func TestAccAWSFsxWindowsFileSystem_basic(t *testing.T) {
Expand Down