-
Notifications
You must be signed in to change notification settings - Fork 127
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
DEVPROD-13056: fix s3 put skip_existing failures #8510
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 |
---|---|---|
|
@@ -2,18 +2,25 @@ package command | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go-v2/credentials" | ||
s3Types "github.com/aws/aws-sdk-go-v2/service/s3/types" | ||
"github.com/evergreen-ci/evergreen/agent/internal" | ||
"github.com/evergreen-ci/evergreen/agent/internal/client" | ||
"github.com/evergreen-ci/evergreen/model" | ||
"github.com/evergreen-ci/evergreen/model/artifact" | ||
"github.com/evergreen-ci/evergreen/model/task" | ||
"github.com/evergreen-ci/evergreen/testutil" | ||
"github.com/evergreen-ci/evergreen/util" | ||
"github.com/evergreen-ci/pail" | ||
"github.com/evergreen-ci/utility" | ||
"github.com/mongodb/grip/send" | ||
. "github.com/smartystreets/goconvey/convey" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
@@ -639,3 +646,85 @@ func TestPreservePath(t *testing.T) { | |
} | ||
|
||
} | ||
|
||
func TestS3PutSkipExisting(t *testing.T) { | ||
if skip, _ := strconv.ParseBool(os.Getenv("SKIP_INTEGRATION_TESTS")); skip { | ||
t.Skip("SKIP_INTEGRATION_TESTS is set, skipping integration test") | ||
} | ||
|
||
temproot := t.TempDir() | ||
|
||
settings := testutil.GetIntegrationFile(t) | ||
|
||
firstFilePath := filepath.Join(temproot, "first-file.txt") | ||
secondFilePath := filepath.Join(temproot, "second-file.txt") | ||
|
||
payload := []byte("hello world") | ||
require.NoError(t, os.WriteFile(firstFilePath, payload, 0755)) | ||
require.NoError(t, os.WriteFile(secondFilePath, []byte("second file"), 0755)) | ||
|
||
accessKeyID := settings.Expansions["aws_key"] | ||
secretAccessKey := settings.Expansions["aws_secret"] | ||
token := settings.Expansions["aws_token"] | ||
bucketName := settings.Expansions["bucket"] | ||
region := "us-east-1" | ||
|
||
id := utility.RandomString() | ||
|
||
remoteFile := fmt.Sprintf("tests/%s/%s", t.Name(), id) | ||
|
||
cmd := s3PutFactory() | ||
params := map[string]any{ | ||
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. 🤯 didn't know about 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. It's newish! |
||
"aws_key": accessKeyID, | ||
"aws_secret": secretAccessKey, | ||
"aws_session_token": token, | ||
"local_file": firstFilePath, | ||
"remote_file": remoteFile, | ||
"bucket": bucketName, | ||
"region": region, | ||
"skip_existing": "true", | ||
"content_type": "text/plain", | ||
"permissions": "private", | ||
} | ||
|
||
require.NoError(t, cmd.ParseParams(params)) | ||
|
||
tconf := &internal.TaskConfig{ | ||
Task: task.Task{}, | ||
WorkDir: temproot, | ||
} | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
sender := send.MakeInternalLogger() | ||
logger := client.NewSingleChannelLogHarness("test", sender) | ||
comm := client.NewMock("") | ||
|
||
require.NoError(t, cmd.Execute(ctx, comm, logger, tconf)) | ||
|
||
params["local_file"] = secondFilePath | ||
require.NoError(t, cmd.ParseParams(params)) | ||
|
||
require.NoError(t, cmd.Execute(ctx, comm, logger, tconf)) | ||
|
||
creds := credentials.NewStaticCredentialsProvider(accessKeyID, secretAccessKey, token) | ||
|
||
opts := pail.S3Options{ | ||
Region: region, | ||
Name: bucketName, | ||
Credentials: creds, | ||
} | ||
|
||
bucket, err := pail.NewS3Bucket(ctx, opts) | ||
require.NoError(t, err) | ||
|
||
got, err := bucket.Get(ctx, remoteFile) | ||
require.NoError(t, err) | ||
|
||
content, err := io.ReadAll(got) | ||
require.NoError(t, err) | ||
|
||
// verify that file content wasn't overwritten by the second file | ||
assert.Equal(t, payload, content) | ||
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. Can you add a little comment here, like "verify that file content wasn't overwritten by the second file" 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. Done! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,10 @@ github_pr_creator_org: "10gen" | |
expansions: | ||
papertrail_key_id: $PAPERTRAIL_KEY_ID | ||
papertrail_secret_key: $PAPERTRAIL_SECRET_KEY | ||
aws_key: $AWS_ACCESS_KEY_ID | ||
aws_secret: $AWS_SECRET_ACCESS_KEY | ||
Comment on lines
+77
to
+78
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. Are these meant to be different than the ones used on line 54 and 55? I don't have time for a full review so I may be missing something. 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. I'm not sure where those are coming from honestly -- I'm using the credentials we get from assume role at the beginning of the task! |
||
aws_token: $AWS_SESSION_TOKEN | ||
bucket: evergreen-integration-testing | ||
# Do not edit below this line | ||
github_app_key: | | ||
EOF | ||
|
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.
I think this edit is wrong -- it should still be using length of uploaded files