1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 check "gopkg.in/check.v1"
18 func testLoadLegacyConfig(content []byte, mungeFlag string, c *check.C) (*arvados.Cluster, error) {
19 tmpfile, err := ioutil.TempFile("", "example")
23 defer os.Remove(tmpfile.Name())
25 if _, err := tmpfile.Write(content); err != nil {
28 if err := tmpfile.Close(); err != nil {
31 flags := flag.NewFlagSet("test", flag.ExitOnError)
32 ldr := testLoader(c, "Clusters: {zzzzz: {}}", nil)
34 args := ldr.MungeLegacyConfigArgs(ldr.Logger, []string{"-config", tmpfile.Name()}, mungeFlag)
36 cfg, err := ldr.Load()
40 cluster, err := cfg.GetCluster("")
47 func (s *LoadSuite) TestDeprecatedNodeProfilesToServices(c *check.C) {
48 hostname, err := os.Hostname()
49 c.Assert(err, check.IsNil)
61 arvados-dispatch-cloud:
69 "http://localhost:8000": {}
72 "http://localhost:9004": {}
75 "http://dispatch-host:9006": {}
84 arvados-dispatch-cloud:
89 func (s *LoadSuite) TestLegacyKeepWebConfig(c *check.C) {
94 "APIHost": "example.com",
95 "AuthToken": "abcdefg",
101 "AttachmentOnlyHost": "download.example.com",
102 "TrustAllContent": true,
106 "MaxCollectionEntries": 42,
107 "MaxCollectionBytes": 1234567890,
108 "MaxPermissionEntries": 100,
109 "MaxUUIDEntries": 100
111 "ManagementToken": "xyzzy"
114 cluster, err := testLoadLegacyConfig(content, "-legacy-keepweb-config", c)
115 c.Check(err, check.IsNil)
117 c.Check(cluster.Services.Controller.ExternalURL, check.Equals, arvados.URL{Scheme: "https", Host: "example.com"})
118 c.Check(cluster.SystemRootToken, check.Equals, "abcdefg")
120 c.Check(cluster.Collections.WebDAVCache.TTL, check.Equals, arvados.Duration(60*time.Second))
121 c.Check(cluster.Collections.WebDAVCache.UUIDTTL, check.Equals, arvados.Duration(time.Second))
122 c.Check(cluster.Collections.WebDAVCache.MaxCollectionEntries, check.Equals, 42)
123 c.Check(cluster.Collections.WebDAVCache.MaxCollectionBytes, check.Equals, int64(1234567890))
124 c.Check(cluster.Collections.WebDAVCache.MaxPermissionEntries, check.Equals, 100)
125 c.Check(cluster.Collections.WebDAVCache.MaxUUIDEntries, check.Equals, 100)
127 c.Check(cluster.Services.WebDAVDownload.ExternalURL, check.Equals, arvados.URL{Host: "download.example.com"})
128 c.Check(cluster.Services.WebDAVDownload.InternalURLs[arvados.URL{Host: ":80"}], check.NotNil)
129 c.Check(cluster.Services.WebDAV.InternalURLs[arvados.URL{Host: ":80"}], check.NotNil)
131 c.Check(cluster.Collections.TrustAllContent, check.Equals, true)
132 c.Check(cluster.Users.AnonymousUserToken, check.Equals, "anonusertoken")
133 c.Check(cluster.ManagementToken, check.Equals, "xyzzy")
136 func (s *LoadSuite) TestLegacyKeepproxyConfig(c *check.C) {
137 f := "-legacy-keepproxy-config"
138 content := []byte(fmtKeepproxyConfig("", true))
139 cluster, err := testLoadLegacyConfig(content, f, c)
141 c.Check(err, check.IsNil)
142 c.Check(cluster, check.NotNil)
143 c.Check(cluster.Services.Controller.ExternalURL, check.Equals, arvados.URL{Scheme: "https", Host: "example.com"})
144 c.Check(cluster.SystemRootToken, check.Equals, "abcdefg")
145 c.Check(cluster.ManagementToken, check.Equals, "xyzzy")
146 c.Check(cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: ":80"}], check.Equals, arvados.ServiceInstance{})
147 c.Check(cluster.Collections.DefaultReplication, check.Equals, 0)
148 c.Check(cluster.API.KeepServiceRequestTimeout.String(), check.Equals, "15s")
149 c.Check(cluster.SystemLogs.LogLevel, check.Equals, "debug")
151 content = []byte(fmtKeepproxyConfig("", false))
152 cluster, err = testLoadLegacyConfig(content, f, c)
153 c.Check(cluster.SystemLogs.LogLevel, check.Equals, "info")
155 content = []byte(fmtKeepproxyConfig(`"DisableGet": true,`, true))
156 _, err = testLoadLegacyConfig(content, f, c)
157 c.Check(err, check.NotNil)
159 content = []byte(fmtKeepproxyConfig(`"DisablePut": true,`, true))
160 _, err = testLoadLegacyConfig(content, f, c)
161 c.Check(err, check.NotNil)
163 content = []byte(fmtKeepproxyConfig(`"PIDFile": "test",`, true))
164 _, err = testLoadLegacyConfig(content, f, c)
165 c.Check(err, check.NotNil)
167 content = []byte(fmtKeepproxyConfig(`"DisableGet": false, "DisablePut": false, "PIDFile": "",`, true))
168 _, err = testLoadLegacyConfig(content, f, c)
169 c.Check(err, check.IsNil)
172 func fmtKeepproxyConfig(param string, debugLog bool) string {
177 "APIHost": "example.com",
178 "AuthToken": "abcdefg",
182 "DefaultReplicas": 0,
186 "ManagementToken": "xyzzy"
191 func (s *LoadSuite) TestLegacyArvGitHttpdConfig(c *check.C) {
196 "APIHost": "example.com",
197 "AuthToken": "abcdefg",
200 "GitCommand": "/test/git",
201 "GitoliteHome": "/test/gitolite",
202 "RepoRoot": "/test/reporoot",
203 "ManagementToken": "xyzzy"
206 f := "-legacy-git-httpd-config"
207 cluster, err := testLoadLegacyConfig(content, f, c)
209 c.Check(err, check.IsNil)
210 c.Check(cluster, check.NotNil)
211 c.Check(cluster.Services.Controller.ExternalURL, check.Equals, arvados.URL{Scheme: "https", Host: "example.com"})
212 c.Check(cluster.SystemRootToken, check.Equals, "abcdefg")
213 c.Check(cluster.ManagementToken, check.Equals, "xyzzy")
214 c.Check(cluster.Git.GitCommand, check.Equals, "/test/git")
215 c.Check(cluster.Git.GitoliteHome, check.Equals, "/test/gitolite")
216 c.Check(cluster.Git.Repositories, check.Equals, "/test/reporoot")
217 c.Check(cluster.Services.Keepproxy.InternalURLs[arvados.URL{Host: ":9000"}], check.Equals, arvados.ServiceInstance{})
220 func (s *LoadSuite) TestLegacyKeepBalanceConfig(c *check.C) {
221 f := "-legacy-keepbalance-config"
222 content := []byte(fmtKeepBalanceConfig(""))
223 cluster, err := testLoadLegacyConfig(content, f, c)
225 c.Check(err, check.IsNil)
226 c.Check(cluster, check.NotNil)
227 c.Check(cluster.ManagementToken, check.Equals, "xyzzy")
228 c.Check(cluster.Services.Keepbalance.InternalURLs[arvados.URL{Host: ":80"}], check.Equals, arvados.ServiceInstance{})
229 c.Check(cluster.Collections.BalanceCollectionBuffers, check.Equals, 1000)
230 c.Check(cluster.Collections.BalanceCollectionBatch, check.Equals, 100000)
231 c.Check(cluster.Collections.BalancePeriod.String(), check.Equals, "10m")
232 c.Check(cluster.Collections.BlobMissingReport, check.Equals, "testfile")
233 c.Check(cluster.API.KeepServiceRequestTimeout.String(), check.Equals, "30m")
235 content = []byte(fmtKeepBalanceConfig(`"KeepServiceTypes":["disk"],`))
236 _, err = testLoadLegacyConfig(content, f, c)
237 c.Check(err, check.IsNil)
239 content = []byte(fmtKeepBalanceConfig(`"KeepServiceTypes":[],`))
240 _, err = testLoadLegacyConfig(content, f, c)
241 c.Check(err, check.IsNil)
243 content = []byte(fmtKeepBalanceConfig(`"KeepServiceTypes":["proxy"],`))
244 _, err = testLoadLegacyConfig(content, f, c)
245 c.Check(err, check.NotNil)
247 content = []byte(fmtKeepBalanceConfig(`"KeepServiceTypes":["disk", "proxy"],`))
248 _, err = testLoadLegacyConfig(content, f, c)
249 c.Check(err, check.NotNil)
251 content = []byte(fmtKeepBalanceConfig(`"KeepServiceList":{},`))
252 _, err = testLoadLegacyConfig(content, f, c)
253 c.Check(err, check.NotNil)
256 func fmtKeepBalanceConfig(param string) string {
261 "APIHost": "example.com",
262 "AuthToken": "abcdefg",
268 "CollectionBatchSize": 100000,
269 "CollectionBuffers": 1000,
270 "RequestTimeout": "30m",
271 "ManagementToken": "xyzzy",
272 "LostBlocksFile": "testfile"