Skip to content

Commit

Permalink
Running all the integration test with --only-dir mounting (#1100)
Browse files Browse the repository at this point in the history
* adding --only-dir mounting in integration tests

* updating function name and removing unnecessary files

* Upating comments

* linux tests

* local changes

* renaming directory

* fixing merge conflict

* fixing merge conflict

* small fix

* adding test case where directory exist in only dir mounting

* adding test case where directory exist in only dir mounting

* new line

* adding licence

* fixed comments

* fixing comments

* formating

* fixing lint tests

* fixing comments

* fixing comments

* fixing lint tests

* fixing lint tests

* small fix

* small fix

* updating functions name

* small fix

* adding comment

* adding comment

* fixing comments

* resolving comments

* fixed comments
  • Loading branch information
Tulsishah committed May 23, 2023
1 parent 976f724 commit 9438a11
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 85 deletions.
2 changes: 1 addition & 1 deletion perfmetrics/scripts/continuous_test/gcp_ubuntu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ commitId=$(git log --before='yesterday 23:59:59' --max-count=1 --pretty=%H)
git checkout $commitId

echo "Executing integration tests"
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/... -p 1 --integrationTest -v --testbucket=gcsfuse-integration-test
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/... -p 1 --integrationTest -v --testbucket=gcsfuse-integration-test -timeout=60m

# Checkout back to master branch to use latest CI test scripts in master.
git checkout master
Expand Down
2 changes: 1 addition & 1 deletion perfmetrics/scripts/presubmit_test/pr_perf_test/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ echo checkout PR branch
git checkout pr/$KOKORO_GITHUB_PULL_REQUEST_NUMBER

# Executing integration tests
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/... -p 1 --integrationTest -v --testbucket=gcsfuse-integration-test
GODEBUG=asyncpreemptoff=1 go test ./tools/integration_tests/... -p 1 --integrationTest -v --testbucket=gcsfuse-integration-test -timeout=60m

# Executing perf tests
echo Mounting gcs bucket from pr branch
Expand Down
14 changes: 13 additions & 1 deletion tools/integration_tests/operations/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

Expand All @@ -44,12 +46,22 @@ func TestMain(m *testing.M) {
{"--implicit-dirs=true"},
{"--implicit-dirs=false"}}

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

if setup.TestBucket() != "" && setup.MountedDirectory() != "" {
log.Printf("Both --testbucket and --mountedDirectory can't be specified at the same time.")
os.Exit(1)
}

successCode := setup.RunTests(flags, m)
// Run tests for mountedDirectory only if --mountedDirectory flag is set.
setup.RunTestsForMountedDirectoryFlag(m)

// Run tests for testBucket
successCode := static_mounting.RunTests(flags, m)

if successCode == 0 {
successCode = only_dir_mounting.RunTests(flags, m)
}

os.Exit(successCode)
}
25 changes: 11 additions & 14 deletions tools/integration_tests/readonly/readonly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package readonly_test
import (
"log"
"os"
"os/exec"
"strings"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

Expand All @@ -41,15 +41,6 @@ const ContentInFileInSubDirectoryTestBucket = "This is from directory Test/b fil
const RenameFile = "rename.txt"
const RenameDir = "rename"

// Run shell script
func runScriptForTestData(script string, testBucket string) {
cmd := exec.Command("/bin/bash", script, testBucket)
_, err := cmd.Output()
if err != nil {
panic(err)
}
}

func checkErrorForReadOnlyFileSystem(err error, t *testing.T) {
if !strings.Contains(err.Error(), "read-only file system") && !strings.Contains(err.Error(), "permission denied") {
t.Errorf("Incorrect error for readonly filesystem: %v", err.Error())
Expand All @@ -67,21 +58,27 @@ func TestMain(m *testing.M) {

flags := [][]string{{"--o=ro", "--implicit-dirs=true"}, {"--file-mode=544", "--dir-mode=544", "--implicit-dirs=true"}}

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

if setup.TestBucket() == "" && setup.MountedDirectory() != "" {
log.Printf("Please pass the name of bucket mounted at mountedDirectory to --testBucket flag.")
os.Exit(1)
}

// Run tests for testBucket
// Clean the bucket for readonly testing.
runScriptForTestData("testdata/delete_objects.sh", setup.TestBucket())
setup.RunScriptForTestData("testdata/delete_objects.sh", setup.TestBucket())

// Create objects in bucket for testing.
runScriptForTestData("testdata/create_objects.sh", setup.TestBucket())
setup.RunScriptForTestData("testdata/create_objects.sh", setup.TestBucket())

// Run tests for mountedDirectory only if --mountedDirectory flag is set.
setup.RunTestsForMountedDirectoryFlag(m)

successCode := setup.RunTests(flags, m)
successCode := static_mounting.RunTests(flags, m)

// Delete objects from bucket after testing.
runScriptForTestData("testdata/delete_objects.sh", setup.TestBucket())
setup.RunScriptForTestData("testdata/delete_objects.sh", setup.TestBucket())

os.Exit(successCode)
}
14 changes: 14 additions & 0 deletions tools/integration_tests/readonly/testdata/create_objects.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Here $1 refers to the testBucket argument
echo "This is from directory Test file a" >> a.txt
gsutil mv a.txt gs://$1/Test/
Expand Down
14 changes: 14 additions & 0 deletions tools/integration_tests/readonly/testdata/delete_objects.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Here $1 refers to the testBucket argument
gsutil rm -a gs://$1/**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"os"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/only_dir_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting/static_mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

Expand All @@ -37,12 +39,22 @@ func TestMain(m *testing.M) {

flags := [][]string{{"--rename-dir-limit=3", "--implicit-dirs"}, {"--rename-dir-limit=3"}}

setup.ExitWithFailureIfBothTestBucketAndMountedDirectoryFlagsAreNotSet()

if setup.TestBucket() != "" && setup.MountedDirectory() != "" {
log.Printf("Both --testbucket and --mountedDirectory can't be specified at the same time.")
os.Exit(1)
}

successCode := setup.RunTests(flags, m)
// Run tests for mountedDirectory only if --mountedDirectory flag is set.
setup.RunTestsForMountedDirectoryFlag(m)

// Run tests for testBucket
successCode := static_mounting.RunTests(flags, m)

if successCode == 0 {
successCode = only_dir_mounting.RunTests(flags, m)
}

os.Exit(successCode)
}
50 changes: 50 additions & 0 deletions tools/integration_tests/util/mounting/mounting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2023 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package mounting

import (
"fmt"
"log"
"os"
"os/exec"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

func MountGcsfuse(flags []string) error {
mountCmd := exec.Command(
setup.BinFile(),
flags...,
)

// Adding mount command in LogFile
file, err := os.OpenFile(setup.LogFile(), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Println("Could not open logfile")
}
defer file.Close()

_, err = file.WriteString(mountCmd.String() + "\n")
if err != nil {
fmt.Println("Could not write cmd to logFile")
}

_, err = mountCmd.CombinedOutput()
if err != nil {
log.Println(mountCmd.String())
return fmt.Errorf("cannot mount gcsfuse: %w\n", err)
}
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2023 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package only_dir_mounting

import (
"fmt"
"log"
"path"
"testing"

"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/mounting"
"github.com/googlecloudplatform/gcsfuse/tools/integration_tests/util/setup"
)

const DirectoryInTestBucket = "Test"

func mountGcsfuseWithOnlyDir(flags []string, dir string) (err error) {
defaultArg := []string{"--only-dir",
dir,
"--debug_gcs",
"--debug_fs",
"--debug_fuse",
"--log-file=" + setup.LogFile(),
"--log-format=text",
setup.TestBucket(),
setup.MntDir()}

for i := 0; i < len(defaultArg); i++ {
flags = append(flags, defaultArg[i])
}

err = mounting.MountGcsfuse(flags)

return err
}

func mountGcsFuseForFlagsAndExecuteTests(flags [][]string, dir string, m *testing.M) (successCode int) {
for i := 0; i < len(flags); i++ {
if err := mountGcsfuseWithOnlyDir(flags[i], dir); err != nil {
setup.LogAndExit(fmt.Sprintf("mountGcsfuse: %v\n", err))
}
successCode = setup.ExecuteTestForFlagsSet(flags[i], m)
}
return
}

func executeTestsForOnlyDirMounting(flags [][]string, m *testing.M) (successCode int) {
setup.SetUpTestDirForTestBucketFlag()

mountDirInBucket := path.Join(setup.TestBucket(), DirectoryInTestBucket)
// Clean the bucket.

setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/delete_objects.sh", setup.TestBucket())

// "Test" directory not exist in bucket.
mountGcsFuseForFlagsAndExecuteTests(flags, DirectoryInTestBucket, m)

// "Test" directory exist in bucket.
// Clean the bucket.
setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/delete_objects.sh", setup.TestBucket())

// Create Test directory in bucket.
setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/create_objects.sh", mountDirInBucket)

successCode = mountGcsFuseForFlagsAndExecuteTests(flags, DirectoryInTestBucket, m)

// Clean the bucket after testing.
setup.RunScriptForTestData("../util/mounting/only_dir_mounting/testdata/delete_objects.sh", setup.TestBucket())

return
}

func RunTests(flags [][]string, m *testing.M) (successCode int) {
successCode = executeTestsForOnlyDirMounting(flags, m)

log.Printf("Test log: %s\n", setup.LogFile())

return successCode
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

touch a.txt
gsutil mv a.txt gs://$1/
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2023 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Here $1 refers to the testBucket argument
gsutil rm -a gs://$1/**

# If bucket is empty it will throw an CommandException.
if [ $? -eq 1 ]; then
echo "Bucket is already empty."
exit 0
fi

0 comments on commit 9438a11

Please sign in to comment.