-
Notifications
You must be signed in to change notification settings - Fork 505
test(managed_folder): optimize managed_folders e2e-test by skipping unnecessary IAM propagation waits #4795
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -54,34 +54,26 @@ type managedFoldersAdminPermission struct { | |||||||||||||||||||||||||||||
| func (s *managedFoldersAdminPermission) SetupSuite() { | ||||||||||||||||||||||||||||||
| setup.MountGCSFuseWithGivenMountWithConfigFunc(testEnv.cfg, s.flags, testEnv.mountFunc) | ||||||||||||||||||||||||||||||
| setup.SetMntDir(testEnv.mountDir) | ||||||||||||||||||||||||||||||
| testEnv.testDirPath = setup.SetupTestDirectory(TestDirForManagedFolderTest) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| func (s *managedFoldersAdminPermission) TearDownSuite() { | ||||||||||||||||||||||||||||||
| setup.UnmountGCSFuseWithConfig(testEnv.cfg) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| func (s *managedFoldersAdminPermission) SetupTest() { | ||||||||||||||||||||||||||||||
| testEnv.testDirPath = setup.SetupTestDirectory(TestDirForManagedFolderTest) | ||||||||||||||||||||||||||||||
| createDirectoryStructureForNonEmptyManagedFolders(testEnv.ctx, testEnv.storageClient, testEnv.controlClient, s.T()) | ||||||||||||||||||||||||||||||
| if s.managedFoldersPermission != "nil" { | ||||||||||||||||||||||||||||||
| managedFolderRecreated := createDirectoryStructureForNonEmptyManagedFolders(testEnv.ctx, testEnv.storageClient, testEnv.controlClient, s.T()) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if s.managedFoldersPermission != "nil" && managedFolderRecreated { | ||||||||||||||||||||||||||||||
| providePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder1), testEnv.serviceAccount, s.managedFoldersPermission, s.T()) | ||||||||||||||||||||||||||||||
| providePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder2), testEnv.serviceAccount, s.managedFoldersPermission, s.T()) | ||||||||||||||||||||||||||||||
| // Waiting for 60 seconds for policy changes to propagate. This values we kept based on our experiments. | ||||||||||||||||||||||||||||||
| // Wait for policy propagation only when folders were recreated and IAM was reapplied. | ||||||||||||||||||||||||||||||
| time.Sleep(60 * time.Second) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| func (s *managedFoldersAdminPermission) TearDownTest() { | ||||||||||||||||||||||||||||||
| setup.SaveGCSFuseLogFileInCaseOfFailure(s.T()) | ||||||||||||||||||||||||||||||
| // Due to bucket view permissions, it prevents cleaning resources outside managed folders. So we are cleaning managed folders resources only. | ||||||||||||||||||||||||||||||
| if s.bucketPermission == ViewPermission { | ||||||||||||||||||||||||||||||
| revokePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder1), testEnv.serviceAccount, s.managedFoldersPermission, s.T()) | ||||||||||||||||||||||||||||||
| setup.CleanUpDir(path.Join(setup.MntDir(), TestDirForManagedFolderTest, ManagedFolder1)) | ||||||||||||||||||||||||||||||
| revokePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder2), testEnv.serviceAccount, s.managedFoldersPermission, s.T()) | ||||||||||||||||||||||||||||||
| setup.CleanUpDir(path.Join(setup.MntDir(), TestDirForManagedFolderTest, ManagedFolder2)) | ||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| setup.CleanUpDir(path.Join(setup.MntDir(), TestDirForManagedFolderTest)) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
raj-prince marked this conversation as resolved.
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| //////////////////////////////////////////////////////////////////////// | ||||||||||||||||||||||||||||||
|
|
@@ -128,6 +120,11 @@ func (s *managedFoldersAdminPermission) TestCopyObjectWithInManagedFolder() { | |||||||||||||||||||||||||||||
| testDirPath := path.Join(testEnv.testDirPath, ManagedFolder1) | ||||||||||||||||||||||||||||||
| srcCopyFile := path.Join(testDirPath, FileInNonEmptyManagedFoldersTest) | ||||||||||||||||||||||||||||||
| destCopyFile := path.Join(testDirPath, DestFile) | ||||||||||||||||||||||||||||||
| defer func() { | ||||||||||||||||||||||||||||||
| if err := os.RemoveAll(destCopyFile); err != nil { | ||||||||||||||||||||||||||||||
| log.Printf("failed to remove scratch copy file: %v", err) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| err := operations.CopyFile(srcCopyFile, destCopyFile) | ||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||
|
|
@@ -143,6 +140,11 @@ func (s *managedFoldersAdminPermission) TestCopyObjectWithInManagedFolder() { | |||||||||||||||||||||||||||||
| func (s *managedFoldersAdminPermission) TestCopyManagedFolder() { | ||||||||||||||||||||||||||||||
| srcDirPath := path.Join(testEnv.testDirPath, ManagedFolder1) | ||||||||||||||||||||||||||||||
| destDirPath := path.Join(testEnv.testDirPath, DestFolder) | ||||||||||||||||||||||||||||||
| defer func() { | ||||||||||||||||||||||||||||||
| if err := os.RemoveAll(destDirPath); err != nil { | ||||||||||||||||||||||||||||||
| log.Printf("failed to remove scratch copy folder: %v", err) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| err := operations.CopyDir(srcDirPath, destDirPath) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -160,6 +162,11 @@ func (s *managedFoldersAdminPermission) TestMoveObjectWithInManagedFolder() { | |||||||||||||||||||||||||||||
| testDirPath := path.Join(testEnv.testDirPath, ManagedFolder1) | ||||||||||||||||||||||||||||||
| srcMoveFile := path.Join(testDirPath, FileInNonEmptyManagedFoldersTest) | ||||||||||||||||||||||||||||||
| destMoveFile := path.Join(testDirPath, DestFile) | ||||||||||||||||||||||||||||||
| defer func() { | ||||||||||||||||||||||||||||||
| if err := os.RemoveAll(destMoveFile); err != nil { | ||||||||||||||||||||||||||||||
| log.Printf("failed to remove scratch move file: %v", err) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| err := operations.Move(srcMoveFile, destMoveFile) | ||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||
|
|
@@ -179,6 +186,11 @@ func (s *managedFoldersAdminPermission) TestMoveObjectWithInManagedFolder() { | |||||||||||||||||||||||||||||
| func (s *managedFoldersAdminPermission) TestMoveManagedFolder() { | ||||||||||||||||||||||||||||||
| srcDirPath := path.Join(testEnv.testDirPath, ManagedFolder1) | ||||||||||||||||||||||||||||||
| destDirPath := path.Join(testEnv.testDirPath, DestFolder) | ||||||||||||||||||||||||||||||
| defer func() { | ||||||||||||||||||||||||||||||
| if err := os.RemoveAll(destDirPath); err != nil { | ||||||||||||||||||||||||||||||
| log.Printf("failed to remove scratch move folder: %v", err) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| err := operations.Move(srcDirPath, destDirPath) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
@@ -223,7 +235,21 @@ func TestManagedFolders_FolderAdminPermission(t *testing.T) { | |||||||||||||||||||||||||||||
| creds_tests.ApplyPermissionToServiceAccount(testEnv.ctx, testEnv.storageClient, testEnv.serviceAccount, ViewPermission, setup.TestBucket()) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ts.managedFoldersPermission = permissions[i][1] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if ts.managedFoldersPermission != "nil" { | ||||||||||||||||||||||||||||||
| providePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder1), testEnv.serviceAccount, ts.managedFoldersPermission, t) | ||||||||||||||||||||||||||||||
| providePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder2), testEnv.serviceAccount, ts.managedFoldersPermission, t) | ||||||||||||||||||||||||||||||
| // Wait once per permission scenario for initial policy propagation. | ||||||||||||||||||||||||||||||
| time.Sleep(60 * time.Second) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+239
to
+244
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The IAM policy configuration here is fragile because it assumes the managed folders already exist in the bucket. If the first scenario (
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SetupTest creates the folder if not already exist, applies the iam permission and wait for propagation. |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| suite.Run(t, ts) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if ts.managedFoldersPermission != "nil" { | ||||||||||||||||||||||||||||||
| revokePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder1), testEnv.serviceAccount, ts.managedFoldersPermission, t) | ||||||||||||||||||||||||||||||
| revokePermissionToManagedFolder(testEnv.bucket, path.Join(testEnv.testDir, ManagedFolder2), testEnv.serviceAccount, ts.managedFoldersPermission, t) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| if ts.bucketPermission == ViewPermission { | ||||||||||||||||||||||||||||||
| creds_tests.RevokePermission(testEnv.ctx, testEnv.storageClient, testEnv.serviceAccount, ViewPermission, setup.TestBucket()) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,6 +32,7 @@ import ( | |||||||||||||||||||||||||||||||||
| "github.com/googlecloudplatform/gcsfuse/v3/internal/storage" | ||||||||||||||||||||||||||||||||||
| "github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup" | ||||||||||||||||||||||||||||||||||
| "google.golang.org/grpc/codes" | ||||||||||||||||||||||||||||||||||
| "google.golang.org/grpc/status" | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| func storageControlClientRetryOptions() []gax.CallOption { | ||||||||||||||||||||||||||||||||||
|
|
@@ -96,16 +97,20 @@ func DeleteManagedFoldersInBucket(ctx context.Context, client *control.StorageCo | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| func CreateManagedFoldersInBucket(ctx context.Context, client *control.StorageControlClient, managedFolderPath, bucket string) { | ||||||||||||||||||||||||||||||||||
| func CreateManagedFoldersInBucket(ctx context.Context, client *control.StorageControlClient, managedFolderPath, bucket string) bool { | ||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add doc string - it's unclear what "bool" return type actually stands for. |
||||||||||||||||||||||||||||||||||
| mf := &controlpb.ManagedFolder{} | ||||||||||||||||||||||||||||||||||
| req := &controlpb.CreateManagedFolderRequest{ | ||||||||||||||||||||||||||||||||||
| Parent: fmt.Sprintf("projects/_/buckets/%v", bucket), | ||||||||||||||||||||||||||||||||||
| ManagedFolder: mf, | ||||||||||||||||||||||||||||||||||
| ManagedFolderId: managedFolderPath, | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| if _, err := client.CreateManagedFolder(ctx, req); err != nil && !strings.Contains(err.Error(), "The specified managed folder already exists") { | ||||||||||||||||||||||||||||||||||
| if _, err := client.CreateManagedFolder(ctx, req); err != nil { | ||||||||||||||||||||||||||||||||||
| if status.Code(err) == codes.AlreadyExists || strings.Contains(err.Error(), "The specified managed folder already exists") { | ||||||||||||||||||||||||||||||||||
| return false | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| log.Fatalf("Error while creating managed folder: %v", err) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return true | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+107
to
+113
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| func CreateFolderInBucket(ctx context.Context, client *control.StorageControlClient, folderPath string) (*controlpb.Folder, error) { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could reduce nesting by using short-return.