Skip to content

Commit

Permalink
Update test for vSphere resizing disk change;
Browse files Browse the repository at this point in the history
  • Loading branch information
ycliuhw committed Jan 23, 2020
1 parent d2b8649 commit d7c8ac2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
8 changes: 3 additions & 5 deletions provider/vsphere/internal/vsphereclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"strings"

"github.com/dustin/go-humanize"
"github.com/juju/clock"
"github.com/juju/errors"
"github.com/juju/loggo"
Expand Down Expand Up @@ -43,10 +44,6 @@ func IsExtendDiskError(err error) bool {
return ok
}

func isNotSupported(err error) bool {
return err == object.ErrNotSupported
}

// Client encapsulates a vSphere client, exposing the subset of
// functionality that we require in the Juju provider.
type Client struct {
Expand Down Expand Up @@ -614,7 +611,8 @@ func (c *Client) extendDisk(
disk *types.VirtualDisk,
desiredCapacityKB int64,
) error {
c.logger.Debugf("extending disk from %v, to %v", disk.CapacityInKB, desiredCapacityKB)
prettySize := func(kb int64) string { return humanize.IBytes(uint64(kb) * 1024) }
c.logger.Debugf("extending disk from %q, to %q", prettySize(disk.CapacityInKB), prettySize(desiredCapacityKB))

// Resize the disk to desired size.
disk.CapacityInKB = desiredCapacityKB
Expand Down
23 changes: 17 additions & 6 deletions provider/vsphere/internal/vsphereclient/createvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ func (s *clientSuite) TestCreateVirtualMachineDatastoreSpecified(c *gc.C) {
_, err := client.CreateVirtualMachine(context.Background(), args)
c.Assert(err, jc.ErrorIsNil)

//findStubCall(c, s.roundTripper.Calls(), "?")

cisp := baseCisp()
cisp.EntityName = vmTemplateName(args)
s.roundTripper.CheckCall(
Expand Down Expand Up @@ -455,10 +453,23 @@ func (s *clientSuite) TestCreateVirtualMachineRootDiskSize(c *gc.C) {
_, err := client.CreateVirtualMachine(context.Background(), args)
c.Assert(err, jc.ErrorIsNil)

call := findStubCall(c, s.roundTripper.Calls(), "ExtendVirtualDisk")
c.Assert(call.Args, jc.DeepEquals, []interface{}{
"disk.vmdk",
int64(rootDisk) * 1024, // in KiB
s.roundTripper.CheckCall(c, 36, "ReconfigVM_Task", types.VirtualMachineConfigSpec{
DeviceChange: []types.BaseVirtualDeviceConfigSpec{
&types.VirtualDeviceConfigSpec{
Operation: types.VirtualDeviceConfigSpecOperationEdit,
FileOperation: "",
Device: &types.VirtualDisk{
VirtualDevice: types.VirtualDevice{
Backing: &types.VirtualDiskFlatVer2BackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: "disk.vmdk",
},
},
},
CapacityInKB: 1024 * 1024 * 20, // 20 GiB
},
},
},
})
}

Expand Down
3 changes: 2 additions & 1 deletion provider/vsphere/internal/vsphereclient/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ func (r *mockRoundTripper) RoundTrip(ctx context.Context, req, res soap.HasFault
r.MethodCall(r, "Logout")
res.Res = &types.LogoutResponse{}
case *methods.ReconfigVM_TaskBody:
r.MethodCall(r, "ReconfigVM_Task")
req := req.(*methods.ReconfigVM_TaskBody).Req
r.MethodCall(r, "ReconfigVM_Task", req.Spec)
res.Res = &types.ReconfigVM_TaskResponse{reconfigVMTask}
case *methods.Destroy_TaskBody:
r.MethodCall(r, "Destroy_Task")
Expand Down

0 comments on commit d7c8ac2

Please sign in to comment.