1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
15 check "gopkg.in/check.v1"
18 var _ = check.Suite(&MountsSuite{})
20 type MountsSuite struct {
25 func (s *MountsSuite) SetUpTest(c *check.C) {
26 s.vm = MakeTestVolumeManager(2)
28 theConfig = DefaultConfig()
29 theConfig.systemAuthToken = arvadostest.DataManagerToken
31 s.rtr = MakeRESTRouter(testCluster)
34 func (s *MountsSuite) TearDownTest(c *check.C) {
37 theConfig = DefaultConfig()
41 func (s *MountsSuite) TestMounts(c *check.C) {
42 vols := s.vm.AllWritable()
43 vols[0].Put(context.Background(), TestHash, TestBlock)
44 vols[1].Put(context.Background(), TestHash2, TestBlock2)
46 resp := s.call("GET", "/mounts", "", nil)
47 c.Check(resp.Code, check.Equals, http.StatusOK)
48 var mntList []struct {
49 UUID string `json:"uuid"`
50 DeviceID string `json:"device_id"`
51 ReadOnly bool `json:"read_only"`
52 Replication int `json:"replication"`
53 StorageClasses []string `json:"storage_classes"`
55 err := json.Unmarshal(resp.Body.Bytes(), &mntList)
56 c.Assert(err, check.IsNil)
57 c.Assert(len(mntList), check.Equals, 2)
58 for _, m := range mntList {
59 c.Check(len(m.UUID), check.Equals, 27)
60 c.Check(m.UUID[:12], check.Equals, "zzzzz-ivpuk-")
61 c.Check(m.DeviceID, check.Equals, "mock-device-id")
62 c.Check(m.ReadOnly, check.Equals, false)
63 c.Check(m.Replication, check.Equals, 1)
64 c.Check(m.StorageClasses, check.DeepEquals, []string{"default"})
66 c.Check(mntList[0].UUID, check.Not(check.Equals), mntList[1].UUID)
69 for _, tok := range []string{"", "xyzzy"} {
70 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks", tok, nil)
71 c.Check(resp.Code, check.Equals, http.StatusUnauthorized)
72 c.Check(resp.Body.String(), check.Equals, "Unauthorized\n")
75 tok := arvadostest.DataManagerToken
77 // Nonexistent mount UUID
78 resp = s.call("GET", "/mounts/X/blocks", tok, nil)
79 c.Check(resp.Code, check.Equals, http.StatusNotFound)
80 c.Check(resp.Body.String(), check.Equals, "mount not found\n")
82 // Complete index of first mount
83 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks", tok, nil)
84 c.Check(resp.Code, check.Equals, http.StatusOK)
85 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
87 // Partial index of first mount (one block matches prefix)
88 resp = s.call("GET", "/mounts/"+mntList[0].UUID+"/blocks?prefix="+TestHash[:2], tok, nil)
89 c.Check(resp.Code, check.Equals, http.StatusOK)
90 c.Check(resp.Body.String(), check.Matches, TestHash+`\+[0-9]+ [0-9]+\n\n`)
92 // Complete index of second mount (note trailing slash)
93 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/", tok, nil)
94 c.Check(resp.Code, check.Equals, http.StatusOK)
95 c.Check(resp.Body.String(), check.Matches, TestHash2+`\+[0-9]+ [0-9]+\n\n`)
97 // Partial index of second mount (no blocks match prefix)
98 resp = s.call("GET", "/mounts/"+mntList[1].UUID+"/blocks/?prefix="+TestHash[:2], tok, nil)
99 c.Check(resp.Code, check.Equals, http.StatusOK)
100 c.Check(resp.Body.String(), check.Equals, "\n")
103 func (s *MountsSuite) TestMetrics(c *check.C) {
104 s.call("PUT", "/"+TestHash, "", TestBlock)
105 s.call("PUT", "/"+TestHash2, "", TestBlock2)
106 resp := s.call("GET", "/metrics.json", "", nil)
107 c.Check(resp.Code, check.Equals, http.StatusOK)
118 SampleCount string `json:"sample_count"`
119 SampleSum float64 `json:"sample_sum"`
127 json.NewDecoder(resp.Body).Decode(&j)
128 found := make(map[string]bool)
129 for _, g := range j {
130 for _, m := range g.Metric {
131 if len(m.Label) == 2 && m.Label[0].Name == "code" && m.Label[0].Value == "200" && m.Label[1].Name == "method" && m.Label[1].Value == "put" {
132 c.Check(m.Summary.SampleCount, check.Equals, "2")
133 c.Check(len(m.Summary.Quantile), check.Not(check.Equals), 0)
134 c.Check(m.Summary.Quantile[0].Value, check.Not(check.Equals), float64(0))
139 c.Check(found["request_duration_seconds"], check.Equals, true)
140 c.Check(found["time_to_status_seconds"], check.Equals, true)
143 func (s *MountsSuite) call(method, path, tok string, body []byte) *httptest.ResponseRecorder {
144 resp := httptest.NewRecorder()
145 req, _ := http.NewRequest(method, path, bytes.NewReader(body))
147 req.Header.Set("Authorization", "OAuth2 "+tok)
149 s.rtr.ServeHTTP(resp, req)