Esempio n. 1
0
func (s *ServerRequiredSuite) TestAskGetKeepProxyConnectionError(c *C) {
	arv, err := arvadosclient.MakeArvadosClient()
	c.Assert(err, Equals, nil)

	// keepclient with no such keep server
	kc := keepclient.New(&arv)
	locals := map[string]string{
		TestProxyUUID: "http://localhost:12345",
	}
	kc.SetServiceRoots(locals, nil, nil)

	// Ask should result in temporary connection refused error
	hash := fmt.Sprintf("%x", md5.Sum([]byte("foo")))
	_, _, err = kc.Ask(hash)
	c.Check(err, NotNil)
	errNotFound, _ := err.(*keepclient.ErrNotFound)
	c.Check(errNotFound.Temporary(), Equals, true)
	c.Assert(strings.Contains(err.Error(), "connection refused"), Equals, true)

	// Get should result in temporary connection refused error
	_, _, _, err = kc.Get(hash)
	c.Check(err, NotNil)
	errNotFound, _ = err.(*keepclient.ErrNotFound)
	c.Check(errNotFound.Temporary(), Equals, true)
	c.Assert(strings.Contains(err.Error(), "connection refused"), Equals, true)
}
Esempio n. 2
0
// setup keepclient using the config provided
func setupKeepClient(config apiConfig, keepServicesJSON string, isDst bool, replications int, srcBlobSignatureTTL time.Duration) (kc *keepclient.KeepClient, blobSignatureTTL time.Duration, err error) {
	arv := arvadosclient.ArvadosClient{
		ApiToken:    config.APIToken,
		ApiServer:   config.APIHost,
		ApiInsecure: config.APIHostInsecure,
		Client: &http.Client{Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: config.APIHostInsecure}}},
		External: config.ExternalClient,
	}

	// if keepServicesJSON is provided, use it to load services; else, use DiscoverKeepServers
	if keepServicesJSON == "" {
		kc, err = keepclient.MakeKeepClient(&arv)
		if err != nil {
			return nil, 0, err
		}
	} else {
		kc = keepclient.New(&arv)
		err = kc.LoadKeepServicesFromJSON(keepServicesJSON)
		if err != nil {
			return kc, 0, err
		}
	}

	if isDst {
		// Get default replications value from destination, if it is not already provided
		if replications == 0 {
			value, err := arv.Discovery("defaultCollectionReplication")
			if err == nil {
				replications = int(value.(float64))
			} else {
				return nil, 0, err
			}
		}

		kc.Want_replicas = replications
	}

	// If srcBlobSignatureTTL is not provided, get it from API server discovery doc
	blobSignatureTTL = srcBlobSignatureTTL
	if !isDst && srcBlobSignatureTTL == 0 {
		value, err := arv.Discovery("blobSignatureTtl")
		if err == nil {
			blobSignatureTTL = time.Duration(int(value.(float64))) * time.Second
		} else {
			return nil, 0, err
		}
	}

	return kc, blobSignatureTTL, nil
}
Esempio n. 3
0
func runProxy(c *C, args []string, bogusClientToken bool) *keepclient.KeepClient {
	args = append([]string{"keepproxy"}, args...)
	os.Args = append(args, "-listen=:0")
	listener = nil
	go main()
	waitForListener()

	arv, err := arvadosclient.MakeArvadosClient()
	c.Assert(err, Equals, nil)
	if bogusClientToken {
		arv.ApiToken = "bogus-token"
	}
	kc := keepclient.New(&arv)
	sr := map[string]string{
		TestProxyUUID: "http://" + listener.Addr().String(),
	}
	kc.SetServiceRoots(sr, sr, sr)
	kc.Arvados.External = true

	return kc
}
Esempio n. 4
0
// setup keepclient using the config provided
func setupKeepClient(config apiConfig, keepServicesJSON string, blobSignatureTTL time.Duration) (kc *keepclient.KeepClient, ttl time.Duration, err error) {
	arv := arvadosclient.ArvadosClient{
		ApiToken:    config.APIToken,
		ApiServer:   config.APIHost,
		ApiInsecure: config.APIHostInsecure,
		Client: &http.Client{Transport: &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: config.APIHostInsecure}}},
		External: config.ExternalClient,
	}

	// if keepServicesJSON is provided, use it to load services; else, use DiscoverKeepServers
	if keepServicesJSON == "" {
		kc, err = keepclient.MakeKeepClient(&arv)
		if err != nil {
			return
		}
	} else {
		kc = keepclient.New(&arv)
		err = kc.LoadKeepServicesFromJSON(keepServicesJSON)
		if err != nil {
			return
		}
	}

	// Get if blobSignatureTTL is not provided
	ttl = blobSignatureTTL
	if blobSignatureTTL == 0 {
		value, err := arv.Discovery("blobSignatureTtl")
		if err == nil {
			ttl = time.Duration(int(value.(float64))) * time.Second
		} else {
			return nil, 0, err
		}
	}

	return
}