@@ -10,6 +10,7 @@ import (
10
10
gosql "database/sql"
11
11
"fmt"
12
12
"net/url"
13
+ "os"
13
14
"path"
14
15
"time"
15
16
@@ -33,8 +34,21 @@ import (
33
34
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
34
35
"github.com/cockroachdb/errors"
35
36
"github.com/stretchr/testify/require"
37
+ "gopkg.in/yaml.v3"
36
38
)
37
39
40
+ // At the moment, Azure VMs do not have managed identities set up yet.
41
+ // Therefore, in order to use implicit authentication, we need to put a
42
+ // credentials file on each VM and point the
43
+ // `COCKROACH_AZURE_APPLICATION_CREDENTIALS_FILE` environment variable at the
44
+ // file.
45
+ // Currently, the only set of credentials that have write access to the storage
46
+ // buckets are the Teamcity credentials, so the Azure fixture roachtests cannot
47
+ // be run locally until those managed identities are set up.
48
+ // TODO (kev-cao): Once managed identities are set up, we can remove this file
49
+ // and rely on the managed identity to authenticate with Azure Blob Storage.
50
+ const azureCredentialsFilePath = "/home/ubuntu/azure-credentials.yaml"
51
+
38
52
type BackupFixture interface {
39
53
Kind () string
40
54
// The database that is backed up.
@@ -159,13 +173,20 @@ type backupDriver struct {
159
173
}
160
174
161
175
func (bd * backupDriver ) prepareCluster (ctx context.Context ) {
162
- bd .c .Start (ctx , bd .t .L (), option .NewStartOpts (option .NoBackupSchedule ), install .MakeClusterSettings (install.ClusterSettingsOption {
163
- // Large imports can run into a death spiral where splits fail because
164
- // there is a snapshot backlog, which makes the snapshot backlog worse
165
- // because add sst causes ranges to fall behind and need recovery snapshots
166
- // to catch up.
167
- "kv.snapshot_rebalance.max_rate" : "256 MiB" ,
168
- }))
176
+ bd .c .Start (
177
+ ctx , bd .t .L (), option .NewStartOpts (option .NoBackupSchedule ),
178
+ install .MakeClusterSettings (
179
+ install.ClusterSettingsOption {
180
+ // Large imports can run into a death spiral where splits fail because
181
+ // there is a snapshot backlog, which makes the snapshot backlog worse
182
+ // because add sst causes ranges to fall behind and need recovery snapshots
183
+ // to catch up.
184
+ "kv.snapshot_rebalance.max_rate" : "256 MiB" ,
185
+ },
186
+ install.EnvOption {
187
+ fmt .Sprintf ("COCKROACH_AZURE_APPLICATION_CREDENTIALS_FILE=%s" , azureCredentialsFilePath ),
188
+ },
189
+ ))
169
190
}
170
191
171
192
func (bd * backupDriver ) initWorkload (ctx context.Context ) {
@@ -513,6 +534,12 @@ func GetFixtureRegistry(ctx context.Context, t test.Test, cloud spec.Cloud) *blo
513
534
Host : "cockroach-fixtures-us-east-2" ,
514
535
RawQuery : "AUTH=implicit" ,
515
536
}
537
+ case spec .Azure :
538
+ uri = url.URL {
539
+ Scheme : "azure-blob" ,
540
+ Host : "cockroachdb-fixtures-eastus" ,
541
+ RawQuery : "AUTH=implicit&AZURE_ACCOUNT_NAME=roachtest" ,
542
+ }
516
543
case spec .GCE , spec .Local :
517
544
account , err := vm .Providers ["gce" ].FindActiveAccount (t .L ())
518
545
require .NoError (t , err )
@@ -544,7 +571,7 @@ func registerBackupFixtures(r registry.Registry) {
544
571
}),
545
572
timeout : 30 * time .Minute ,
546
573
suites : registry .Suites (registry .Nightly ),
547
- clouds : []spec.Cloud {spec .AWS , spec .GCE , spec .Local },
574
+ clouds : []spec.Cloud {spec .AWS , spec .Azure , spec . GCE , spec .Local },
548
575
},
549
576
{
550
577
fixture : SmallFixture ,
@@ -555,7 +582,7 @@ func registerBackupFixtures(r registry.Registry) {
555
582
// fixture on top of the allocated 2 hours for the test.
556
583
timeout : 3 * time .Hour ,
557
584
suites : registry .Suites (registry .Nightly ),
558
- clouds : []spec.Cloud {spec .AWS , spec .GCE },
585
+ clouds : []spec.Cloud {spec .AWS , spec .Azure , spec . GCE },
559
586
},
560
587
{
561
588
fixture : MediumFixture ,
@@ -566,7 +593,7 @@ func registerBackupFixtures(r registry.Registry) {
566
593
}),
567
594
timeout : 12 * time .Hour ,
568
595
suites : registry .Suites (registry .Weekly ),
569
- clouds : []spec.Cloud {spec .AWS , spec .GCE },
596
+ clouds : []spec.Cloud {spec .AWS , spec .Azure , spec . GCE },
570
597
// The fixture takes an estimated 3.5 hours to fingerprint, so we skip it.
571
598
skipFingerprint : true ,
572
599
},
@@ -604,6 +631,7 @@ func registerBackupFixtures(r registry.Registry) {
604
631
Suites : bf .suites ,
605
632
Skip : bf .skip ,
606
633
Run : func (ctx context.Context , t test.Test , c cluster.Cluster ) {
634
+ require .NoError (t , maybePutAzureCredentialsFile (ctx , c , azureCredentialsFilePath ))
607
635
registry := GetFixtureRegistry (ctx , t , c .Cloud ())
608
636
609
637
handle , err := registry .Create (ctx , bf .fixture .Name , t .L ())
@@ -638,6 +666,44 @@ func registerBackupFixtures(r registry.Registry) {
638
666
}
639
667
}
640
668
669
+ func maybePutAzureCredentialsFile (ctx context.Context , c cluster.Cluster , path string ) error {
670
+ if c .Cloud () != spec .Azure {
671
+ return nil
672
+ }
673
+
674
+ type azureCreds struct {
675
+ TenantID string `yaml:"azure_tenant_id"`
676
+ ClientID string `yaml:"azure_client_id"`
677
+ ClientSecret string `yaml:"azure_client_secret"`
678
+ }
679
+
680
+ azureEnvVars := []string {AzureTenantIDEnvVar , AzureClientIDEnvVar , AzureClientSecretEnvVar }
681
+ azureEnvValues := make (map [string ]string )
682
+ for _ , envVar := range azureEnvVars {
683
+ val := os .Getenv (envVar )
684
+ if val == "" {
685
+ return errors .Newf ("environment variable %s is not set" , envVar )
686
+ }
687
+ azureEnvValues [envVar ] = val
688
+ }
689
+
690
+ creds := azureCreds {
691
+ TenantID : azureEnvValues [AzureTenantIDEnvVar ],
692
+ ClientID : azureEnvValues [AzureClientIDEnvVar ],
693
+ ClientSecret : azureEnvValues [AzureClientSecretEnvVar ],
694
+ }
695
+
696
+ credsYaml , err := yaml .Marshal (creds )
697
+ if err != nil {
698
+ return errors .Wrapf (err , "failed to marshal Azure credentials to YAML" )
699
+ }
700
+
701
+ return errors .Wrap (
702
+ c .PutString (ctx , string (credsYaml ), path , 0700 ),
703
+ "failed to put Azure credentials file in cluster" ,
704
+ )
705
+ }
706
+
641
707
func registerBlobFixtureGC (r registry.Registry ) {
642
708
r .Add (registry.TestSpec {
643
709
Name : "blobfixture/gc" ,
0 commit comments