예제 #1
0
파일: worker.go 프로젝트: rif/golang-stuff
func (s *storageWorker) waitForDeath() error {
	storageDir := os.Getenv("JUJU_STORAGE_DIR")
	storageAddr := os.Getenv("JUJU_STORAGE_ADDR")
	logger.Infof("serving %s on %s", storageDir, storageAddr)

	storageListener, err := localstorage.Serve(storageAddr, storageDir)
	if err != nil {
		logger.Errorf("error with local storage: %v", err)
		return err
	}
	defer storageListener.Close()

	sharedStorageDir := os.Getenv("JUJU_SHARED_STORAGE_DIR")
	sharedStorageAddr := os.Getenv("JUJU_SHARED_STORAGE_ADDR")
	logger.Infof("serving %s on %s", sharedStorageDir, sharedStorageAddr)

	sharedStorageListener, err := localstorage.Serve(sharedStorageAddr, sharedStorageDir)
	if err != nil {
		logger.Errorf("error with local storage: %v", err)
		return err
	}
	defer sharedStorageListener.Close()

	logger.Infof("storage routines started, awaiting death")

	<-s.tomb.Dying()

	logger.Infof("dying, closing storage listeners")
	return tomb.ErrDying
}
예제 #2
0
// makeDummyStorage creates a local storage.
// Returns a cleanup function that must be called when done with the storage.
func makeDummyStorage(c *C) (environs.Storage, func()) {
	listener, err := localstorage.Serve("127.0.0.1:0", c.MkDir())
	c.Assert(err, IsNil)
	storage := localstorage.Client(listener.Addr().String())
	cleanup := func() { listener.Close() }
	return storage, cleanup
}
예제 #3
0
// CreateLocalTestStorage returns the listener, which needs to be closed, and
// the storage that is backed by a directory created in the running tests temp
// directory.
func CreateLocalTestStorage(c *gc.C) (closer io.Closer, storage environs.Storage, dataDir string) {
	dataDir = c.MkDir()
	listener, err := localstorage.Serve("localhost:0", dataDir)
	c.Assert(err, gc.IsNil)
	storage = localstorage.Client(listener.Addr().String())
	closer = listener
	return
}
예제 #4
0
func createLocalStorageListener(dir, address string) (net.Listener, error) {
	info, err := os.Stat(dir)
	if os.IsNotExist(err) {
		return nil, fmt.Errorf("storage directory %q does not exist, bootstrap first", dir)
	} else if err != nil {
		return nil, err
	} else if !info.Mode().IsDir() {
		return nil, fmt.Errorf("%q exists but is not a directory (and it needs to be)", dir)
	}
	return localstorage.Serve(address, dir)
}
예제 #5
0
// setDummyStorage injects the local provider's fake storage implementation
// into the given environment, so that tests can manipulate storage as if it
// were real.
// Returns a cleanup function that must be called when done with the storage.
func setDummyStorage(c *C, env *azureEnviron) func() {
	listener, err := localstorage.Serve("127.0.0.1:0", c.MkDir())
	c.Assert(err, IsNil)
	env.storage = localstorage.Client(listener.Addr().String())
	return func() { listener.Close() }
}
예제 #6
0
// startServer starts a new local storage server
// using a temporary directory and returns the listener,
// a base URL for the server and the directory path.
func startServer(c *C) (listener net.Listener, url, dataDir string) {
	dataDir = c.MkDir()
	listener, err := localstorage.Serve("localhost:0", dataDir)
	c.Assert(err, IsNil)
	return listener, fmt.Sprintf("http://%s/", listener.Addr()), dataDir
}