From f5bb7c93d7a97daa33aa88fefa78f3aeb71415a5 Mon Sep 17 00:00:00 2001 From: Tulsi Shah <46474643+Tulsishah@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:22:50 +0000 Subject: [PATCH] GKE e2e test fix (#2416) * fix cache dir name * fix cache dir name * add test bucket flag * lint fix * lint fix * lint fix * test script * lint fix * lint fix * test on VM * test on VM * undo test changes * review comment * lint fix * small fix --- .../operations/operations_test.go | 29 ++++++++++++------- .../read_cache/setup_test.go | 6 ++-- .../read_large_files/read_large_files_test.go | 26 ++++++++++++++--- .../readonly/readonly_test.go | 12 ++++---- .../rename_dir_limit/rename_dir_limit_test.go | 3 -- .../run_tests_mounted_directory.sh | 27 +++++++++-------- 6 files changed, 63 insertions(+), 40 deletions(-) diff --git a/tools/integration_tests/operations/operations_test.go b/tools/integration_tests/operations/operations_test.go index 3d61d1b820..5f9cbec223 100644 --- a/tools/integration_tests/operations/operations_test.go +++ b/tools/integration_tests/operations/operations_test.go @@ -20,6 +20,7 @@ import ( "log" "os" "path" + "strconv" "testing" "cloud.google.com/go/storage" @@ -88,8 +89,14 @@ const ContentInFileInDirThreeInCreateThreeLevelDirTest = "Hello world!!" const Content = "line 1\nline 2\n" const onlyDirMounted = "OnlyDirMountOperations" +var ( + cacheDir string + storageClient *storage.Client + ctx context.Context +) + func createMountConfigsAndEquivalentFlags() (flags [][]string) { - cacheDirPath := path.Join(os.Getenv("HOME"), "operations-cache-dir"+setup.GenerateRandomString(5)) + cacheDirPath := path.Join(os.TempDir(), cacheDir) // Set up config file with create-empty-file: true. mountConfig1 := map[string]interface{}{ @@ -137,15 +144,17 @@ func TestMain(m *testing.M) { setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet() // Create storage client before running tests. - ctx := context.Background() - var storageClient *storage.Client - closeStorageClient := client.CreateStorageClientWithCancel(&ctx, &storageClient) - defer func() { - err := closeStorageClient() - if err != nil { - log.Fatalf("closeStorageClient failed: %v", err) - } - }() + var err error + ctx = context.Background() + storageClient, err = client.CreateStorageClient(ctx) + if err != nil { + log.Printf("Error creating storage client: %v\n", err) + os.Exit(1) + } + defer storageClient.Close() + + cacheDir = "cache-dir-operations-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient)) + // To run mountedDirectory tests, we need both testBucket and mountedDirectory // flags to be set, as operations tests validates content from the bucket. if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() { diff --git a/tools/integration_tests/read_cache/setup_test.go b/tools/integration_tests/read_cache/setup_test.go index ab8c616e75..3640c23db0 100644 --- a/tools/integration_tests/read_cache/setup_test.go +++ b/tools/integration_tests/read_cache/setup_test.go @@ -19,6 +19,7 @@ import ( "log" "os" "path" + "strconv" "testing" "cloud.google.com/go/storage" @@ -67,10 +68,9 @@ const ( enableCrcCheck = true ) -var cacheDirName = "cache-dir" + setup.GenerateRandomString(5) - var ( testDirPath string + cacheDirName string cacheDirPath string mountFunc func([]string) error // mount directory is where our tests run. @@ -150,6 +150,8 @@ func TestMain(m *testing.M) { } }() + cacheDirName = "cache-dir-read-cache-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient)) + setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet() setup.RunTestsForMountedDirectoryFlag(m) diff --git a/tools/integration_tests/read_large_files/read_large_files_test.go b/tools/integration_tests/read_large_files/read_large_files_test.go index 3752581fc3..3a517fd64c 100644 --- a/tools/integration_tests/read_large_files/read_large_files_test.go +++ b/tools/integration_tests/read_large_files/read_large_files_test.go @@ -16,12 +16,15 @@ package read_large_files import ( + "context" "log" "os" "path" "strconv" "testing" + "cloud.google.com/go/storage" + "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client" "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/mounting/static_mounting" "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/operations" "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup" @@ -35,10 +38,15 @@ const MinReadableByteFromFile = 0 const MaxReadableByteFromFile = 500 * OneMB const DirForReadLargeFilesTests = "dirForReadLargeFilesTests" -var FiveHundredMBFile string = "fiveHundredMBFile" + setup.GenerateRandomString(5) + ".txt" +var ( + storageClient *storage.Client + ctx context.Context + FiveHundredMBFile = "fiveHundredMBFile" + setup.GenerateRandomString(5) + ".txt" + cacheDir string +) func createMountConfigsAndEquivalentFlags() (flags [][]string) { - cacheDirPath := path.Join(os.Getenv("HOME"), "cache-dri") + cacheDirPath := path.Join(os.TempDir(), cacheDir) // Set up config file for file cache with cache-file-for-range-read: false mountConfig1 := map[string]interface{}{ @@ -70,14 +78,24 @@ func createMountConfigsAndEquivalentFlags() (flags [][]string) { func TestMain(m *testing.M) { setup.ParseSetUpFlags() + var err error + ctx = context.Background() + storageClient, err = client.CreateStorageClient(ctx) + if err != nil { + log.Printf("Error creating storage client: %v\n", err) + os.Exit(1) + } + defer storageClient.Close() + cacheDir = "cache-dir-read-large-files-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient)) + flags := [][]string{{"--implicit-dirs"}} mountConfigFlags := createMountConfigsAndEquivalentFlags() flags = append(flags, mountConfigFlags...) setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet() - if setup.TestBucket() != "" && setup.MountedDirectory() != "" { - log.Print("Both --testbucket and --mountedDirectory can't be specified at the same time.") + if setup.TestBucket() == "" && setup.MountedDirectory() != "" { + log.Print("Please pass the name of bucket mounted at mountedDirectory to --testBucket flag.") os.Exit(1) } diff --git a/tools/integration_tests/readonly/readonly_test.go b/tools/integration_tests/readonly/readonly_test.go index 7858a1695a..e1f3a66789 100644 --- a/tools/integration_tests/readonly/readonly_test.go +++ b/tools/integration_tests/readonly/readonly_test.go @@ -20,9 +20,9 @@ import ( "log" "os" "path" + "strconv" "strings" "testing" - "time" "cloud.google.com/go/storage" "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client" @@ -52,6 +52,7 @@ const RenameDir = "rename" var ( storageClient *storage.Client ctx context.Context + cacheDir string ) func createTestDataForReadOnlyTests(ctx context.Context, storageClient *storage.Client) { @@ -93,7 +94,7 @@ func checkErrorForObjectNotExist(err error, t *testing.T) { } func createMountConfigsAndEquivalentFlags() (flags [][]string) { - cacheDirPath := path.Join(os.Getenv("HOME"), "cache-dir"+setup.GenerateRandomString(5)) + cacheDirPath := path.Join(os.TempDir(), cacheDir) // Set up config file for file cache. mountConfig := map[string]interface{}{ @@ -115,18 +116,15 @@ func TestMain(m *testing.M) { var err error ctx = context.Background() - var cancel context.CancelFunc - - ctx, cancel = context.WithTimeout(ctx, time.Minute*20) storageClient, err = client.CreateStorageClient(ctx) if err != nil { log.Printf("Error creating storage client: %v\n", err) os.Exit(1) } - - defer cancel() defer storageClient.Close() + cacheDir = "cache-dir-readonly-hns-" + strconv.FormatBool(setup.IsHierarchicalBucket(ctx, storageClient)) + flags := [][]string{{"--o=ro", "--implicit-dirs=true"}, {"--file-mode=544", "--dir-mode=544", "--implicit-dirs=true"}} if !testing.Short() { 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 5ce0c399cc..562a4cfeb0 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 @@ -20,7 +20,6 @@ import ( "log" "os" "testing" - "time" "cloud.google.com/go/storage" "github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client" @@ -53,13 +52,11 @@ func TestMain(m *testing.M) { var err error ctx = context.Background() - ctx, cancel := context.WithTimeout(ctx, time.Minute*20) storageClient, err = client.CreateStorageClient(ctx) if err != nil { log.Printf("Error creating storage client: %v\n", err) os.Exit(1) } - defer cancel() defer storageClient.Close() flags := [][]string{{"--rename-dir-limit=3", "--implicit-dirs"}, {"--rename-dir-limit=3"}} diff --git a/tools/integration_tests/run_tests_mounted_directory.sh b/tools/integration_tests/run_tests_mounted_directory.sh index 2531d3d019..e7843299f5 100755 --- a/tools/integration_tests/run_tests_mounted_directory.sh +++ b/tools/integration_tests/run_tests_mounted_directory.sh @@ -105,7 +105,7 @@ sudo umount $MOUNT_DIR # Run tests with config "file-cache: max-size-mb" static mounting. echo "file-cache: max-size-mb: 2 -cache-dir: ./cache-dir +cache-dir: /tmp/cache-dir-operations-hns-false " > /tmp/gcsfuse_config.yaml gcsfuse --config-file=/tmp/gcsfuse_config.yaml $TEST_BUCKET_NAME $MOUNT_DIR GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/operations/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME @@ -163,7 +163,7 @@ sudo umount $MOUNT_DIR # Run tests with config "file-cache: max-size-mb" static mounting. echo "file-cache: max-size-mb: 3 -cache-dir: ./cache-dir +cache-dir: /tmp/cache-dir-readonly-hns-false " > /tmp/gcsfuse_config.yaml gcsfuse --config-file /tmp/gcsfuse_config.yaml --only-dir testDir --file-mode=544 --dir-mode=544 --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/readonly/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME/testDir @@ -261,27 +261,27 @@ sudo umount $MOUNT_DIR # package read_large_files # Run tests with static mounting. (flags: --implicit-dirs) gcsfuse --implicit-dirs $TEST_BUCKET_NAME $MOUNT_DIR -GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR +GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME sudo umount $MOUNT_DIR # Run tests with config "file-cache: max-size-mb, cache-file-for-range-read". echo "file-cache: max-size-mb: 700 cache-file-for-range-read: true -cache-dir: ./cache-dir +cache-dir: /tmp/cache-dir-read-large-files-hns-false " > /tmp/gcsfuse_config.yaml gcsfuse --config-file /tmp/gcsfuse_config.yaml --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR -GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR +GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME sudo umount $MOUNT_DIR # Run tests with config "file-cache: max-size-mb". echo "file-cache: max-size-mb: -1 cache-file-for-range-read: false -cache-dir: ./cache-dir +cache-dir: /tmp/cache-dir-read-large-files-hns-false " > /tmp/gcsfuse_config.yaml gcsfuse --config-file /tmp/gcsfuse_config.yaml --implicit-dirs=true $TEST_BUCKET_NAME $MOUNT_DIR -GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR +GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/read_large_files/... -p 1 --integrationTest -v --mountedDirectory=$MOUNT_DIR --testbucket=$TEST_BUCKET_NAME sudo umount $MOUNT_DIR # package write_large_files @@ -342,8 +342,8 @@ function read_cache_test_setup() { function cleanup_test_environment() { # Clean up any pre-existing log files and cache directory. - rm -rf /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir - mkdir -p /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir + rm -rf /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir-read-cache-hns-false + mkdir -p /tmp/gcsfuse_read_cache_test_logs /tmp/cache-dir-read-cache-hns-false } function generate_config_file() { @@ -368,7 +368,7 @@ metadata-cache: stat-cache-max-size-mb: 4 ttl-secs: $cache_ttl type-cache-max-size-mb: 32 -cache-dir: /tmp/cache-dir" > /tmp/gcsfuse_config.yaml +cache-dir: /tmp/cache-dir-read-cache-hns-false" > /tmp/gcsfuse_config.yaml } function run_read_cache_test() { @@ -552,7 +552,7 @@ test_cases=( ) for test_case in "${test_cases[@]}"; do gcsfuse --kernel-list-cache-ttl-secs=-1 "$TEST_BUCKET_NAME" "$MOUNT_DIR" - GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel-list-cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case" + GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel_list_cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case" sudo umount "$MOUNT_DIR" done @@ -562,7 +562,7 @@ test_cases=( ) for test_case in "${test_cases[@]}"; do gcsfuse --kernel-list-cache-ttl-secs=5 --rename-dir-limit=10 "$TEST_BUCKET_NAME" "$MOUNT_DIR" - GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel-list-cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case" + GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel_list_cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case" sudo umount "$MOUNT_DIR" done @@ -572,7 +572,6 @@ test_cases=( ) for test_case in "${test_cases[@]}"; do gcsfuse --kernel-list-cache-ttl-secs=0 --stat-cache-ttl=0 --rename-dir-limit=10 "$TEST_BUCKET_NAME" "$MOUNT_DIR" - GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel-list-cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case" + GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/kernel_list_cache/... -p 1 --integrationTest -v --mountedDirectory="$MOUNT_DIR" --testbucket="$TEST_BUCKET_NAME" -run "$test_case" sudo umount "$MOUNT_DIR" done -