1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
14 "git.arvados.org/arvados.git/lib/config"
15 "git.arvados.org/arvados.git/sdk/go/arvados"
16 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
17 "git.arvados.org/arvados.git/sdk/go/arvadostest"
18 "git.arvados.org/arvados.git/sdk/go/ctxlog"
22 func (s *ServerRequiredSuite) TestOverrideDiscovery(c *check.C) {
23 defer os.Setenv("ARVADOS_KEEP_SERVICES", "")
25 data := []byte("TestOverrideDiscovery")
26 hash := fmt.Sprintf("%x+%d", md5.Sum(data), len(data))
30 arvadostest.ActiveToken,
33 ks := RunSomeFakeKeepServers(st, 2)
35 os.Setenv("ARVADOS_KEEP_SERVICES", "")
36 arv1, err := arvadosclient.MakeArvadosClient()
37 c.Assert(err, check.IsNil)
38 arv1.ApiToken = arvadostest.ActiveToken
40 os.Setenv("ARVADOS_KEEP_SERVICES", ks[0].url+" "+ks[1].url+" ")
41 arv2, err := arvadosclient.MakeArvadosClient()
42 c.Assert(err, check.IsNil)
43 arv2.ApiToken = arvadostest.ActiveToken
45 // ARVADOS_KEEP_SERVICES was empty when we created arv1, but
46 // it pointed to our stub servers when we created
47 // arv2. Regardless of what it's set to now, a keepclient for
48 // arv2 should use our stub servers, but one created for arv1
51 kc1, err := MakeKeepClient(arv1)
52 c.Assert(err, check.IsNil)
53 kc2, err := MakeKeepClient(arv2)
54 c.Assert(err, check.IsNil)
56 _, _, _, err = kc1.Get(hash)
57 c.Check(err, check.NotNil)
58 _, _, _, err = kc2.Get(hash)
59 c.Check(err, check.IsNil)
62 func (s *StandaloneSuite) TestKeepServicesFromClusterConfig(c *check.C) {
63 // This behavior is disabled via env var in the test
64 // environment. Clear the env var to test the default
65 // production behavior.
66 v := "ARVADOS_USE_KEEP_ACCESSIBLE_API"
67 defer os.Setenv(v, os.Getenv(v))
70 rdr := bytes.NewReader([]byte(`
76 "https://[::1]:12345/":
77 Rendezvous: abcdefghijklmno
78 "https://[::1]:54321/":
80 "http://0.0.0.0:54321/":
84 "https://[::1]:55555/":
87 ldr := config.NewLoader(rdr, ctxlog.TestLogger(c))
89 cfg, err := ldr.Load()
90 c.Assert(err, check.IsNil)
91 cluster, err := cfg.GetCluster("")
92 c.Assert(err, check.IsNil)
93 c.Assert(cluster.ClusterID, check.Equals, "zzzzz")
94 ac, err := arvados.NewClientFromConfig(cluster)
95 c.Assert(err, check.IsNil)
96 arv1, err := arvadosclient.New(ac)
97 c.Assert(err, check.IsNil)
98 c.Check(arv1.Cluster, check.NotNil)
99 kc, err := MakeKeepClient(arv1)
100 c.Assert(err, check.IsNil)
101 // Note the default rendezvous string is generated based on
102 // the MD5 of the keepstore URL and that URL *must* have a
103 // trailing slash in order to match the RailsAPI behavior --
104 // meanwhile, the keepstore URL given in the localRoots map
105 // *must not* have a trailing slash.
106 c.Check(kc.localRoots, check.DeepEquals, map[string]string{
107 "zzzzz-bi6l4-abcdefghijklmno": "https://[::1]:12345",
108 fmt.Sprintf("zzzzz-bi6l4-%x", md5.Sum([]byte("xyz")))[:27]: "https://[::1]:54321",
109 fmt.Sprintf("zzzzz-bi6l4-%x", md5.Sum([]byte("http://0.0.0.0:54321/")))[:27]: "http://0.0.0.0:54321",