var testKeepServicesJSON = "{ \"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 }"
// Testing keep-rsync needs two sets of keep services: src and dst.
// The test setup hence tweaks keep-rsync initialization to achieve this.
var testKeepServicesJSON = "{ \"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 }"
// Testing keep-rsync needs two sets of keep services: src and dst.
// The test setup hence tweaks keep-rsync initialization to achieve this.
-func setupRsync(c *C, enforcePermissions bool, setupDstServers bool) {
+func setupRsync(c *C, enforcePermissions, setupDstServers bool, replications int) {
srcConfig.APIHost = os.Getenv("ARVADOS_API_HOST")
srcConfig.APIToken = os.Getenv("ARVADOS_API_TOKEN")
srcConfig.APIHostInsecure = matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE"))
// dstConfig
srcConfig.APIHost = os.Getenv("ARVADOS_API_HOST")
srcConfig.APIToken = os.Getenv("ARVADOS_API_TOKEN")
srcConfig.APIHostInsecure = matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE"))
// dstConfig
dstConfig.APIHost = os.Getenv("ARVADOS_API_HOST")
dstConfig.APIToken = os.Getenv("ARVADOS_API_TOKEN")
dstConfig.APIHostInsecure = matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE"))
dstConfig.APIHost = os.Getenv("ARVADOS_API_HOST")
dstConfig.APIToken = os.Getenv("ARVADOS_API_TOKEN")
dstConfig.APIHostInsecure = matchTrue.MatchString(os.Getenv("ARVADOS_API_HOST_INSECURE"))
- // initialize keep-rsync
- err := initializeKeepRsync()
+ // setup keepclients
+ var err error
+ kcSrc, kcDst, err = setupKeepClients(srcConfig, dstConfig, srcKeepServicesJSON, dstKeepServicesJSON, replications)
// Do a Get in dst for the src hash, which should raise block not found error.
// Do a Get in src for the dst hash, which should raise block not found error.
func (s *ServerRequiredSuite) TestRsyncPutInOne_GetFromOtherShouldFail(c *C) {
// Do a Get in dst for the src hash, which should raise block not found error.
// Do a Get in src for the dst hash, which should raise block not found error.
func (s *ServerRequiredSuite) TestRsyncPutInOne_GetFromOtherShouldFail(c *C) {
func (s *ServerRequiredSuite) TestRsyncInitializeWithKeepServicesJSON(c *C) {
srcKeepServicesJSON = testKeepServicesJSON
func (s *ServerRequiredSuite) TestRsyncInitializeWithKeepServicesJSON(c *C) {
srcKeepServicesJSON = testKeepServicesJSON
// Do a Get in dst for the src hash, which should raise block not found error.
// Do a Get in src for the dst hash, which should raise block not found error.
func (s *ServerRequiredSuite) TestRsyncWithBlobSigning_PutInOne_GetFromOtherShouldFail(c *C) {
// Do a Get in dst for the src hash, which should raise block not found error.
// Do a Get in src for the dst hash, which should raise block not found error.
func (s *ServerRequiredSuite) TestRsyncWithBlobSigning_PutInOne_GetFromOtherShouldFail(c *C) {
c.Check(err, Equals, nil)
tomorrow := time.Now().AddDate(0, 0, 1)
c.Check(err, Equals, nil)
tomorrow := time.Now().AddDate(0, 0, 1)
- signedLocator := keepclient.SignLocator(locatorInSrc, arvSrc.ApiToken, tomorrow, []byte(blobSigningKey))
+ signedLocator := keepclient.SignLocator(locatorInSrc, kcSrc.Arvados.ApiToken, tomorrow, []byte(blobSigningKey))
reader, blocklen, _, err := kcSrc.Get(signedLocator)
c.Check(err, IsNil)
reader, blocklen, _, err := kcSrc.Get(signedLocator)
c.Check(err, IsNil)
- signedLocator = keepclient.SignLocator(locatorInDst, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
+ signedLocator = keepclient.SignLocator(locatorInDst, kcDst.Arvados.ApiToken, tomorrow, []byte(blobSigningKey))
reader, blocklen, _, err = kcDst.Get(signedLocator)
c.Check(err, IsNil)
reader, blocklen, _, err = kcDst.Get(signedLocator)
c.Check(err, IsNil)
c.Check(all, DeepEquals, dstData)
// Get srcLocator using kcDst should fail with Not Found error
c.Check(all, DeepEquals, dstData)
// Get srcLocator using kcDst should fail with Not Found error
- signedLocator = keepclient.SignLocator(locatorInSrc, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
+ signedLocator = keepclient.SignLocator(locatorInSrc, kcDst.Arvados.ApiToken, tomorrow, []byte(blobSigningKey))
_, _, _, err = kcDst.Get(locatorInSrc)
c.Assert(err.Error(), Equals, "Block not found")
// Get dstLocator using kcSrc should fail with Not Found error
_, _, _, err = kcDst.Get(locatorInSrc)
c.Assert(err.Error(), Equals, "Block not found")
// Get dstLocator using kcSrc should fail with Not Found error
- signedLocator = keepclient.SignLocator(locatorInDst, arvSrc.ApiToken, tomorrow, []byte(blobSigningKey))
+ signedLocator = keepclient.SignLocator(locatorInDst, kcSrc.Arvados.ApiToken, tomorrow, []byte(blobSigningKey))
_, _, _, err = kcSrc.Get(locatorInDst)
c.Assert(err.Error(), Equals, "Block not found")
}
// Test keep-rsync initialization with default replications count
func (s *ServerRequiredSuite) TestInitializeRsyncDefaultReplicationsCount(c *C) {
_, _, _, err = kcSrc.Get(locatorInDst)
c.Assert(err.Error(), Equals, "Block not found")
}
// Test keep-rsync initialization with default replications count
func (s *ServerRequiredSuite) TestInitializeRsyncDefaultReplicationsCount(c *C) {
}
// Test keep-rsync initialization with replications count argument
func (s *ServerRequiredSuite) TestInitializeRsyncReplicationsCount(c *C) {
}
// Test keep-rsync initialization with replications count argument
func (s *ServerRequiredSuite) TestInitializeRsyncReplicationsCount(c *C) {
- // First set replications to 3 to mimic passing input argument
- replications = 3
-
- setupRsync(c, false, false)
+ setupRsync(c, false, false, 3)
// Hence there are 3 additional blocks in src
// Also, put 2 extra blocks in dst; they are hence only in dst
// Run rsync and verify that those 7 blocks are now available in dst
// Hence there are 3 additional blocks in src
// Also, put 2 extra blocks in dst; they are hence only in dst
// Run rsync and verify that those 7 blocks are now available in dst
-func testKeepRsync(c *C, enforcePermissions bool, indexPrefix string) {
- setupRsync(c, enforcePermissions, true)
-
- prefix = indexPrefix
+func testKeepRsync(c *C, enforcePermissions bool, prefix string) {
+ setupRsync(c, enforcePermissions, true, 1)
-var srcLocators []string
-var srcLocatorsMatchingPrefix []string
-var dstLocators []string
-var extraDstLocators []string
-
+var srcLocators, srcLocatorsMatchingPrefix, dstLocators, extraDstLocators []string
func setupTestData(c *C, enforcePermissions bool, indexPrefix string) {
srcLocators = []string{}
srcLocatorsMatchingPrefix = []string{}
dstLocators = []string{}
extraDstLocators = []string{}
func setupTestData(c *C, enforcePermissions bool, indexPrefix string) {
srcLocators = []string{}
srcLocatorsMatchingPrefix = []string{}
dstLocators = []string{}
extraDstLocators = []string{}
- data := []byte(fmt.Sprintf("test-data-%d", i))
- hash := fmt.Sprintf("%x", md5.Sum(data))
-
- hash2, rep, err := kcSrc.PutB(data)
- c.Check(hash2, Matches, fmt.Sprintf(`^%s\+11(\+.+)?$`, hash))
- c.Check(rep, Equals, 2)
+ hash, _, err := kcSrc.PutB([]byte(fmt.Sprintf("test-data-%d", i)))
- getLocator := hash
- if enforcePermissions {
- getLocator = keepclient.SignLocator(getLocator, arvSrc.ApiToken, tomorrow, []byte(blobSigningKey))
- }
-
- reader, blocklen, _, err := kcSrc.Get(getLocator)
- c.Check(err, IsNil)
- c.Check(blocklen, Equals, int64(11))
- all, err := ioutil.ReadAll(reader)
- c.Check(all, DeepEquals, data)
-
- srcLocators = append(srcLocators, fmt.Sprintf("%s+%d", hash, blocklen))
+ srcLocators = append(srcLocators, strings.Split(hash, "+A")[0])
- srcLocatorsMatchingPrefix = append(srcLocatorsMatchingPrefix, fmt.Sprintf("%s+%d", hash, blocklen))
+ srcLocatorsMatchingPrefix = append(srcLocatorsMatchingPrefix, strings.Split(hash, "+A")[0])
- data := []byte(fmt.Sprintf("test-data-%d", i))
- hash := fmt.Sprintf("%x", md5.Sum(data))
-
- hash2, rep, err := kcDst.PutB(data)
- c.Check(hash2, Matches, fmt.Sprintf(`^%s\+11(\+.+)?$`, hash))
- c.Check(rep, Equals, 1)
- c.Check(err, IsNil)
-
- getLocator := hash
- if enforcePermissions {
- getLocator = keepclient.SignLocator(getLocator, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
- }
-
- reader, blocklen, _, err := kcDst.Get(getLocator)
+ hash, _, err := kcDst.PutB([]byte(fmt.Sprintf("test-data-%d", i)))
- c.Check(blocklen, Equals, int64(11))
- all, err := ioutil.ReadAll(reader)
- c.Check(all, DeepEquals, data)
-
- dstLocators = append(dstLocators, fmt.Sprintf("%s+%d", hash, blocklen))
+ dstLocators = append(dstLocators, strings.Split(hash, "+A")[0])
- data := []byte(fmt.Sprintf("other-data-%d", i))
- hash := fmt.Sprintf("%x", md5.Sum(data))
-
- hash2, rep, err := kcDst.PutB(data)
- c.Check(hash2, Matches, fmt.Sprintf(`^%s\+12(\+.+)?$`, hash))
- c.Check(rep, Equals, 1)
- c.Check(err, IsNil)
-
- getLocator := hash
- if enforcePermissions {
- getLocator = keepclient.SignLocator(getLocator, arvDst.ApiToken, tomorrow, []byte(blobSigningKey))
- }
-
- reader, blocklen, _, err := kcDst.Get(getLocator)
+ hash, _, err := kcDst.PutB([]byte(fmt.Sprintf("other-data-%d", i)))
- c.Check(blocklen, Equals, int64(12))
- all, err := ioutil.ReadAll(reader)
- c.Check(all, DeepEquals, data)
-
- extraDstLocators = append(extraDstLocators, fmt.Sprintf("%s+%d", hash, blocklen))
+ dstLocators = append(dstLocators, strings.Split(hash, "+A")[0])
+ extraDstLocators = append(extraDstLocators, strings.Split(hash, "+A")[0])
func (s *ServerRequiredSuite) TestErrorDuringRsync_FakeSrcKeepservers(c *C) {
srcKeepServicesJSON = testKeepServicesJSON
func (s *ServerRequiredSuite) TestErrorDuringRsync_FakeSrcKeepservers(c *C) {
srcKeepServicesJSON = testKeepServicesJSON
c.Check(strings.HasSuffix(err.Error(), "no such host"), Equals, true)
}
c.Check(strings.HasSuffix(err.Error(), "no such host"), Equals, true)
}
func (s *ServerRequiredSuite) TestErrorDuringRsync_FakeDstKeepservers(c *C) {
dstKeepServicesJSON = testKeepServicesJSON
func (s *ServerRequiredSuite) TestErrorDuringRsync_FakeDstKeepservers(c *C) {
dstKeepServicesJSON = testKeepServicesJSON
c.Check(strings.HasSuffix(err.Error(), "no such host"), Equals, true)
}
// Test rsync with signature error during Get from src.
func (s *ServerRequiredSuite) TestErrorDuringRsync_ErrorGettingBlockFromSrc(c *C) {
c.Check(strings.HasSuffix(err.Error(), "no such host"), Equals, true)
}
// Test rsync with signature error during Get from src.
func (s *ServerRequiredSuite) TestErrorDuringRsync_ErrorGettingBlockFromSrc(c *C) {
// put some blocks in src and dst
setupTestData(c, true, "")
// put some blocks in src and dst
setupTestData(c, true, "")
// Change blob signing key to a fake key, so that Get from src fails
blobSigningKey = "123456789012345678901234yhksjoll2grmku38mi7yxd66h5j4q9w4jzanezacp8s6q0ro3hxakfye02152hncy6zml2ed0uc"
// Change blob signing key to a fake key, so that Get from src fails
blobSigningKey = "123456789012345678901234yhksjoll2grmku38mi7yxd66h5j4q9w4jzanezacp8s6q0ro3hxakfye02152hncy6zml2ed0uc"
- err := performKeepRsync()
- c.Check(err.Error(), Equals, "Block not found")
+ err := performKeepRsync(kcSrc, kcDst, "")
+ c.Check(strings.HasSuffix(err.Error(), "Block not found"), Equals, true)
}
// Test rsync with error during Put to src.
func (s *ServerRequiredSuite) TestErrorDuringRsync_ErrorPuttingBlockInDst(c *C) {
}
// Test rsync with error during Put to src.
func (s *ServerRequiredSuite) TestErrorDuringRsync_ErrorPuttingBlockInDst(c *C) {
// put some blocks in src and dst
setupTestData(c, true, "")
// put some blocks in src and dst
setupTestData(c, true, "")
- err := performKeepRsync()
- c.Check(err.Error(), Equals, "Could not write sufficient replicas")
+ err := performKeepRsync(kcSrc, kcDst, "")
+ c.Check(strings.HasSuffix(err.Error(), "Could not write sufficient replicas"), Equals, true)
// Setup a src config file
srcFile := setupConfigFile(c, "src-config")
defer os.Remove(srcFile.Name())
// Setup a src config file
srcFile := setupConfigFile(c, "src-config")
defer os.Remove(srcFile.Name())
// Setup a dst config file
dstFile := setupConfigFile(c, "dst-config")
defer os.Remove(dstFile.Name())
// Setup a dst config file
dstFile := setupConfigFile(c, "dst-config")
defer os.Remove(dstFile.Name())
// Test loadConfig func without setting up the config files
func (s *ServerRequiredSuite) TestLoadConfig_MissingSrcConfig(c *C) {
// Test loadConfig func without setting up the config files
func (s *ServerRequiredSuite) TestLoadConfig_MissingSrcConfig(c *C) {
c.Assert(err.Error(), Equals, "-src-config-file must be specified")
}
// Test loadConfig func - error reading src config
func (s *ServerRequiredSuite) TestLoadConfig_ErrorLoadingSrcConfig(c *C) {
c.Assert(err.Error(), Equals, "-src-config-file must be specified")
}
// Test loadConfig func - error reading src config
func (s *ServerRequiredSuite) TestLoadConfig_ErrorLoadingSrcConfig(c *C) {
c.Assert(strings.HasSuffix(err.Error(), "no such file or directory"), Equals, true)
}
c.Assert(strings.HasSuffix(err.Error(), "no such file or directory"), Equals, true)
}
// Setup a src config file
srcFile := setupConfigFile(c, "src-config")
defer os.Remove(srcFile.Name())
// Setup a src config file
srcFile := setupConfigFile(c, "src-config")
defer os.Remove(srcFile.Name())
// Setup a src config file
srcFile := setupConfigFile(c, "src-config")
defer os.Remove(srcFile.Name())
// Setup a src config file
srcFile := setupConfigFile(c, "src-config")
defer os.Remove(srcFile.Name())
c.Assert(strings.HasSuffix(err.Error(), "no such file or directory"), Equals, true)
}
c.Assert(strings.HasSuffix(err.Error(), "no such file or directory"), Equals, true)
}