1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 func (s *routerSuite) TestMounts(c *C) {
16 router, cancel := testRouter(c, s.cluster, nil)
19 router.keepstore.mountsW[0].BlockWrite(context.Background(), fooHash, []byte("foo"))
20 router.keepstore.mountsW[1].BlockWrite(context.Background(), barHash, []byte("bar"))
22 resp := call(router, "GET", "/mounts", s.cluster.SystemRootToken, nil, nil)
23 c.Check(resp.Code, Equals, http.StatusOK)
24 c.Log(resp.Body.String())
26 var mntList []struct {
27 UUID string `json:"uuid"`
28 DeviceID string `json:"device_id"`
29 ReadOnly bool `json:"read_only"`
30 Replication int `json:"replication"`
31 StorageClasses map[string]bool `json:"storage_classes"`
33 err := json.Unmarshal(resp.Body.Bytes(), &mntList)
35 c.Assert(mntList, HasLen, 2)
37 for _, m := range mntList {
38 c.Check(len(m.UUID), Equals, 27)
39 c.Check(m.UUID[:12], Equals, "zzzzz-nyw5e-")
40 c.Check(m.DeviceID, Matches, "0x[0-9a-f]+")
41 c.Check(m.ReadOnly, Equals, false)
42 c.Check(m.Replication, Equals, 1)
43 c.Check(m.StorageClasses, HasLen, 1)
44 for k := range m.StorageClasses {
45 c.Check(k, Matches, "testclass.*")
48 c.Check(mntList[0].UUID, Not(Equals), mntList[1].UUID)
50 c.Logf("=== bad auth")
51 for _, tok := range []string{"", "xyzzy"} {
52 resp = call(router, "GET", "/mounts/"+mntList[1].UUID+"/blocks", tok, nil, nil)
54 c.Check(resp.Code, Equals, http.StatusUnauthorized)
55 c.Check(resp.Body.String(), Equals, "Unauthorized\n")
57 c.Check(resp.Code, Equals, http.StatusForbidden)
58 c.Check(resp.Body.String(), Equals, "Forbidden\n")
62 c.Logf("=== nonexistent mount UUID")
63 resp = call(router, "GET", "/mounts/X/blocks", s.cluster.SystemRootToken, nil, nil)
64 c.Check(resp.Code, Equals, http.StatusNotFound)
66 c.Logf("=== complete index of first mount")
67 resp = call(router, "GET", "/mounts/"+mntList[0].UUID+"/blocks", s.cluster.SystemRootToken, nil, nil)
68 c.Check(resp.Code, Equals, http.StatusOK)
69 c.Check(resp.Body.String(), Matches, fooHash+`\+[0-9]+ [0-9]+\n\n`)
71 c.Logf("=== partial index of first mount (one block matches prefix)")
72 resp = call(router, "GET", "/mounts/"+mntList[0].UUID+"/blocks?prefix="+fooHash[:2], s.cluster.SystemRootToken, nil, nil)
73 c.Check(resp.Code, Equals, http.StatusOK)
74 c.Check(resp.Body.String(), Matches, fooHash+`\+[0-9]+ [0-9]+\n\n`)
76 c.Logf("=== complete index of second mount (note trailing slash)")
77 resp = call(router, "GET", "/mounts/"+mntList[1].UUID+"/blocks/", s.cluster.SystemRootToken, nil, nil)
78 c.Check(resp.Code, Equals, http.StatusOK)
79 c.Check(resp.Body.String(), Matches, barHash+`\+[0-9]+ [0-9]+\n\n`)
81 c.Logf("=== partial index of second mount (no blocks match prefix)")
82 resp = call(router, "GET", "/mounts/"+mntList[1].UUID+"/blocks/?prefix="+fooHash[:2], s.cluster.SystemRootToken, nil, nil)
83 c.Check(resp.Code, Equals, http.StatusOK)
84 c.Check(resp.Body.String(), Equals, "\n")