Skip to content

Commit

Permalink
roachtest: update backup fixtures
Browse files Browse the repository at this point in the history
Previously, backup fixture creation was a manual process. Now, fixture
creation will run as a roachtest and use the fixture registry utility
added by cockroachdb#140368.

Fixture generation was reworked to use import instead of old backup
fixtures. This makes it trivial to bootstrap fixtures in new clouds and
in new fixture buckets.

Release note: none
Part of: cockroachdb#139159
  • Loading branch information
jeffswenson committed Feb 4, 2025
1 parent 118501a commit 728eeeb
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 291 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/roachtest/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ go_library(
"//pkg/multitenant/mtinfopb",
"//pkg/roachpb",
"//pkg/roachprod",
"//pkg/roachprod/blobfixture",
"//pkg/roachprod/config",
"//pkg/roachprod/errors",
"//pkg/roachprod/install",
Expand Down
62 changes: 58 additions & 4 deletions pkg/cmd/roachtest/tests/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,45 @@ func getAWSKMSAssumeRoleURI() (string, error) {
return correctURI, nil
}

func withAuthParameters(uri url.URL) (url.URL, error) {
q := uri.Query()
switch uri.Scheme {
case "gs":
expect := map[string]string{
AssumeRoleGCSCredentials: gcp.CredentialsParam,
AssumeRoleGCSServiceAccount: gcp.AssumeRoleParam,
}
for env, param := range expect {
v := os.Getenv(env)
if v == "" {
return url.URL{}, errors.Newf("env variable %s must be present to run the KMS test", env)
}
// Nightly env uses JSON credentials, which have to be base64 encoded.
if param == gcp.CredentialsParam {
v = base64.StdEncoding.EncodeToString([]byte(v))
}
q.Add(param, v)
}

// Get GCP Key name from env variable.
keyName := os.Getenv(KMSKeyNameAEnvVar)
if keyName == "" {
return url.URL{}, errors.Newf("env variable %s must be present to run the KMS test", KMSKeyNameAEnvVar)
}

// Set AUTH to specified
q.Add(cloudstorage.AuthParam, cloudstorage.AuthParamSpecified)
case "s3":

default:
return url.URL{}, errors.Newf("unsupported scheme %s", uri.Scheme)
}

uri.RawQuery = q.Encode()

return uri, nil
}

func getGCSKMSURI(keyIDEnvVariable string) (string, error) {
q := make(url.Values)
expect := map[string]string{
Expand Down Expand Up @@ -985,7 +1024,7 @@ func getGCSKMSAssumeRoleURI() (string, error) {
return correctURI, nil
}

func getGCSBackupPath(dest string) (string, error) {
func getGCSAuth() (url.Values, error) {
q := make(url.Values)
expect := map[string]string{
AssumeRoleGCSCredentials: gcp.CredentialsParam,
Expand All @@ -994,7 +1033,7 @@ func getGCSBackupPath(dest string) (string, error) {
for env, param := range expect {
v := os.Getenv(env)
if v == "" {
return "", errors.Errorf("env variable %s must be present to run the assume role test", env)
return nil, errors.Errorf("env variable %s must be present to run the assume role test", env)
}

// Nightly env uses JSON credentials, which have to be base64 encoded.
Expand All @@ -1003,6 +1042,14 @@ func getGCSBackupPath(dest string) (string, error) {
}
q.Add(param, v)
}
return q, nil
}

func getGCSBackupPath(dest string) (string, error) {
q, err := getGCSAuth()
if err != nil {
return "", err
}

// Set AUTH to specified
q.Add(cloudstorage.AuthParam, cloudstorage.AuthParamSpecified)
Expand All @@ -1011,7 +1058,7 @@ func getGCSBackupPath(dest string) (string, error) {
return uri, nil
}

func getAWSBackupPath(dest string) (string, error) {
func getS3Auth() (url.Values, error) {
q := make(url.Values)
expect := map[string]string{
AssumeRoleAWSKeyIDEnvVar: amazon.AWSAccessKeyParam,
Expand All @@ -1022,11 +1069,18 @@ func getAWSBackupPath(dest string) (string, error) {
for env, param := range expect {
v := os.Getenv(env)
if v == "" {
return "", errors.Errorf("env variable %s must be present to run the KMS test", env)
return nil, errors.Errorf("env variable %s must be present to run S3 tests", env)
}
q.Add(param, v)
}
q.Add(cloudstorage.AuthParam, cloudstorage.AuthParamSpecified)
return q, nil
}

func getAWSBackupPath(dest string) (string, error) {
q, err := getS3Auth()
if err != nil {
return "", err
}
return fmt.Sprintf("s3://"+backupTestingBucket+"/%s?%s", dest, q.Encode()), nil
}
Loading

0 comments on commit 728eeeb

Please sign in to comment.