13647: Use cluster config instead of custom keepstore config.
[arvados.git] / lib / config / deprecated_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package config
6
7 import (
8         "flag"
9         "fmt"
10         "io/ioutil"
11         "os"
12         "time"
13
14         "git.curoverse.com/arvados.git/sdk/go/arvados"
15         check "gopkg.in/check.v1"
16 )
17
18 func testLoadLegacyConfig(content []byte, mungeFlag string, c *check.C) (*arvados.Cluster, error) {
19         tmpfile, err := ioutil.TempFile("", "example")
20         if err != nil {
21                 return nil, err
22         }
23         defer os.Remove(tmpfile.Name())
24
25         if _, err := tmpfile.Write(content); err != nil {
26                 return nil, err
27         }
28         if err := tmpfile.Close(); err != nil {
29                 return nil, err
30         }
31         flags := flag.NewFlagSet("test", flag.ExitOnError)
32         ldr := testLoader(c, "Clusters: {zzzzz: {}}", nil)
33         ldr.SetupFlags(flags)
34         args := ldr.MungeLegacyConfigArgs(ldr.Logger, []string{"-config", tmpfile.Name()}, mungeFlag)
35         flags.Parse(args)
36         cfg, err := ldr.Load()
37         if err != nil {
38                 return nil, err
39         }
40         cluster, err := cfg.GetCluster("")
41         if err != nil {
42                 return nil, err
43         }
44         return cluster, nil
45 }
46
47 func (s *LoadSuite) TestDeprecatedNodeProfilesToServices(c *check.C) {
48         hostname, err := os.Hostname()
49         c.Assert(err, check.IsNil)
50         checkEquivalent(c, `
51 Clusters:
52  z1111:
53   NodeProfiles:
54    "*":
55     arvados-controller:
56      listen: ":9004"
57    `+hostname+`:
58     arvados-api-server:
59      listen: ":8000"
60    dispatch-host:
61     arvados-dispatch-cloud:
62      listen: ":9006"
63 `, `
64 Clusters:
65  z1111:
66   Services:
67    RailsAPI:
68     InternalURLs:
69      "http://localhost:8000": {}
70    Controller:
71     InternalURLs:
72      "http://localhost:9004": {}
73    DispatchCloud:
74     InternalURLs:
75      "http://dispatch-host:9006": {}
76   NodeProfiles:
77    "*":
78     arvados-controller:
79      listen: ":9004"
80    `+hostname+`:
81     arvados-api-server:
82      listen: ":8000"
83    dispatch-host:
84     arvados-dispatch-cloud:
85      listen: ":9006"
86 `)
87 }
88
89 func (s *LoadSuite) TestLegacyKeepWebConfig(c *check.C) {
90         content := []byte(`
91 {
92         "Client": {
93                 "Scheme": "",
94                 "APIHost": "example.com",
95                 "AuthToken": "abcdefg",
96         },
97         "Listen": ":80",
98         "AnonymousTokens": [
99                 "anonusertoken"
100         ],
101         "AttachmentOnlyHost": "download.example.com",
102         "TrustAllContent": true,
103         "Cache": {
104                 "TTL": "1m",
105                 "UUIDTTL": "1s",
106                 "MaxCollectionEntries": 42,
107                 "MaxCollectionBytes": 1234567890,
108                 "MaxPermissionEntries": 100,
109                 "MaxUUIDEntries": 100
110         },
111         "ManagementToken": "xyzzy"
112 }
113 `)
114         cluster, err := testLoadLegacyConfig(content, "-legacy-keepweb-config", c)
115         c.Check(err, check.IsNil)
116
117         c.Check(cluster.Services.Controller.ExternalURL, check.Equals, arvados.URL{Scheme: "https", Host: "example.com"})
118         c.Check(cluster.SystemRootToken, check.Equals, "abcdefg")
119
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)
126
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)
130
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")
134 }
135
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)
140
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")
150
151         content = []byte(fmtKeepproxyConfig("", false))
152         cluster, err = testLoadLegacyConfig(content, f, c)
153         c.Check(cluster.SystemLogs.LogLevel, check.Equals, "info")
154
155         content = []byte(fmtKeepproxyConfig(`"DisableGet": true,`, true))
156         _, err = testLoadLegacyConfig(content, f, c)
157         c.Check(err, check.NotNil)
158
159         content = []byte(fmtKeepproxyConfig(`"DisablePut": true,`, true))
160         _, err = testLoadLegacyConfig(content, f, c)
161         c.Check(err, check.NotNil)
162
163         content = []byte(fmtKeepproxyConfig(`"PIDFile": "test",`, true))
164         _, err = testLoadLegacyConfig(content, f, c)
165         c.Check(err, check.NotNil)
166
167         content = []byte(fmtKeepproxyConfig(`"DisableGet": false, "DisablePut": false, "PIDFile": "",`, true))
168         _, err = testLoadLegacyConfig(content, f, c)
169         c.Check(err, check.IsNil)
170 }
171
172 func fmtKeepproxyConfig(param string, debugLog bool) string {
173         return fmt.Sprintf(`
174 {
175         "Client": {
176                 "Scheme": "",
177                 "APIHost": "example.com",
178                 "AuthToken": "abcdefg",
179                 "Insecure": false
180         },
181         "Listen": ":80",
182         "DefaultReplicas": 0,
183         "Timeout": "15s",
184         "Debug": %t,
185         %s
186         "ManagementToken": "xyzzy"
187 }
188 `, debugLog, param)
189 }
190
191 func (s *LoadSuite) TestLegacyArvGitHttpdConfig(c *check.C) {
192         content := []byte(`
193 {
194         "Client": {
195                 "Scheme": "",
196                 "APIHost": "example.com",
197                 "AuthToken": "abcdefg",
198         },
199         "Listen": ":9000",
200         "GitCommand": "/test/git",
201         "GitoliteHome": "/test/gitolite",
202         "RepoRoot": "/test/reporoot",
203         "ManagementToken": "xyzzy"
204 }
205 `)
206         f := "-legacy-git-httpd-config"
207         cluster, err := testLoadLegacyConfig(content, f, c)
208
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{})
218 }