Skip to content

Commit

Permalink
bugfix: change the option to set volume size
Browse files Browse the repository at this point in the history
Before use 'size' or 'opt.size' to set volume size, now change it to
'opt.size', 'size' will not effective.

Signed-off-by: Rudy Zhang <rudyflyzhang@gmail.com>
  • Loading branch information
rudyfly committed May 25, 2018
1 parent c320db1 commit 2fc15cf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 28 deletions.
18 changes: 6 additions & 12 deletions apis/server/volume_bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ func (s *Server) createVolume(ctx context.Context, rw http.ResponseWriter, req *
CreatedAt: volume.CreationTimestamp.Format("2006-1-2 15:04:05"),
}

var status map[string]interface{}
status := map[string]interface{}{}
for k, v := range volume.Options() {
if k != "" && v != "" {
if status == nil {
status = make(map[string]interface{})
}
status[k] = v
}
}
status["size"] = volume.Size()
respVolume.Status = status

return EncodeResponse(rw, http.StatusCreated, respVolume)
Expand All @@ -83,15 +81,13 @@ func (s *Server) getVolume(ctx context.Context, rw http.ResponseWriter, req *htt
Labels: volume.Labels,
}

var status map[string]interface{}
status := map[string]interface{}{}
for k, v := range volume.Options() {
if k != "" && v != "" {
if status == nil {
status = make(map[string]interface{})
}
status[k] = v
}
}
status["size"] = volume.Size()
respVolume.Status = status

return EncodeResponse(rw, http.StatusOK, respVolume)
Expand All @@ -113,15 +109,13 @@ func (s *Server) listVolume(ctx context.Context, rw http.ResponseWriter, req *ht
Labels: volume.Labels,
}

var status map[string]interface{}
status := map[string]interface{}{}
for k, v := range volume.Options() {
if k != "" && v != "" {
if status == nil {
status = make(map[string]interface{})
}
status[k] = v
}
}
status["size"] = volume.Size()
respVolume.Status = status

