Skip to content

Commit

Permalink
Conflict resolution.
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasiamac committed Mar 24, 2015
1 parent 213e070 commit 0db7255
Show file tree
Hide file tree
Showing 23 changed files with 1,718 additions and 276 deletions.
24 changes: 24 additions & 0 deletions api/storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,27 @@ func (c *Client) List() ([]params.StorageInfo, error) {
}
return found.Results, nil
}

// ListPools returns a list of pools that matches given filter.
// If no filter was provided, a list of all pools is returned.
func (c *Client) ListPools(providers, names []string) ([]params.StoragePool, error) {
args := params.StoragePoolFilter{
Names: names,
Providers: providers,
}
found := params.StoragePoolsResult{}
if err := c.facade.FacadeCall("ListPools", args, &found); err != nil {
return nil, errors.Trace(err)
}
return found.Results, nil
}

// CreatePool creates pool with specified parameters.
func (c *Client) CreatePool(pname, provider string, attrs map[string]interface{}) error {
args := params.StoragePool{
Name: pname,
Provider: provider,
Attrs: attrs,
}
return c.facade.FacadeCall("CreatePool", args, nil)
}
133 changes: 119 additions & 14 deletions api/storage/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package storage_test

import (
"fmt"

"github.com/juju/errors"
"github.com/juju/names"
jc "github.com/juju/testing/checkers"
Expand All @@ -24,8 +26,6 @@ type storageMockSuite struct {
var _ = gc.Suite(&storageMockSuite{})

func (s *storageMockSuite) TestShow(c *gc.C) {
var called bool

one := "shared-fs/0"
oneTag := names.NewStorageTag(one)
two := "db-dir/1000"
Expand All @@ -39,7 +39,6 @@ func (s *storageMockSuite) TestShow(c *gc.C) {
id, request string,
a, result interface{},
) error {
called = true
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "Show")
Expand Down Expand Up @@ -74,11 +73,9 @@ func (s *storageMockSuite) TestShow(c *gc.C) {
c.Assert(found, gc.HasLen, 2)
c.Assert(expected.Contains(found[0].StorageTag), jc.IsTrue)
c.Assert(expected.Contains(found[1].StorageTag), jc.IsTrue)
c.Assert(called, jc.IsTrue)
}

func (s *storageMockSuite) TestShowFacadeCallError(c *gc.C) {
var called bool
one := "shared-fs/0"
oneTag := names.NewStorageTag(one)

Expand All @@ -89,7 +86,6 @@ func (s *storageMockSuite) TestShowFacadeCallError(c *gc.C) {
id, request string,
a, result interface{},
) error {
called = true
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "Show")
Expand All @@ -100,12 +96,9 @@ func (s *storageMockSuite) TestShowFacadeCallError(c *gc.C) {
found, err := storageClient.Show([]names.StorageTag{oneTag})
c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
c.Assert(found, gc.HasLen, 0)
c.Assert(called, jc.IsTrue)
}

func (s *storageMockSuite) TestList(c *gc.C) {
var called bool

one := "shared-fs/0"
oneTag := names.NewStorageTag(one)
two := "db-dir/1000"
Expand All @@ -118,7 +111,6 @@ func (s *storageMockSuite) TestList(c *gc.C) {
id, request string,
a, result interface{},
) error {
called = true
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "List")
Expand Down Expand Up @@ -163,20 +155,16 @@ func (s *storageMockSuite) TestList(c *gc.C) {
}

c.Assert(found, jc.DeepEquals, expected)
c.Assert(called, jc.IsTrue)
}

func (s *storageMockSuite) TestListFacadeCallError(c *gc.C) {
var called bool

msg := "facade failure"
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, result interface{},
) error {
called = true
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "List")
Expand All @@ -187,5 +175,122 @@ func (s *storageMockSuite) TestListFacadeCallError(c *gc.C) {
found, err := storageClient.List()
c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
c.Assert(found, gc.HasLen, 0)
}

func (s *storageMockSuite) TestListPools(c *gc.C) {
expected := []params.StoragePool{
params.StoragePool{Name: "name0", Provider: "type0"},
params.StoragePool{Name: "name1", Provider: "type1"},
params.StoragePool{Name: "name2", Provider: "type2"},
}
want := len(expected)

apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, result interface{},
) error {
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "ListPools")

args, ok := a.(params.StoragePoolFilter)
c.Assert(ok, jc.IsTrue)
c.Assert(args.Names, gc.HasLen, 2)
c.Assert(args.Providers, gc.HasLen, 1)

if results, k := result.(*params.StoragePoolsResult); k {
instances := make([]params.StoragePool, want)
for i := 0; i < want; i++ {
instances[i] = params.StoragePool{
Name: fmt.Sprintf("name%v", i),
Provider: fmt.Sprintf("type%v", i),
}
}
results.Results = instances
}

return nil
})
storageClient := storage.NewClient(apiCaller)
names := []string{"a", "b"}
types := []string{"1"}
found, err := storageClient.ListPools(types, names)
c.Assert(err, jc.ErrorIsNil)
c.Assert(found, gc.HasLen, want)
c.Assert(found, gc.DeepEquals, expected)
}

func (s *storageMockSuite) TestListPoolsFacadeCallError(c *gc.C) {
msg := "facade failure"
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, result interface{},
) error {
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "ListPools")

return errors.New(msg)
})
storageClient := storage.NewClient(apiCaller)
found, err := storageClient.ListPools(nil, nil)
c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
c.Assert(found, gc.HasLen, 0)
}

