15467: Added tests for KeepServices
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Fri, 2 Aug 2019 14:46:11 +0000 (10:46 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Fri, 2 Aug 2019 19:01:26 +0000 (15:01 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

lib/config/deprecated.go
lib/config/generated_config.go
services/crunch-dispatch-slurm/crunch-dispatch-slurm.go
services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go

index ce9b2e4d01d3654c73faf8855acc99c53832cc74..7ae69708eb53d06334b2e732c944f31fb41a3e2d 100644 (file)
@@ -203,10 +203,12 @@ func loadOldClientConfig(cluster *arvados.Cluster, client *arvados.Client) {
                        cluster.Containers.SLURM.KeepServices = make(map[string]arvados.Service)
                }
                if cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"].InternalURLs == nil {
-                       cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"].InternalURLs = map[arvados.URL]arvados.ServiceInstance{}
+                       cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"] = arvados.Service{InternalURLs: make(map[arvados.URL]arvados.ServiceInstance)}
                }
                p, err := url.Parse(r)
-               cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"].InternalURLs[arvados.URL(p)] = struct{}{}
+               if err == nil {
+                       cluster.Containers.SLURM.KeepServices["00000-bi6l4-000000000000000"].InternalURLs[arvados.URL(*p)] = struct{}{}
+               }
        }
 }
 
index 35edb05bcd683a1b07596d39e39ae441c1b7aa86..4e7790603a94c8397835efa1569ca4fd5f23c2a7 100644 (file)
@@ -531,6 +531,9 @@ Clusters:
       SLURM:
         PrioritySpread: 0
         SbatchArgumentsList: []
+        KeepServices:
+          SAMPLE:
+            InternalURLs: {}
         Managed:
           # Path to dns server configuration directory
           # (e.g. /etc/unbound.d/conf.d). If false, do not write any config
index 300e923640bdd0d4cb2e6bb8ecf7a5c83cfa0024..982141ad81a51269f6d7f110d728d2327227dc71 100644 (file)
@@ -13,6 +13,7 @@ import (
        "fmt"
        "log"
        "math"
+       "net/url"
        "os"
        "regexp"
        "strings"
@@ -133,15 +134,16 @@ func (disp *Dispatcher) configure(prog string, args []string) error {
                        os.Setenv("ARVADOS_API_HOST_INSECURE", "1")
                }
                ks := ""
-               if length(disp.cluster.Containers.SLURM.KeepServices) > 0 {
+               if len(disp.cluster.Containers.SLURM.KeepServices) > 0 {
                        for _, svc := range disp.cluster.Containers.SLURM.KeepServices {
                                for k, _ := range svc.InternalURLs {
-                                       ks += k
+                                       u := url.URL(k)
+                                       ks += u.String()
                                        ks += " "
                                }
                        }
                }
-               os.Setenv("ARVADOS_KEEP_SERVICES", ks)
+               os.Setenv("ARVADOS_KEEP_SERVICES", strings.TrimSuffix(ks, " "))
                os.Setenv("ARVADOS_EXTERNAL_CLIENT", "")
        } else {
                disp.logger.Warnf("Client credentials missing from config, so falling back on environment variables (deprecated).")
index 4a0213d4777ff78dbd70e58c2f5f28d6daf20fd7..63117128eb594e5c492fbe2e93e84c5f77672b1f 100644 (file)
@@ -11,7 +11,6 @@ import (
        "fmt"
        "io"
        "io/ioutil"
-       "log"
        "net/http"
        "net/http/httptest"
        "os"
@@ -396,8 +395,9 @@ func (s *StubbedSuite) TestLoadLegacyConfig(c *C) {
 Client:
   APIHost: example.com
   AuthToken: abcdefg
-  KeepServices:
-    - https://example.com/keep
+  KeepServiceURIs:
+    - https://example.com/keep1
+    - https://example.com/keep2
 SbatchArguments: ["--foo", "bar"]
 PollPeriod: 12s
 PrioritySpread: 42
@@ -408,16 +408,16 @@ BatchSize: 99
 `)
        tmpfile, err := ioutil.TempFile("", "example")
        if err != nil {
-               log.Fatal(err)
+               c.Error(err)
        }
 
        defer os.Remove(tmpfile.Name()) // clean up
 
        if _, err := tmpfile.Write(content); err != nil {
-               log.Fatal(err)
+               c.Error(err)
        }
        if err := tmpfile.Close(); err != nil {
-               log.Fatal(err)
+               c.Error(err)
 
        }
        err = s.disp.configure("crunch-dispatch-slurm", []string{"-config", tmpfile.Name()})
@@ -433,11 +433,16 @@ BatchSize: 99
        c.Check(s.disp.cluster.Containers.ReserveExtraRAM, Equals, arvados.ByteSize(12345))
        c.Check(s.disp.cluster.Containers.MinRetryPeriod, Equals, arvados.Duration(13*time.Second))
        c.Check(s.disp.cluster.API.MaxItemsPerResponse, Equals, 99)
-       c.Check(s.disp.cluster.Containers.SLURM.KeepServices, DeepEquals, map[string]Service{
-               "00000-bi6l4-000000000000000": Service{
-                       InternalURLs: map[string]struct{}{
-                               "https://example.com/keep": struct{}{},
+       c.Check(s.disp.cluster.Containers.SLURM.KeepServices, DeepEquals, map[string]arvados.Service{
+               "00000-bi6l4-000000000000000": arvados.Service{
+                       InternalURLs: map[arvados.URL]arvados.ServiceInstance{
+                               arvados.URL{Scheme: "https", Path: "/keep1", Host: "example.com"}: struct{}{},
+                               arvados.URL{Scheme: "https", Path: "/keep2", Host: "example.com"}: struct{}{},
                        },
                },
        })
+       ks := os.Getenv("ARVADOS_KEEP_SERVICES")
+       if ks != "https://example.com/keep1 https://example.com/keep2" && ks != "https://example.com/keep2 https://example.com/keep1" {
+               c.Assert(ks, Equals, "https://example.com/keep1 https://example.com/keep2")
+       }
 }