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

Convert gcloud operations in storage client - 1 #1959

Merged
merged 33 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b5aea8a
convert cleanup gcs dir function in storage client
Tulsishah May 28, 2024
e42eee9
lint fix
Tulsishah May 28, 2024
8c4dc5c
lint fix
Tulsishah May 28, 2024
5fe00f4
lint fix
Tulsishah May 28, 2024
278ae38
rebasing and trigger integration tests
Tulsishah May 30, 2024
e6c6465
removing gcloud command in dynamic mounting
Tulsishah May 30, 2024
482376b
small fix
Tulsishah May 30, 2024
644e56f
lint fix
Tulsishah May 30, 2024
5d2102e
small fix
Tulsishah May 30, 2024
e5e27ae
small fix
Tulsishah May 30, 2024
02fc741
small changes
Tulsishah May 31, 2024
45194ad
removing testing changes
Tulsishah May 31, 2024
54af9e7
increaing context timeout
Tulsishah May 31, 2024
0abe972
deleting bucket data and then bucket
Tulsishah May 31, 2024
423b128
small fix
Tulsishah May 31, 2024
65ec503
rebasing and small fix
Tulsishah Jun 10, 2024
15988c9
rebasing and small fix
Tulsishah Jun 10, 2024
67dc720
testing crash
Tulsishah Jun 10, 2024
6792f2b
adding stat cache ttl 0
Tulsishah Jun 10, 2024
b520d6c
increasing timeout
Tulsishah Jun 10, 2024
cfec0be
increasing timeout in comment
Tulsishah Jun 10, 2024
1f6b66a
setting bucket and dir path using GetBucketAndObjectBasedOnTypeOfMount
Tulsishah Jun 10, 2024
d60e53f
increase timeout of client
Tulsishah Jun 10, 2024
226a51e
lint fix
Tulsishah Jun 10, 2024
474830e
lint fix
Tulsishah Jun 10, 2024
5f6c0c4
fix cancel client
Tulsishah Jun 10, 2024
59e16e2
small fix
Tulsishah Jun 10, 2024
b4f3c95
review comment
Tulsishah Jun 11, 2024
4a92970
review comments
Tulsishah Jun 12, 2024
8499e04
lint tests
Tulsishah Jun 12, 2024
9acc4ef
lint tests
Tulsishah Jun 12, 2024
04671bc
increasing timeout
Tulsishah Jun 12, 2024
4e2601b
review comment
Tulsishah Jun 13, 2024
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
28 changes: 15 additions & 13 deletions tools/integration_tests/implicit_dir/implicit_dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup/implicit_and_explicit_dir_setup"
Expand All @@ -36,19 +37,23 @@ const NumberOfFilesInExplicitDirInImplicitSubDir = 1
const NumberOfFilesInExplicitDirInImplicitDir = 1
const DirForImplicitDirTests = "dirForImplicitDirTests"

var (
storageClient *storage.Client
ctx context.Context
)

func TestMain(m *testing.M) {
setup.ParseSetUpFlags()

ctx = context.Background()
var cancel context.CancelFunc
var err error

// Create storage client before running tests.
ctx, cancel = context.WithTimeout(ctx, time.Minute*15)
storageClient, err = client.CreateStorageClient(ctx)
if err != nil {
log.Fatalf("client.CreateStorageClient: %v", err)
}
ctx = context.Background()
closeStorageClient := client.CreateStorageClientWithTimeOut(&ctx, &storageClient, time.Minute*15)
defer func() {
err := closeStorageClient()
if err != nil {
log.Fatalf("closeStorageClient failed: %v", err)
}
}()

flagsSet := [][]string{{"--implicit-dirs"}}

Expand All @@ -58,10 +63,7 @@ func TestMain(m *testing.M) {

successCode := implicit_and_explicit_dir_setup.RunTestsForImplicitDirAndExplicitDir(flagsSet, m)

// Close storage client and release resources.
storageClient.Close()
cancel()
// Clean up test directory created.
setup.CleanupDirectoryOnGCS(path.Join(setup.TestBucket(), testDirName))
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(setup.TestBucket(), testDirName))
os.Exit(successCode)
}
4 changes: 0 additions & 4 deletions tools/integration_tests/implicit_dir/local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
"path/filepath"
"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/operations"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
"golang.org/x/net/context"
)