respVolumes.Volumes = append(respVolumes.Volumes, respVolume)
Expand Down
2 changes: 1 addition & 1 deletion apis/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ paths:
Scope: "local"
Options:
device: "tmpfs"
o: "size=100m,uid=1000"
o: "opt.size=100m,uid=1000"
type: "tmpfs"
Warnings: []
500:
Expand Down
2 changes: 1 addition & 1 deletion cli/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func parseVolume(volumeCreateConfig *types.VolumeCreateConfig, v *VolumeCreateCo

// volumeCreateExample shows examples in volume create command, and is used in auto-generated cli docs.
func volumeCreateExample() string {
return `$ pouch volume create -d local -n pouch-volume -o size=100g
return `$ pouch volume create -d local -n pouch-volume -o opt.size=100g
Mountpoint:
Name: pouch-volume
Scope:
Expand Down
2 changes: 1 addition & 1 deletion storage/volume/modules/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (p *Local) Options() map[string]types.Option {
func (p *Local) Attach(ctx driver.Context, v *types.Volume, s *types.Storage) error {
ctx.Log.Debugf("Local attach volume: %s", v.Name)
mountPath := v.Path()
size := v.Option("size")
size := v.Size()
reqID := v.Option("reqID")
ids := v.Option("ids")

Expand Down
6 changes: 3 additions & 3 deletions test/cli_alikernel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (suite *PouchAliKernelSuite) TestAliKernelDiskQuotaWorks(c *check.C) {
funcname = tmpname[i]
}

command.PouchRun("volume", "create", "--name", funcname, "-d", "local", "-o", "size=1g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", funcname, "-d", "local", "-o", "opt.size=1g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", funcname)

command.PouchRun("run", "-d", "-v", funcname+":/mnt", "--name", funcname, busyboxImage, "top").Assert(c, icmd.Success)
Expand Down Expand Up @@ -76,10 +76,10 @@ func (suite *PouchAliKernelSuite) TestAliKernelDiskQuotaMultiWorks(c *check.C) {
name1 := funcname + "1"
name2 := funcname + "2"

command.PouchRun("volume", "create", "--name", name1, "-d", "local", "-o", "size=2.2g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", name1, "-d", "local", "-o", "opt.size=2.2g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", name1)

command.PouchRun("volume", "create", "--name", name2, "-d", "local", "-o", "size=3.2g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", name2, "-d", "local", "-o", "opt.size=3.2g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", name2)

command.PouchRun("run", "-d", "-v", name1+":/mnt/test1", "-v", name2+":/mnt/test2", "--name", funcname, busyboxImage, "top").Assert(c, icmd.Success)
Expand Down
2 changes: 1 addition & 1 deletion test/cli_run_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (suite *PouchRunVolumeSuite) TestRunWithDiskQuotaRegular(c *check.C) {
containerName := "diskquota-regular"

ret := command.PouchRun("volume", "create", "-n", volumeName,
"-o", "size=256m", "-o", "mount=/data/volume")
"-o", "opt.size=256m", "-o", "mount=/data/volume")
defer func() {
command.PouchRun("volume", "rm", volumeName).Assert(c, icmd.Success)
}()
Expand Down
18 changes: 9 additions & 9 deletions test/cli_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (suite *PouchVolumeSuite) TestVolumeCreateWithSelector(c *check.C) {
defer command.PouchRun("volume", "remove", funcname)
}

// TestVolumeCreateWithSize tests creating volume with -o size=xxx.
// TestVolumeCreateWithSize tests creating volume with -o opt.size=xxx.
func (suite *PouchVolumeSuite) TestVolumeCreateWithSize(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
Expand All @@ -156,7 +156,7 @@ func (suite *PouchVolumeSuite) TestVolumeCreateWithSize(c *check.C) {
funcname = tmpname[i]
}

command.PouchRun("volume", "create", "--name", funcname, "-o", "size=1048576").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", funcname, "-o", "opt.size=1048576").Assert(c, icmd.Success)
defer command.PouchRun("volume", "remove", funcname)
}

Expand Down Expand Up @@ -267,15 +267,15 @@ func (suite *PouchVolumeSuite) TestVolumeList(c *check.C) {

volumeName := "volume_" + funcname
volumeName1 := "volume_" + funcname + "_1"
command.PouchRun("volume", "create", "--name", volumeName1, "-o", "size=1g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", volumeName1, "-o", "opt.size=1g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", volumeName1)

volumeName2 := "volume_" + funcname + "_2"
command.PouchRun("volume", "create", "--name", volumeName2, "-o", "size=2g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", volumeName2, "-o", "opt.size=2g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", volumeName2)

volumeName3 := "volume_" + funcname + "_3"
command.PouchRun("volume", "create", "--name", volumeName3, "-o", "size=3g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", volumeName3, "-o", "opt.size=3g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", volumeName3)

ret := command.PouchRun("volume", "list")
Expand All @@ -302,15 +302,15 @@ func (suite *PouchVolumeSuite) TestVolumeListOptions(c *check.C) {

volumeName := "volume_" + funcname
volumeName1 := "volume_" + funcname + "_1"
command.PouchRun("volume", "create", "--name", volumeName1, "-o", "size=1g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", volumeName1, "-o", "opt.size=1g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", volumeName1)

volumeName2 := "volume_" + funcname + "_2"
command.PouchRun("volume", "create", "--name", volumeName2, "-o", "size=2g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", volumeName2, "-o", "opt.size=2g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", volumeName2)

volumeName3 := "volume_" + funcname + "_3"
command.PouchRun("volume", "create", "--name", volumeName3, "-o", "size=3g").Assert(c, icmd.Success)
command.PouchRun("volume", "create", "--name", volumeName3, "-o", "opt.size=3g").Assert(c, icmd.Success)
defer command.PouchRun("volume", "rm", volumeName3)

ret := command.PouchRun("volume", "list", "--size", "--mountpoint")
Expand All @@ -319,7 +319,7 @@ func (suite *PouchVolumeSuite) TestVolumeListOptions(c *check.C) {
for _, line := range strings.Split(ret.Stdout(), "\n") {
if strings.Contains(line, volumeName) {
if !strings.Contains(line, "local") ||
!strings.Contains(line, "g") ||
!strings.Contains(line, "M") ||
!strings.Contains(line, DefaultVolumeMountPath) {
c.Errorf("list result have no driver or name or size or mountpoint, line: %s", line)
break
Expand Down

0 comments on commit 2fc15cf

Please sign in to comment.