Merge branch '15370-loopback-dispatchcloud'
[arvados.git] / lib / config / deprecated_keepstore_test.go
index 42ea9bbc7867458aa2ab9524ca2f34e6fe7b24df..ff1d8be7bd9763abac7246bb092b51c6f5498427 100644 (file)
@@ -17,8 +17,8 @@ import (
        "text/template"
        "time"
 
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
-       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
+       "git.arvados.org/arvados.git/sdk/go/arvados"
+       "git.arvados.org/arvados.git/sdk/go/arvadostest"
        check "gopkg.in/check.v1"
 )
 
@@ -30,6 +30,10 @@ type KeepstoreMigrationSuite struct {
 var _ = check.Suite(&KeepstoreMigrationSuite{})
 
 func (s *KeepstoreMigrationSuite) SetUpSuite(c *check.C) {
+       os.Setenv("ARVADOS_API_HOST", os.Getenv("ARVADOS_TEST_API_HOST"))
+       os.Setenv("ARVADOS_API_HOST_INSECURE", "1")
+       os.Setenv("ARVADOS_API_TOKEN", arvadostest.AdminToken)
+
        // We don't need the keepstore servers, but we do need
        // keep_services listings that point to localhost, rather than
        // the apiserver fixtures that point to fictional hosts
@@ -88,33 +92,56 @@ func (s *KeepstoreMigrationSuite) TestDeprecatedKeepstoreConfig(c *check.C) {
        c.Assert(err, check.IsNil)
 
        s.checkEquivalentWithKeepstoreConfig(c, `
-Listen: ":12345"
+Listen: ":25107"
 Debug: true
 LogFormat: text
 MaxBuffers: 1234
 MaxRequests: 2345
 BlobSignatureTTL: 123m
 BlobSigningKeyFile: `+keyfile.Name()+`
+Volumes:
+- Type: Directory
+  Root: /tmp
 `, `
 Clusters:
   z1111:
-    {}
+    SystemRootToken: `+arvadostest.AdminToken+`
+    TLS: {Insecure: true}
+    Services:
+      Controller:
+        ExternalURL: "https://`+os.Getenv("ARVADOS_API_HOST")+`/"
 `, `
 Clusters:
   z1111:
+    SystemRootToken: `+arvadostest.AdminToken+`
+    TLS: {Insecure: true}
     Services:
       Keepstore:
         InternalURLs:
-          "http://`+hostname+`:12345": {}
+          "http://`+hostname+`:25107": {Rendezvous: `+s.ksByPort[25107].UUID[12:]+`}
+      Controller:
+        ExternalURL: "https://`+os.Getenv("ARVADOS_API_HOST")+`/"
     SystemLogs:
       Format: text
       LogLevel: debug
     API:
-      MaxKeepBlockBuffers: 1234
+      MaxKeepBlobBuffers: 1234
       MaxConcurrentRequests: 2345
     Collections:
       BlobSigningTTL: 123m
       BlobSigningKey: blobsigningkey
+    Volumes:
+      z1111-nyw5e-`+s.ksByPort[25107].UUID[12:]+`:
+        AccessViaHosts:
+          "http://`+hostname+`:25107":
+            ReadOnly: false
+        Driver: Directory
+        DriverParameters:
+          Root: /tmp
+          Serialize: false
+        ReadOnly: false
+        Replication: 1
+        StorageClasses: {}
 `)
 }
 
@@ -198,8 +225,8 @@ Volumes:
                Driver:      "S3",
                Replication: 4,
        }, &arvados.S3VolumeDriverParameters{
-               AccessKey:          "accesskeydata",
-               SecretKey:          "secretkeydata",
+               AccessKeyID:        "accesskeydata",
+               SecretAccessKey:    "secretkeydata",
                Endpoint:           "https://storage.googleapis.com",
                Region:             "us-east-1z",
                Bucket:             "testbucket",
@@ -227,7 +254,7 @@ Volumes:
   ReadOnly: true
   StorageAccountName: storageacctname
   StorageAccountKeyFile: `+secretkeyfile.Name()+`
-  StorageBaseURL: https://example.example
+  StorageBaseURL: https://example.example/
   ContainerName: testctr
   LocationConstraint: true
   AzureReplication: 4
@@ -241,7 +268,7 @@ Volumes:
        }, &arvados.AzureVolumeDriverParameters{
                StorageAccountName:   "storageacctname",
                StorageAccountKey:    "secretkeydata",
-               StorageBaseURL:       "https://example.example",
+               StorageBaseURL:       "https://example.example/",
                ContainerName:        "testctr",
                RequestTimeout:       arvados.Duration(time.Minute * 3),
                ListBlobsRetryDelay:  arvados.Duration(time.Minute * 4),
@@ -306,7 +333,7 @@ func (s *KeepstoreMigrationSuite) testDeprecatedVolume(c *check.C, oldconfigdata
                c.Check(v.Driver, check.Equals, expectvol.Driver)
                c.Check(v.Replication, check.Equals, expectvol.Replication)
 
-               avh, ok := v.AccessViaHosts[arvados.URL{Scheme: "http", Host: hostname + ":12345"}]
+               avh, ok := v.AccessViaHosts[arvados.URL{Scheme: "http", Host: hostname + ":12345", Path: "/"}]
                c.Check(ok, check.Equals, true)
                c.Check(avh.ReadOnly, check.Equals, expectvol.ReadOnly)
 
@@ -489,6 +516,7 @@ Volumes:
        url := arvados.URL{
                Scheme: "http",
                Host:   fmt.Sprintf("%s:%d", hostname, port),
+               Path:   "/",
        }
        _, ok := before["zzzzz-nyw5e-readonlyonother"].AccessViaHosts[url]
        c.Check(ok, check.Equals, false)
@@ -516,6 +544,7 @@ Volumes:
        url := arvados.URL{
                Scheme: "http",
                Host:   fmt.Sprintf("%s:%d", hostname, port),
+               Path:   "/",
        }
        _, ok := before["zzzzz-nyw5e-writableonother"].AccessViaHosts[url]
        c.Check(ok, check.Equals, false)
@@ -545,10 +574,39 @@ Volumes:
 
        hostname, err := os.Hostname()
        c.Assert(err, check.IsNil)
-       _, ok := newvol.AccessViaHosts[arvados.URL{Scheme: "http", Host: fmt.Sprintf("%s:%d", hostname, port)}]
+       _, ok := newvol.AccessViaHosts[arvados.URL{Scheme: "http", Host: fmt.Sprintf("%s:%d", hostname, port), Path: "/"}]
        c.Check(ok, check.Equals, true)
 }
 
+// Ensure logs mention unmigrated servers.
+func (s *KeepstoreMigrationSuite) TestPendingKeepstoreMigrations(c *check.C) {
+       client := arvados.NewClientFromEnv()
+       for _, host := range []string{"keep0", "keep1"} {
+               err := client.RequestAndDecode(new(struct{}), "POST", "arvados/v1/keep_services", nil, map[string]interface{}{
+                       "keep_service": map[string]interface{}{
+                               "service_type": "disk",
+                               "service_host": host + ".zzzzz.example.com",
+                               "service_port": 25107,
+                       },
+               })
+               c.Assert(err, check.IsNil)
+       }
+
+       port, _ := s.getTestKeepstorePortAndMatchingVolumeUUID(c)
+       logs := s.logsWithKeepstoreConfig(c, `
+Listen: :`+strconv.Itoa(port)+`
+Volumes:
+- Type: S3
+  Endpoint: https://storage.googleapis.com
+  Bucket: foo
+`)
+       c.Check(logs, check.Matches, `(?ms).*you should remove the legacy keepstore config file.*`)
+       c.Check(logs, check.Matches, `(?ms).*you should migrate the legacy keepstore configuration file on host keep1.zzzzz.example.com.*`)
+       c.Check(logs, check.Not(check.Matches), `(?ms).*should migrate.*keep0.zzzzz.example.com.*`)
+       c.Check(logs, check.Matches, `(?ms).*keepstore configured at http://keep2.zzzzz.example.com:25107/ does not have access to any volumes.*`)
+       c.Check(logs, check.Matches, `(?ms).*Volumes.zzzzz-nyw5e-possconfigerror.AccessViaHosts refers to nonexistent keepstore server http://keep00.zzzzz.example.com:25107.*`)
+}
+
 const clusterConfigForKeepstoreMigrationTest = `
 Clusters:
   zzzzz:
@@ -557,6 +615,8 @@ Clusters:
       Keepstore:
         InternalURLs:
           "http://{{.hostname}}:12345": {}
+          "http://keep0.zzzzz.example.com:25107": {}
+          "http://keep2.zzzzz.example.com:25107": {}
       Controller:
         ExternalURL: "https://{{.controller}}"
     TLS:
@@ -575,7 +635,7 @@ Clusters:
 
       zzzzz-nyw5e-readonlyonother:
         AccessViaHosts:
-          "http://other.host.example:12345": {ReadOnly: true}
+          "http://keep0.zzzzz.example.com:25107": {ReadOnly: true}
         Driver: S3
         DriverParameters:
           Endpoint: https://storage.googleapis.com
@@ -585,7 +645,7 @@ Clusters:
 
       zzzzz-nyw5e-writableonother:
         AccessViaHosts:
-          "http://other.host.example:12345": {}
+          "http://keep0.zzzzz.example.com:25107": {}
         Driver: S3
         DriverParameters:
           Endpoint: https://storage.googleapis.com
@@ -594,6 +654,8 @@ Clusters:
         Replication: 3
 
       zzzzz-nyw5e-localfilesystem:
+        AccessViaHosts:
+          "http://keep0.zzzzz.example.com:25107": {}
         Driver: Directory
         DriverParameters:
           Root: /data/sdd
@@ -606,16 +668,23 @@ Clusters:
         DriverParameters:
           Root: /data/sde
         Replication: 1
+
+      zzzzz-nyw5e-possconfigerror:
+        AccessViaHosts:
+          "http://keep00.zzzzz.example.com:25107": {}
+        Driver: Directory
+        DriverParameters:
+          Root: /data/sdf
+        Replication: 1
 `
 
 // Determine the effect of combining the given legacy keepstore config
 // YAML (just the "Volumes" entries of an old keepstore config file)
 // with the example clusterConfigForKeepstoreMigrationTest config.
 //
-// Return two Volumes configs -- one without loading
-// keepstoreconfigdata ("before") and one with ("after") -- for the
-// caller to compare.
-func (s *KeepstoreMigrationSuite) loadWithKeepstoreConfig(c *check.C, keepstoreVolumesYAML string) (before, after map[string]arvados.Volume) {
+// Return two Volumes configs -- one without loading keepstoreYAML
+// ("before") and one with ("after") -- for the caller to compare.
+func (s *KeepstoreMigrationSuite) loadWithKeepstoreConfig(c *check.C, keepstoreYAML string) (before, after map[string]arvados.Volume) {
        ldr := testLoader(c, s.clusterConfigYAML(c), nil)
        cBefore, err := ldr.Load()
        c.Assert(err, check.IsNil)
@@ -623,7 +692,7 @@ func (s *KeepstoreMigrationSuite) loadWithKeepstoreConfig(c *check.C, keepstoreV
        keepstoreconfig, err := ioutil.TempFile("", "")
        c.Assert(err, check.IsNil)
        defer os.Remove(keepstoreconfig.Name())
-       io.WriteString(keepstoreconfig, keepstoreVolumesYAML)
+       io.WriteString(keepstoreconfig, keepstoreYAML)
 
        ldr = testLoader(c, s.clusterConfigYAML(c), nil)
        ldr.KeepstorePath = keepstoreconfig.Name()
@@ -633,6 +702,24 @@ func (s *KeepstoreMigrationSuite) loadWithKeepstoreConfig(c *check.C, keepstoreV
        return cBefore.Clusters["zzzzz"].Volumes, cAfter.Clusters["zzzzz"].Volumes
 }
 
+// Return the log messages emitted when loading keepstoreYAML along
+// with clusterConfigForKeepstoreMigrationTest.
+func (s *KeepstoreMigrationSuite) logsWithKeepstoreConfig(c *check.C, keepstoreYAML string) string {
+       var logs bytes.Buffer
+
+       keepstoreconfig, err := ioutil.TempFile("", "")
+       c.Assert(err, check.IsNil)
+       defer os.Remove(keepstoreconfig.Name())
+       io.WriteString(keepstoreconfig, keepstoreYAML)
+
+       ldr := testLoader(c, s.clusterConfigYAML(c), &logs)
+       ldr.KeepstorePath = keepstoreconfig.Name()
+       _, err = ldr.Load()
+       c.Assert(err, check.IsNil)
+
+       return logs.String()
+}
+
 func (s *KeepstoreMigrationSuite) clusterConfigYAML(c *check.C) string {
        hostname, err := os.Hostname()
        c.Assert(err, check.IsNil)