Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/impl/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/contiv/volplugin/api"
"github.com/contiv/volplugin/config"
"github.com/contiv/volplugin/storage"

. "gopkg.in/check.v1"
)
Expand Down Expand Up @@ -70,7 +71,7 @@ func (s *dockerSuite) TestBasic(c *C) {
err := s.client.PublishPolicy("policy1", &config.Policy{
Name: "policy1",
Backend: "ceph",
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: config.CreateOptions{
Size: "10MB",
},
Expand Down
17 changes: 9 additions & 8 deletions config/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/contiv/errored"
"github.com/contiv/volplugin/errors"
"github.com/contiv/volplugin/storage"
"github.com/coreos/etcd/client"
"golang.org/x/net/context"
)
Expand All @@ -18,14 +19,14 @@ var defaultDrivers = map[string]*BackendDrivers{
// Policy is the configuration of the policy. It includes default
// information for items such as pool and volume configuration.
type Policy struct {
Name string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions RuntimeOptions `json:"runtime"`
DriverOptions map[string]string `json:"driver"`
FileSystems map[string]string `json:"filesystems"`
Backends *BackendDrivers `json:"backends,omitempty"`
Backend string `json:"backend,omitempty"`
Name string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions RuntimeOptions `json:"runtime"`
DriverOptions storage.DriverParams `json:"driver"`
FileSystems map[string]string `json:"filesystems"`
Backends *BackendDrivers `json:"backends,omitempty"`
Backend string `json:"backend,omitempty"`
}

// BackendDrivers is a struct containing all the drivers used under this policy
Expand Down
23 changes: 13 additions & 10 deletions config/policy_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import . "gopkg.in/check.v1"
import (
"github.com/contiv/volplugin/storage"
. "gopkg.in/check.v1"
)

var testPolicies = map[string]*Policy{
"basic": {
Expand All @@ -10,7 +13,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
Size: "10MB",
FileSystem: defaultFilesystem,
Expand All @@ -31,7 +34,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
Size: "20MB",
FileSystem: defaultFilesystem,
Expand All @@ -45,7 +48,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
Size: "0",
FileSystem: defaultFilesystem,
Expand All @@ -59,7 +62,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
Size: "20MB",
FileSystem: defaultFilesystem,
Expand All @@ -73,7 +76,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
Size: "not a number",
FileSystem: defaultFilesystem,
Expand All @@ -87,7 +90,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
Size: "10MB",
FileSystem: defaultFilesystem,
Expand All @@ -106,7 +109,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
},
Name: "blanksize",
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
FileSystem: defaultFilesystem,
},
Expand All @@ -119,7 +122,7 @@ var testPolicies = map[string]*Policy{
Mount: "ceph",
},
Name: "blanksize",
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
FileSystem: defaultFilesystem,
},
Expand All @@ -128,7 +131,7 @@ var testPolicies = map[string]*Policy{
},
"nobackend": {
Name: "nobackend",
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{
Size: "10MB",
FileSystem: defaultFilesystem,
Expand Down
9 changes: 6 additions & 3 deletions config/validation_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package config

import . "gopkg.in/check.v1"
import (
"github.com/contiv/volplugin/storage"
. "gopkg.in/check.v1"
)

var (
defaultBackends = &BackendDrivers{CRUD: "ceph", Mount: "ceph", Snapshot: "ceph"}
VolumeConfigs = map[string]map[string]*Volume{
"valid": {
"basic": {
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{Size: "10MB"},
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
VolumeName: "basicvolume",
PolicyName: "basicpolicy",
Backends: defaultBackends,
},
"basicwithruntime": {
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{Size: "10MB"},
RuntimeOptions: RuntimeOptions{UseSnapshots: true, Snapshot: SnapshotConfig{Frequency: "10m", Keep: 10}},
VolumeName: "basicvolume",
Expand Down
18 changes: 9 additions & 9 deletions config/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
// Volume is the configuration of the policy. It includes pool and
// snapshot information.
type Volume struct {
PolicyName string `json:"policy"`
VolumeName string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
DriverOptions map[string]string `json:"driver"`
MountSource string `json:"mount" merge:"mount"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions RuntimeOptions `json:"runtime"`
Backends *BackendDrivers `json:"backends,omitempty"`
PolicyName string `json:"policy"`
VolumeName string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
DriverOptions storage.DriverParams `json:"driver"`
MountSource string `json:"mount" merge:"mount"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions RuntimeOptions `json:"runtime"`
Backends *BackendDrivers `json:"backends,omitempty"`
}

// CreateOptions are the set of options used by apiserver during the volume
Expand Down Expand Up @@ -102,7 +102,7 @@ func (c *Client) CreateVolume(rc *VolumeRequest) (*Volume, error) {
}

if resp.DriverOptions == nil {
resp.DriverOptions = map[string]string{}
resp.DriverOptions = storage.DriverParams{}
}

if err := resp.Validate(); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions config/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s *configSuite) TestVolumeValidate(c *C) {
c.Assert(vc.Validate(), NotNil)

vc = &Volume{
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{Size: "10MB"},
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
VolumeName: "",
Expand All @@ -55,7 +55,7 @@ func (s *configSuite) TestVolumeValidate(c *C) {
c.Assert(vc.Validate(), NotNil)

vc = &Volume{
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{Size: "10MB"},
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
VolumeName: "foo",
Expand All @@ -70,7 +70,7 @@ func (s *configSuite) TestVolumeValidate(c *C) {
Snapshot: "ceph",
CRUD: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: CreateOptions{Size: "10MB"},
RuntimeOptions: RuntimeOptions{UseSnapshots: false},
VolumeName: "foo",
Expand Down Expand Up @@ -229,7 +229,7 @@ func (s *configSuite) TestToDriverOptions(c *C) {
Volume: storage.Volume{
Name: "policy1/test",
Size: 0xa,
Params: storage.Params{"pool": "rbd"},
Params: storage.DriverParams{"pool": "rbd"},
},
FSOptions: storage.FSOptions{
Type: "ext4",
Expand Down
34 changes: 18 additions & 16 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package db

import (
"time"

"github.com/contiv/volplugin/storage"
)

// Policy is the configuration of the policy. It includes default
// information for items such as pool and volume configuration.
type Policy struct {
Name string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions *RuntimeOptions `json:"runtime"`
DriverOptions map[string]string `json:"driver"`
FileSystems map[string]string `json:"filesystems"`
Backends *BackendDrivers `json:"backends,omitempty"`
Backend string `json:"backend,omitempty"`
Name string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions *RuntimeOptions `json:"runtime"`
DriverOptions storage.DriverParams `json:"driver"`
FileSystems map[string]string `json:"filesystems"`
Backends *BackendDrivers `json:"backends,omitempty"`
Backend string `json:"backend,omitempty"`
}

// BackendDrivers is a struct containing all the drivers used under this policy
Expand Down Expand Up @@ -61,14 +63,14 @@ type UseSnapshot struct {
// Volume is the configuration of the policy. It includes pool and
// snapshot information.
type Volume struct {
PolicyName string `json:"policy"`
VolumeName string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
DriverOptions map[string]string `json:"driver"`
MountSource string `json:"mount" merge:"mount"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions *RuntimeOptions `json:"runtime"`
Backends *BackendDrivers `json:"backends,omitempty"`
PolicyName string `json:"policy"`
VolumeName string `json:"name"`
Unlocked bool `json:"unlocked,omitempty" merge:"unlocked"`
DriverOptions storage.DriverParams `json:"driver"`
MountSource string `json:"mount" merge:"mount"`
CreateOptions CreateOptions `json:"create"`
RuntimeOptions *RuntimeOptions `json:"runtime"`
Backends *BackendDrivers `json:"backends,omitempty"`
}

// CreateOptions are the set of options used by apiserver during the volume
Expand Down
17 changes: 9 additions & 8 deletions db/test/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"github.com/contiv/volplugin/db"
"github.com/contiv/volplugin/storage"
. "gopkg.in/check.v1"
)

Expand All @@ -13,7 +14,7 @@ var testPolicies = map[string]*db.Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
Size: "10MB",
FileSystem: db.DefaultFilesystem,
Expand All @@ -34,7 +35,7 @@ var testPolicies = map[string]*db.Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
Size: "20MB",
FileSystem: db.DefaultFilesystem,
Expand All @@ -49,7 +50,7 @@ var testPolicies = map[string]*db.Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
Size: "0",
FileSystem: db.DefaultFilesystem,
Expand All @@ -63,7 +64,7 @@ var testPolicies = map[string]*db.Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
Size: "not a number",
FileSystem: db.DefaultFilesystem,
Expand All @@ -77,7 +78,7 @@ var testPolicies = map[string]*db.Policy{
Mount: "ceph",
Snapshot: "ceph",
},
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
Size: "10MB",
FileSystem: db.DefaultFilesystem,
Expand All @@ -96,7 +97,7 @@ var testPolicies = map[string]*db.Policy{
Mount: "ceph",
},
Name: "blanksize",
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
FileSystem: db.DefaultFilesystem,
},
Expand All @@ -109,7 +110,7 @@ var testPolicies = map[string]*db.Policy{
Mount: "ceph",
},
Name: "blanksize",
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
FileSystem: db.DefaultFilesystem,
},
Expand All @@ -118,7 +119,7 @@ var testPolicies = map[string]*db.Policy{
},
"nobackend": {
Name: "nobackend",
DriverOptions: map[string]string{"pool": "rbd"},
DriverOptions: storage.DriverParams{"pool": "rbd"},
CreateOptions: db.CreateOptions{
Size: "10MB",
FileSystem: db.DefaultFilesystem,
Expand Down
Loading