const (
Expand All @@ -32,8 +30,6 @@ const (

var (
testDirPath string
storageClient *storage.Client
ctx context.Context
)

// //////////////////////////////////////////////////////////////////////
Expand Down
18 changes: 16 additions & 2 deletions tools/integration_tests/interrupt/interrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@
package interrupt

import (
"context"
"log"
"os"
"path"
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"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/setup"
)
Expand All @@ -34,7 +39,16 @@ const (

func TestMain(m *testing.M) {
setup.ParseSetUpFlags()
setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

var storageClient *storage.Client
ctx := context.Background()
closeStorageClient := client.CreateStorageClientWithTimeOut(&ctx, &storageClient, time.Minute*15)
defer func() {
err := closeStorageClient()
if err != nil {
log.Fatalf("closeStorageClient failed: %v", err)
}
}()

setup.RunTestsForMountedDirectoryFlag(m)

Expand All @@ -56,6 +70,6 @@ func TestMain(m *testing.M) {
successCode := static_mounting.RunTests(flags, m)

// Clean up test directory created.
setup.CleanupDirectoryOnGCS(path.Join(setup.TestBucket(), testDirName))
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(setup.TestBucket(), testDirName))
os.Exit(successCode)
}
25 changes: 10 additions & 15 deletions tools/integration_tests/local_file/local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,17 @@ func NewFileShouldGetSyncedToGCSAtClose(ctx context.Context, storageClient *stor
func TestMain(m *testing.M) {
setup.ParseSetUpFlags()

ctx = context.Background()
var cancel context.CancelFunc
var err error

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

// Create storage client before running tests.
ctx, cancel = context.WithTimeout(ctx, time.Minute*15)
storageClient, err = client.CreateStorageClient(ctx)
if err != nil {
log.Fatalf("client.CreateStorageClient: %v", err)
}

ctx = context.Background()
closeStorageClient := client.CreateStorageClientWithTimeOut(&ctx, &storageClient, time.Minute*15)
defer func() {
err := closeStorageClient()
if err != nil {
log.Fatalf("closeStorageClient failed: %v", err)
}
}()
// To run mountedDirectory tests, we need both testBucket and mountedDirectory
// flags to be set, as local_file tests validates content from the bucket.
if setup.AreBothMountedDirectoryAndTestBucketFlagsSet() {
Expand Down Expand Up @@ -114,13 +112,10 @@ func TestMain(m *testing.M) {
}

if successCode == 0 {
successCode = dynamic_mounting.RunTests(flagsSet, m)
successCode = dynamic_mounting.RunTests(ctx, storageClient, flagsSet, m)
}

// Close storage client and release resources.
storageClient.Close()
cancel()
// Clean up test directory created.
setup.CleanupDirectoryOnGCS(path.Join(setup.TestBucket(), testDirName))
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(setup.TestBucket(), testDirName))
os.Exit(successCode)
}
23 changes: 20 additions & 3 deletions tools/integration_tests/log_rotation/log_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@
package log_rotation

import (
"context"
"log"
"os"
"path"
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"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/setup"
)
Expand All @@ -36,8 +41,10 @@ const (
logFileCount = activeLogFileCount + backupLogFileCount
)

var logDirPath string
var logFilePath string
var (
logDirPath string
logFilePath string
)

func getMountConfigForLogRotation(maxFileSizeMB, backupFileCount int, compress bool,
logFilePath string) config.MountConfig {
Expand All @@ -62,6 +69,16 @@ func getMountConfigForLogRotation(maxFileSizeMB, backupFileCount int, compress b
func TestMain(m *testing.M) {
setup.ParseSetUpFlags()

var storageClient *storage.Client
ctx := context.Background()
closeStorageClient := client.CreateStorageClientWithTimeOut(&ctx, &storageClient, time.Minute*15)
defer func() {
err := closeStorageClient()
if err != nil {
log.Fatalf("closeStorageClient failed: %v", err)
}
}()

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

// Run tests for mountedDirectory only if --mountedDirectory flag is set.
Expand Down Expand Up @@ -97,6 +114,6 @@ func TestMain(m *testing.M) {
successCode := static_mounting.RunTests(flags, m)

// Clean up test directory created.
setup.CleanupDirectoryOnGCS(path.Join(setup.TestBucket(), testDirName))
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(setup.TestBucket(), testDirName))
os.Exit(successCode)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (s *enableEmptyManagedFoldersTrue) Teardown(t *testing.T) {
bucket, testDir := setup.GetBucketAndObjectBasedOnTypeOfMount(TestDirForEmptyManagedFoldersTest)
operations.DeleteManagedFoldersInBucket(path.Join(testDir, EmptyManagedFolder1), setup.TestBucket())
operations.DeleteManagedFoldersInBucket(path.Join(testDir, EmptyManagedFolder2), setup.TestBucket())
setup.CleanupDirectoryOnGCS(path.Join(bucket, testDir))
setup.CleanupDirectoryOnGCS(ctx, storageClient, path.Join(bucket, testDir))
}

////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
package managed_folders

import (
"context"
"log"
"os"
"path"
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/operations"

"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/mounting/only_dir_mounting"
Expand All @@ -39,7 +43,9 @@ var (
// Mount directory is where our tests run.
mountDir string
// Root directory is the directory to be unmounted.
rootDir string
rootDir string
storageClient *storage.Client
ctx context.Context
)

////////////////////////////////////////////////////////////////////////
Expand All @@ -49,6 +55,15 @@ var (
func TestMain(m *testing.M) {
setup.ParseSetUpFlags()

ctx = context.Background()
closeStorageClient := client.CreateStorageClientWithTimeOut(&ctx, &storageClient, time.Minute*25)
defer func() {
err := closeStorageClient()
if err != nil {
log.Fatalf("closeStorageClient failed: %v", err)
}
}()

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

if setup.MountedDirectory() != "" {
Expand Down
6 changes: 4 additions & 2 deletions tools/integration_tests/managed_folders/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package managed_folders

import (
"context"
"encoding/json"
"fmt"
"io/fs"
Expand All @@ -25,6 +26,7 @@ import (
"strings"
"testing"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/operations"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/setup"
)
Expand Down Expand Up @@ -113,12 +115,12 @@ func createDirectoryStructureForNonEmptyManagedFolders(t *testing.T) {
operations.CopyFileInBucket(path.Join("/tmp", FileInNonEmptyManagedFoldersTest), testDir, bucket, t)
}

func cleanup(bucket, testDir, serviceAccount, iam_role string, t *testing.T) {
func cleanup(ctx context.Context, client *storage.Client, bucket, testDir, serviceAccount, iam_role string, t *testing.T) {
revokePermissionToManagedFolder(bucket, path.Join(testDir, ManagedFolder1), serviceAccount, iam_role, t)
revokePermissionToManagedFolder(bucket, path.Join(testDir, ManagedFolder2), serviceAccount, iam_role, t)
operations.DeleteManagedFoldersInBucket(path.Join(testDir, ManagedFolder1), setup.TestBucket())
operations.DeleteManagedFoldersInBucket(path.Join(testDir, ManagedFolder2), setup.TestBucket())
setup.CleanupDirectoryOnGCS(path.Join(bucket, testDir))
setup.CleanupDirectoryOnGCS(ctx, client, path.Join(bucket, testDir))
}

func listNonEmptyManagedFolders(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestManagedFolders_FolderViewPermission(t *testing.T) {
bucket, testDir = setup.GetBucketAndObjectBasedOnTypeOfMount(TestDirForManagedFolderTest)
// Create directory structure for testing.
createDirectoryStructureForNonEmptyManagedFolders(t)
defer cleanup(bucket, testDir, serviceAccount, IAMRoleForViewPermission, t)
defer cleanup(ctx, storageClient, bucket, testDir, serviceAccount, IAMRoleForViewPermission, t)

// Run tests.
log.Printf("Running tests with flags and managed folder have nil permissions: %s", flags)
Expand Down
17 changes: 16 additions & 1 deletion tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
package operations_test

import (
"context"
"log"
"os"
"path"
"testing"
"time"

"cloud.google.com/go/storage"
"github.com/googlecloudplatform/gcsfuse/v2/internal/config"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/client"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/creds_tests"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/mounting/dynamic_mounting"
"github.com/googlecloudplatform/gcsfuse/v2/tools/integration_tests/util/mounting/only_dir_mounting"
Expand Down Expand Up @@ -140,6 +145,16 @@ func TestMain(m *testing.M) {

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

// Create storage client before running tests.
ctx := context.Background()
var storageClient *storage.Client
closeStorageClient := client.CreateStorageClientWithTimeOut(&ctx, &storageClient, time.Minute*15)
defer func() {
err := closeStorageClient()
if err != nil {
log.Fatalf("closeStorageClient failed: %v", err)
}
}()
// 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() {
Expand Down Expand Up @@ -174,7 +189,7 @@ func TestMain(m *testing.M) {
}

if successCode == 0 {
successCode = dynamic_mounting.RunTests(flagsSet, m)
successCode = dynamic_mounting.RunTests(ctx, storageClient, flagsSet, m)
}

if successCode == 0 {
Expand Down
8 changes: 4 additions & 4 deletions tools/integration_tests/read_cache/remount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func (s *remountTest) TestCacheIsNotReusedOnDynamicRemount(t *testing.T) {
runTestsOnlyForDynamicMount(t)
testBucket1 := setup.TestBucket()
testFileName1 := setupFileInTestDir(s.ctx, s.storageClient, testDirName, fileSize, t)
testBucket2 := dynamic_mounting.CreateTestBucketForDynamicMounting()
defer dynamic_mounting.DeleteTestBucketForDynamicMounting(testBucket2)
testBucket2 := dynamic_mounting.CreateTestBucketForDynamicMounting(ctx, storageClient)
defer dynamic_mounting.DeleteTestBucketForDynamicMounting(ctx, storageClient, testBucket2)
setup.SetDynamicBucketMounted(testBucket2)
defer setup.SetDynamicBucketMounted("")
// Introducing a sleep of 7 seconds after bucket creation to address propagation delays.
time.Sleep(7 * time.Second)
// Introducing a sleep of 10 seconds after bucket creation to address propagation delays.
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
time.Sleep(10 * time.Second)
client.SetupTestDirectory(s.ctx, s.storageClient, testDirName)
testFileName2 := setupFileInTestDir(s.ctx, s.storageClient, testDirName, fileSize, t)

Expand Down
Loading
Loading