func (s *storageMockSuite) TestCreatePool(c *gc.C) {
var called bool
poolName := "poolName"
poolType := "poolType"
poolConfig := map[string]interface{}{
"test": "one",
"pass": true,
}

apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, result interface{},
) error {
called = true
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "CreatePool")

args, ok := a.(params.StoragePool)
c.Assert(ok, jc.IsTrue)
c.Assert(args.Name, gc.Equals, poolName)
c.Assert(args.Provider, gc.Equals, poolType)
c.Assert(args.Attrs, gc.DeepEquals, poolConfig)

return nil
})
storageClient := storage.NewClient(apiCaller)
err := storageClient.CreatePool(poolName, poolType, poolConfig)
c.Assert(err, jc.ErrorIsNil)
c.Assert(called, jc.IsTrue)
}

func (s *storageMockSuite) TestCreatePoolFacadeCallError(c *gc.C) {
msg := "facade failure"
apiCaller := basetesting.APICallerFunc(
func(objType string,
version int,
id, request string,
a, result interface{},
) error {
c.Check(objType, gc.Equals, "Storage")
c.Check(id, gc.Equals, "")
c.Check(request, gc.Equals, "CreatePool")

return errors.New(msg)
})
storageClient := storage.NewClient(apiCaller)
err := storageClient.CreatePool("", "", nil)
c.Assert(errors.Cause(err), gc.ErrorMatches, msg)
}
28 changes: 28 additions & 0 deletions apiserver/params/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,3 +415,31 @@ type StorageInfo struct {
type StorageInfosResult struct {
Results []StorageInfo `json:"results,omitempty"`
}

// StoragePool holds data for a pool instance.
type StoragePool struct {

// Name is the pool's name.
Name string `json:"name"`

// Provider is the type of storage provider this pool represents, eg "loop", "ebs".
Provider string `json:"provider"`

// Attrs are the pool's configuration attributes.
Attrs map[string]interface{} `json:"attrs"`
}

// StoragePoolFilter holds a filter for pool API call.
type StoragePoolFilter struct {

// Names are pool's names to filter on.
Names []string `json:"names,omitempty"`

// Providers are pool's storage provider types to filter on.
Providers []string `json:"providers,omitempty"`
}

// StoragePoolsResult holds a collection of pool instances.
type StoragePoolsResult struct {
Results []StoragePool `json:"results,omitempty"`
}
7 changes: 6 additions & 1 deletion apiserver/storage/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@

package storage

var CreateAPI = createAPI
var (
CreateAPI = createAPI
IsValidPoolListFilter = (*API).isValidPoolListFilter
ValidateNames = (*API).isValidNameCriteria
ValidateProviders = (*API).isValidProviderCriteria
)
Loading

0 comments on commit 0db7255

Please sign in to comment.