Check if address space valid in getStore

Added a check to see if address space is valid in
addrSpaces map before accessing it. Also fixed some
error strings so that it provides better information
to the user.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2015-10-12 10:52:58 -07:00
parent c454b1084d
commit 6d6490b91c
2 changed files with 7 additions and 3 deletions

View file

@ -130,7 +130,7 @@ func (a *Allocator) RequestPool(addressSpace, pool, subPool string, options map[
log.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6)
k, nw, ipr, err := a.parsePoolRequest(addressSpace, pool, subPool, v6)
if err != nil {
return "", nil, nil, ipamapi.ErrInvalidPool
return "", nil, nil, types.InternalErrorf("failed to parse pool request for address space %q pool %q subpool %q: %v", addressSpace, pool, subPool, err)
}
retry:
@ -199,7 +199,7 @@ func (a *Allocator) getAddrSpace(as string) (*addrSpace, error) {
defer a.Unlock()
aSpace, ok := a.addrSpaces[as]
if !ok {
return nil, types.BadRequestErrorf("cannot find locality of address space: %s", as)
return nil, types.BadRequestErrorf("cannot find address space %s (most likey the backing datastore is not configured)", as)
}
return aSpace, nil
}

View file

@ -74,7 +74,11 @@ func (a *Allocator) getStore(as string) datastore.DataStore {
a.Lock()
defer a.Unlock()
return a.addrSpaces[as].ds
if aSpace, ok := a.addrSpaces[as]; ok {
return aSpace.ds
}
return nil
}
func (a *Allocator) getAddressSpaceFromStore(as string) (*addrSpace, error) {