From fe3f1a6f78b69acab030d08e8d97fce9774aa128 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 05:48:42 +0000 Subject: [PATCH 01/12] testing --- tools/integration_tests/util/setup/setup.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/integration_tests/util/setup/setup.go b/tools/integration_tests/util/setup/setup.go index 462a051484..d0366e790a 100644 --- a/tools/integration_tests/util/setup/setup.go +++ b/tools/integration_tests/util/setup/setup.go @@ -148,6 +148,11 @@ func SetUpTestDir() error { } binFile = path.Join(TestDir(), "bin/gcsfuse") sbinFile = path.Join(TestDir(), "sbin/mount.gcsfuse") + + err := operations.CopyDir(binFile, "/usr/local/bin") + if err != nil { + log.Printf("Error in copying bin file:%v", err) + } } else { // when testInstalledPackage flag is set, gcsfuse is preinstalled on the // machine. Hence, here we are overwriting binFile to gcsfuse. From 175adf2dd0db8cba52f692a1dee2f2942d5d8529 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 05:55:39 +0000 Subject: [PATCH 02/12] testing --- tools/integration_tests/util/operations/dir_operations.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/integration_tests/util/operations/dir_operations.go b/tools/integration_tests/util/operations/dir_operations.go index d221fb5241..234ff720b1 100644 --- a/tools/integration_tests/util/operations/dir_operations.go +++ b/tools/integration_tests/util/operations/dir_operations.go @@ -31,6 +31,7 @@ const FilePermission_0777 = 0777 func CopyDir(srcDirPath string, destDirPath string) (err error) { cmd := exec.Command("cp", "--recursive", srcDirPath, destDirPath) + log.Print(srcDirPath, destDirPath) err = cmd.Run() if err != nil { err = fmt.Errorf("Copying dir operation is failed: %v", err) From a284648813263a2bbecc11465c4ea8e4ab57d4ba Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 06:05:55 +0000 Subject: [PATCH 03/12] testing --- tools/integration_tests/util/operations/dir_operations.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/integration_tests/util/operations/dir_operations.go b/tools/integration_tests/util/operations/dir_operations.go index 234ff720b1..07e875dd13 100644 --- a/tools/integration_tests/util/operations/dir_operations.go +++ b/tools/integration_tests/util/operations/dir_operations.go @@ -29,9 +29,8 @@ const FilePermission_0600 = 0600 const FilePermission_0777 = 0777 func CopyDir(srcDirPath string, destDirPath string) (err error) { - cmd := exec.Command("cp", "--recursive", srcDirPath, destDirPath) + cmd := exec.Command("sudo", "cp", "--recursive", srcDirPath, destDirPath) - log.Print(srcDirPath, destDirPath) err = cmd.Run() if err != nil { err = fmt.Errorf("Copying dir operation is failed: %v", err) From 99f046afd6e3f37db29b5508383451eb360e90e7 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 06:12:36 +0000 Subject: [PATCH 04/12] adding comment for a reason --- tools/integration_tests/util/setup/setup.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/integration_tests/util/setup/setup.go b/tools/integration_tests/util/setup/setup.go index d0366e790a..e58c425a48 100644 --- a/tools/integration_tests/util/setup/setup.go +++ b/tools/integration_tests/util/setup/setup.go @@ -149,6 +149,9 @@ func SetUpTestDir() error { binFile = path.Join(TestDir(), "bin/gcsfuse") sbinFile = path.Join(TestDir(), "sbin/mount.gcsfuse") + // mount.gcsfuse will find gcsfuse executable in mentioned locations. + // https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/tools/mount_gcsfuse/find.go#L59 + // Copying the executable to /usr/local/bin err := operations.CopyDir(binFile, "/usr/local/bin") if err != nil { log.Printf("Error in copying bin file:%v", err) From 8463a639a69d8c4ec499975e36df69184b561f9e Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 06:34:05 +0000 Subject: [PATCH 05/12] creating function to copy dir with root permission --- .../util/operations/dir_operations.go | 10 ++++++++++ tools/integration_tests/util/setup/setup.go | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/integration_tests/util/operations/dir_operations.go b/tools/integration_tests/util/operations/dir_operations.go index 07e875dd13..0eec676a3e 100644 --- a/tools/integration_tests/util/operations/dir_operations.go +++ b/tools/integration_tests/util/operations/dir_operations.go @@ -29,6 +29,16 @@ const FilePermission_0600 = 0600 const FilePermission_0777 = 0777 func CopyDir(srcDirPath string, destDirPath string) (err error) { + cmd := exec.Command("cp", "--recursive", srcDirPath, destDirPath) + + err = cmd.Run() + if err != nil { + err = fmt.Errorf("Copying dir operation is failed: %v", err) + } + return +} + +func CopyDirWithRootPermission(srcDirPath string, destDirPath string) (err error) { cmd := exec.Command("sudo", "cp", "--recursive", srcDirPath, destDirPath) err = cmd.Run() diff --git a/tools/integration_tests/util/setup/setup.go b/tools/integration_tests/util/setup/setup.go index e58c425a48..bbabd73262 100644 --- a/tools/integration_tests/util/setup/setup.go +++ b/tools/integration_tests/util/setup/setup.go @@ -152,7 +152,7 @@ func SetUpTestDir() error { // mount.gcsfuse will find gcsfuse executable in mentioned locations. // https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/tools/mount_gcsfuse/find.go#L59 // Copying the executable to /usr/local/bin - err := operations.CopyDir(binFile, "/usr/local/bin") + err := operations.CopyDirWithRootPermission(binFile, "/usr/local/bin") if err != nil { log.Printf("Error in copying bin file:%v", err) } From c1e91fc5298021ae66a5042b35bb47b78a690527 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 06:45:49 +0000 Subject: [PATCH 06/12] common function --- .../util/operations/dir_operations.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/integration_tests/util/operations/dir_operations.go b/tools/integration_tests/util/operations/dir_operations.go index 0eec676a3e..5dd4b3ed53 100644 --- a/tools/integration_tests/util/operations/dir_operations.go +++ b/tools/integration_tests/util/operations/dir_operations.go @@ -38,9 +38,7 @@ func CopyDir(srcDirPath string, destDirPath string) (err error) { return } -func CopyDirWithRootPermission(srcDirPath string, destDirPath string) (err error) { - cmd := exec.Command("sudo", "cp", "--recursive", srcDirPath, destDirPath) - +func executeCommandForCopyOperation(cmd *exec.Cmd) (err error) { err = cmd.Run() if err != nil { err = fmt.Errorf("Copying dir operation is failed: %v", err) @@ -48,13 +46,19 @@ func CopyDirWithRootPermission(srcDirPath string, destDirPath string) (err error return } +func CopyDirWithRootPermission(srcDirPath string, destDirPath string) (err error) { + cmd := exec.Command("sudo", "cp", "--recursive", srcDirPath, destDirPath) + + err = executeCommandForCopyOperation(cmd) + + return +} + func MoveDir(srcDirPath string, destDirPath string) (err error) { cmd := exec.Command("mv", srcDirPath, destDirPath) - err = cmd.Run() - if err != nil { - err = fmt.Errorf("Moving dir operation is failed: %v", err) - } + err = executeCommandForCopyOperation(cmd) + return } From f04782b3dc51f180fd89843cd3d8570c29220a0f Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 06:48:57 +0000 Subject: [PATCH 07/12] fix --- .../util/operations/dir_operations.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/integration_tests/util/operations/dir_operations.go b/tools/integration_tests/util/operations/dir_operations.go index 5dd4b3ed53..346a6470f8 100644 --- a/tools/integration_tests/util/operations/dir_operations.go +++ b/tools/integration_tests/util/operations/dir_operations.go @@ -28,9 +28,7 @@ import ( const FilePermission_0600 = 0600 const FilePermission_0777 = 0777 -func CopyDir(srcDirPath string, destDirPath string) (err error) { - cmd := exec.Command("cp", "--recursive", srcDirPath, destDirPath) - +func executeCommandForCopyOperation(cmd *exec.Cmd) (err error) { err = cmd.Run() if err != nil { err = fmt.Errorf("Copying dir operation is failed: %v", err) @@ -38,11 +36,11 @@ func CopyDir(srcDirPath string, destDirPath string) (err error) { return } -func executeCommandForCopyOperation(cmd *exec.Cmd) (err error) { - err = cmd.Run() - if err != nil { - err = fmt.Errorf("Copying dir operation is failed: %v", err) - } +func CopyDir(srcDirPath string, destDirPath string) (err error) { + cmd := exec.Command("cp", "--recursive", srcDirPath, destDirPath) + + err = executeCommandForCopyOperation(cmd) + return } @@ -57,8 +55,10 @@ func CopyDirWithRootPermission(srcDirPath string, destDirPath string) (err error func MoveDir(srcDirPath string, destDirPath string) (err error) { cmd := exec.Command("mv", srcDirPath, destDirPath) - err = executeCommandForCopyOperation(cmd) - + err = cmd.Run() + if err != nil { + err = fmt.Errorf("Moving dir operation is failed: %v", err) + } return } From a39706739ad50a49d44b2494614ecd59250f500e Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 07:49:41 +0000 Subject: [PATCH 08/12] testing --- .../operations/operations_test.go | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/tools/integration_tests/operations/operations_test.go b/tools/integration_tests/operations/operations_test.go index 6d37b19c13..dad8552f85 100644 --- a/tools/integration_tests/operations/operations_test.go +++ b/tools/integration_tests/operations/operations_test.go @@ -21,9 +21,6 @@ import ( "testing" "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/creds_tests" - "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting" - "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/persistent_mounting" - "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting" "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup" ) @@ -103,20 +100,20 @@ func TestMain(m *testing.M) { // Run tests for testBucket setup.SetUpTestDirForTestBucketFlag() - successCode := static_mounting.RunTests(flags, m) + //successCode := static_mounting.RunTests(flags, m) + // + //if successCode == 0 { + // successCode = only_dir_mounting.RunTests(flags, m) + //} + // + //if successCode == 0 { + // successCode = persistent_mounting.RunTests(flags, m) + //} - if successCode == 0 { - successCode = only_dir_mounting.RunTests(flags, m) - } - - if successCode == 0 { - successCode = persistent_mounting.RunTests(flags, m) - } - - if successCode == 0 { - // Test for admin permission on test bucket. - successCode = creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m) - } + //if successCode == 0 { + // Test for admin permission on test bucket. + successCode := creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m) + //} os.Exit(successCode) } From ffb3aa20df028222653e2e57482a276a5b6d0707 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 08:11:46 +0000 Subject: [PATCH 09/12] revert changes --- .../operations/operations_test.go | 29 ++++++++++--------- .../util/creds_tests/creds.go | 3 -- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/tools/integration_tests/operations/operations_test.go b/tools/integration_tests/operations/operations_test.go index dad8552f85..6d37b19c13 100644 --- a/tools/integration_tests/operations/operations_test.go +++ b/tools/integration_tests/operations/operations_test.go @@ -21,6 +21,9 @@ import ( "testing" "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/creds_tests" + "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting" + "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/persistent_mounting" + "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting" "github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup" ) @@ -100,20 +103,20 @@ func TestMain(m *testing.M) { // Run tests for testBucket setup.SetUpTestDirForTestBucketFlag() - //successCode := static_mounting.RunTests(flags, m) - // - //if successCode == 0 { - // successCode = only_dir_mounting.RunTests(flags, m) - //} - // - //if successCode == 0 { - // successCode = persistent_mounting.RunTests(flags, m) - //} + successCode := static_mounting.RunTests(flags, m) - //if successCode == 0 { - // Test for admin permission on test bucket. - successCode := creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m) - //} + if successCode == 0 { + successCode = only_dir_mounting.RunTests(flags, m) + } + + if successCode == 0 { + successCode = persistent_mounting.RunTests(flags, m) + } + + if successCode == 0 { + // Test for admin permission on test bucket. + successCode = creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m) + } os.Exit(successCode) } diff --git a/tools/integration_tests/util/creds_tests/creds.go b/tools/integration_tests/util/creds_tests/creds.go index f1106f7e44..ae91f47cf7 100644 --- a/tools/integration_tests/util/creds_tests/creds.go +++ b/tools/integration_tests/util/creds_tests/creds.go @@ -56,9 +56,6 @@ func RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(testFlagSet [][] // Provide permission to service account for testing. setPermission(permission, serviceAccount) - // Revoke the permission and delete creds and service account after testing. - defer setup.RunScriptForTestData("../util/creds_tests/testdata/revoke_permission_and_delete_service_account_and_creds.sh", serviceAccount, key_file_path) - // Without –key-file flag and GOOGLE_APPLICATION_CREDENTIALS // This case will not get covered as gcsfuse internally authenticates from a metadata server on GCE VM. // https://github.com/golang/oauth2/blob/master/google/default.go#L160 From a60dd12300d58e5cf260a1383415f0a6961c80b2 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 08:12:08 +0000 Subject: [PATCH 10/12] revert changes --- tools/integration_tests/util/creds_tests/creds.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/integration_tests/util/creds_tests/creds.go b/tools/integration_tests/util/creds_tests/creds.go index ae91f47cf7..f1106f7e44 100644 --- a/tools/integration_tests/util/creds_tests/creds.go +++ b/tools/integration_tests/util/creds_tests/creds.go @@ -56,6 +56,9 @@ func RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(testFlagSet [][] // Provide permission to service account for testing. setPermission(permission, serviceAccount) + // Revoke the permission and delete creds and service account after testing. + defer setup.RunScriptForTestData("../util/creds_tests/testdata/revoke_permission_and_delete_service_account_and_creds.sh", serviceAccount, key_file_path) + // Without –key-file flag and GOOGLE_APPLICATION_CREDENTIALS // This case will not get covered as gcsfuse internally authenticates from a metadata server on GCE VM. // https://github.com/golang/oauth2/blob/master/google/default.go#L160 From 389b47ab22bb41944f637445909c0719e90082a1 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 11:07:02 +0000 Subject: [PATCH 11/12] adding remove package --- .../list_large_dir/list_large_dir_test.go | 2 ++ tools/integration_tests/operations/operations_test.go | 2 ++ tools/integration_tests/readonly/readonly_test.go | 2 ++ .../rename_dir_limit/rename_dir_limit_test.go | 2 ++ .../implicit_and_explicit_dir_setup.go | 2 ++ tools/integration_tests/util/setup/setup.go | 10 ++++++++++ 6 files changed, 20 insertions(+) diff --git a/tools/integration_tests/list_large_dir/list_large_dir_test.go b/tools/integration_tests/list_large_dir/list_large_dir_test.go index 3a5a24c58a..0189e429ac 100644 --- a/tools/integration_tests/list_large_dir/list_large_dir_test.go +++ b/tools/integration_tests/list_large_dir/list_large_dir_test.go @@ -49,5 +49,7 @@ func TestMain(m *testing.M) { successCode := static_mounting.RunTests(flags, m) + setup.RemoveBinFileCopiedForTesting() + os.Exit(successCode) } diff --git a/tools/integration_tests/operations/operations_test.go b/tools/integration_tests/operations/operations_test.go index 6d37b19c13..f177e37c34 100644 --- a/tools/integration_tests/operations/operations_test.go +++ b/tools/integration_tests/operations/operations_test.go @@ -118,5 +118,7 @@ func TestMain(m *testing.M) { successCode = creds_tests.RunTestsForKeyFileAndGoogleApplicationCredentialsEnvVarSet(flags, "objectAdmin", m) } + setup.RemoveBinFileCopiedForTesting() + os.Exit(successCode) } diff --git a/tools/integration_tests/readonly/readonly_test.go b/tools/integration_tests/readonly/readonly_test.go index 0a9003781a..727e93c15e 100644 --- a/tools/integration_tests/readonly/readonly_test.go +++ b/tools/integration_tests/readonly/readonly_test.go @@ -93,5 +93,7 @@ func TestMain(m *testing.M) { // Delete objects from bucket after testing. setup.RunScriptForTestData("testdata/delete_objects.sh", setup.TestBucket()) + setup.RemoveBinFileCopiedForTesting() + os.Exit(successCode) } diff --git a/tools/integration_tests/rename_dir_limit/rename_dir_limit_test.go b/tools/integration_tests/rename_dir_limit/rename_dir_limit_test.go index 28c5b19399..83a2ad1bb7 100644 --- a/tools/integration_tests/rename_dir_limit/rename_dir_limit_test.go +++ b/tools/integration_tests/rename_dir_limit/rename_dir_limit_test.go @@ -64,5 +64,7 @@ func TestMain(m *testing.M) { successCode = persistent_mounting.RunTests(flags, m) } + setup.RemoveBinFileCopiedForTesting() + os.Exit(successCode) } diff --git a/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go b/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go index bec0d1d538..34e8664c42 100644 --- a/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go +++ b/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup/implicit_and_explicit_dir_setup.go @@ -63,6 +63,8 @@ func RunTestsForImplicitDirAndExplicitDir(flags [][]string, m *testing.M) { successCode = persistent_mounting.RunTests(flags, m) } + setup.RemoveBinFileCopiedForTesting() + os.Exit(successCode) } diff --git a/tools/integration_tests/util/setup/setup.go b/tools/integration_tests/util/setup/setup.go index bbabd73262..0dbdff0fbb 100644 --- a/tools/integration_tests/util/setup/setup.go +++ b/tools/integration_tests/util/setup/setup.go @@ -172,6 +172,16 @@ func SetUpTestDir() error { return nil } +// Removing bin file after testing. +func RemoveBinFileCopiedForTesting() { + if !TestInstalledPackage() { + err := os.Remove("/usr/local/bin/gcsfuse") + if err != nil { + log.Printf("Error in removing file:%v", err) + } + } +} + func UnMount() error { fusermount, err := exec.LookPath("fusermount") if err != nil { From 34832783cdbe0cab649cc57dd2b690675e7ad935 Mon Sep 17 00:00:00 2001 From: Tulsi Shah Date: Fri, 21 Jul 2023 11:12:58 +0000 Subject: [PATCH 12/12] adding remove package --- tools/integration_tests/util/setup/setup.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/integration_tests/util/setup/setup.go b/tools/integration_tests/util/setup/setup.go index 0dbdff0fbb..0d0310339f 100644 --- a/tools/integration_tests/util/setup/setup.go +++ b/tools/integration_tests/util/setup/setup.go @@ -175,7 +175,8 @@ func SetUpTestDir() error { // Removing bin file after testing. func RemoveBinFileCopiedForTesting() { if !TestInstalledPackage() { - err := os.Remove("/usr/local/bin/gcsfuse") + cmd := exec.Command("sudo", "rm", "/usr/local/bin/gcsfuse") + err := cmd.Run() if err != nil { log.Printf("Error in removing file:%v", err) }