10 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
11 "git.curoverse.com/arvados.git/sdk/go/keepclient"
16 // Gocheck boilerplate
17 func Test(t *testing.T) {
21 // Gocheck boilerplate
22 var _ = Suite(&ServerRequiredSuite{})
24 // Tests that require the Keep server running
25 type ServerRequiredSuite struct{}
27 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
30 func (s *ServerRequiredSuite) SetUpTest(c *C) {
31 arvadostest.ResetEnv()
32 srcKeepServicesJSON = ""
33 dstKeepServicesJSON = ""
36 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
37 arvadostest.StopKeep()
41 // Testing keep-rsync needs two sets of keep services: src and dst.
42 // The test setup hence tweaks keep-rsync initialzation to achieve this.
43 // First invoke initializeKeepRsync and then invoke StartKeepAdditional
44 // to create the keep servers to be used as destination.
45 func setupRsync(c *C) {
47 srcConfig.APIHost = os.Getenv("ARVADOS_API_HOST")
48 srcConfig.APIToken = os.Getenv("ARVADOS_API_TOKEN")
49 srcConfig.APIHostInsecure = matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE"))
52 dstConfig.APIHost = os.Getenv("ARVADOS_API_HOST")
53 dstConfig.APIToken = os.Getenv("ARVADOS_API_TOKEN")
54 dstConfig.APIHostInsecure = matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE"))
58 // Start API and Keep servers
59 arvadostest.StartAPI()
60 arvadostest.StartKeep()
62 // initialize keep-rsync
63 err := initializeKeepRsync()
64 c.Assert(err, Equals, nil)
66 // Create two more keep servers to be used as destination
67 arvadostest.StartKeepWithParams(true, false)
70 kcDst, err = keepclient.MakeKeepClient(&arvDst)
71 c.Assert(err, Equals, nil)
72 kcDst.Want_replicas = 1
75 // Test readConfigFromFile method
76 func (s *ServerRequiredSuite) TestReadConfigFromFile(c *C) {
77 // Setup a test config file
78 file, err := ioutil.TempFile(os.TempDir(), "config")
79 c.Assert(err, Equals, nil)
80 defer os.Remove(file.Name())
82 fileContent := "ARVADOS_API_HOST=testhost\n"
83 fileContent += "ARVADOS_API_TOKEN=testtoken\n"
84 fileContent += "ARVADOS_API_HOST_INSECURE=true"
86 _, err = file.Write([]byte(fileContent))
88 // Invoke readConfigFromFile method with this test filename
89 config, err := readConfigFromFile(file.Name())
90 c.Assert(err, Equals, nil)
91 c.Assert(config.APIHost, Equals, "testhost")
92 c.Assert(config.APIToken, Equals, "testtoken")
93 c.Assert(config.APIHostInsecure, Equals, true)
94 c.Assert(config.ExternalClient, Equals, false)
97 // Test keep-rsync initialization, with src and dst keep servers.
98 // Do a Put and Get in src, both of which should succeed.
99 // Do a Put and Get in dst, both of which should succeed.
100 // Do a Get in dst for the src hash, which should raise block not found error.
101 // Do a Get in src for the dst hash, which should raise block not found error.
102 func (s *ServerRequiredSuite) TestRsyncPutInOne_GetFromOtherShouldFail(c *C) {
105 // Put a block in src using kcSrc and Get it
106 srcData := []byte("test-data1")
107 locatorInSrc := fmt.Sprintf("%x", md5.Sum(srcData))
109 hash, rep, err := kcSrc.PutB(srcData)
110 c.Check(hash, Matches, fmt.Sprintf(`^%s\+10(\+.+)?$`, locatorInSrc))
111 c.Check(rep, Equals, 2)
112 c.Check(err, Equals, nil)
114 reader, blocklen, _, err := kcSrc.Get(locatorInSrc)
115 c.Assert(err, Equals, nil)
116 c.Check(blocklen, Equals, int64(10))
117 all, err := ioutil.ReadAll(reader)
118 c.Check(all, DeepEquals, srcData)
120 // Put a different block in src using kcSrc and Get it
121 dstData := []byte("test-data2")
122 locatorInDst := fmt.Sprintf("%x", md5.Sum(dstData))
124 hash, rep, err = kcDst.PutB(dstData)
125 c.Check(hash, Matches, fmt.Sprintf(`^%s\+10(\+.+)?$`, locatorInDst))
126 c.Check(rep, Equals, 1)
127 c.Check(err, Equals, nil)
129 reader, blocklen, _, err = kcDst.Get(locatorInDst)
130 c.Assert(err, Equals, nil)
131 c.Check(blocklen, Equals, int64(10))
132 all, err = ioutil.ReadAll(reader)
133 c.Check(all, DeepEquals, dstData)
135 // Get srcLocator using kcDst should fail with NotFound error
136 _, _, _, err = kcDst.Get(locatorInSrc)
137 c.Assert(err.Error(), Equals, "Block not found")
139 // Get dstLocator using kcSrc should fail with NotFound error
140 _, _, _, err = kcSrc.Get(locatorInDst)
141 c.Assert(err.Error(), Equals, "Block not found")
144 // Test keep-rsync initialization, with srcKeepServicesJSON
145 func (s *ServerRequiredSuite) TestRsyncInitializeWithKeepServicesJSON(c *C) {
146 srcKeepServicesJSON = "{ \"kind\":\"arvados#keepServiceList\", \"etag\":\"\", \"self_link\":\"\", \"offset\":null, \"limit\":null, \"items\":[ { \"href\":\"/keep_services/zzzzz-bi6l4-123456789012340\", \"kind\":\"arvados#keepService\", \"etag\":\"641234567890enhj7hzx432e5\", \"uuid\":\"zzzzz-bi6l4-123456789012340\", \"owner_uuid\":\"zzzzz-tpzed-123456789012345\", \"service_host\":\"keep0.zzzzz.arvadosapi.com\", \"service_port\":25107, \"service_ssl_flag\":false, \"service_type\":\"disk\", \"read_only\":false }, { \"href\":\"/keep_services/zzzzz-bi6l4-123456789012341\", \"kind\":\"arvados#keepService\", \"etag\":\"641234567890enhj7hzx432e5\", \"uuid\":\"zzzzz-bi6l4-123456789012341\", \"owner_uuid\":\"zzzzz-tpzed-123456789012345\", \"service_host\":\"keep0.zzzzz.arvadosapi.com\", \"service_port\":25108, \"service_ssl_flag\":false, \"service_type\":\"disk\", \"read_only\":false } ], \"items_available\":2 }"
150 localRoots := kcSrc.LocalRoots()
151 c.Check(localRoots != nil, Equals, true)
154 for k := range localRoots {
155 if k == "zzzzz-bi6l4-123456789012340" {
159 c.Check(foundIt, Equals, true)
162 for k := range localRoots {
163 if k == "zzzzz-bi6l4-123456789012341" {
167 c.Check(foundIt, Equals, true)