Permalink
Browse files

state: copy Pool from params to info on SetXInfo

Set{Volume,Filesystem}Info will now copy the Pool
from Params to Info the first time it's called for
a volume/filesystem.
  • Loading branch information...
1 parent cd1c7be commit 196ad48a0ec4633f545979530e1e40d3e4529487 @axw committed Mar 16, 2015
Showing with 30 additions and 9 deletions.
  1. +14 −1 state/filesystem.go
  2. +1 −0 state/filesystem_test.go
  3. +6 −6 state/machine_test.go
  4. +1 −1 state/state_test.go
  5. +6 −1 state/volume.go
  6. +2 −0 state/volume_test.go
View
@@ -61,6 +61,11 @@ type FilesystemAttachment interface {
// Info returns the filesystem attachment's FilesystemAttachmentInfo, or a
// NotProvisioned error if the attachment has not yet been made.
+ //
+ // Note that the presence of FilesystemAttachmentInfo does not necessarily
+ // imply that the filesystem is mounted; environment storage providers may
+ // need to prepare a filesystem for attachment to a machine before it can
+ // be mounted.
Info() (FilesystemAttachmentInfo, error)
// Params returns the parameters for creating the filesystem attachment,
@@ -114,6 +119,7 @@ type FilesystemParams struct {
// FilesystemInfo describes information about a filesystem.
type FilesystemInfo struct {
Size uint64 `bson:"size"`
+ Pool string `bson:"pool"`
// FilesystemId is the provider-allocated unique ID of the
// filesystem. This will be unspecified for filesystems
@@ -123,6 +129,9 @@ type FilesystemInfo struct {
// FilesystemAttachmentInfo describes information about a filesystem attachment.
type FilesystemAttachmentInfo struct {
+ // MountPoint is the path at which the filesystem is mounted on the
+ // machine. MountPoint may be empty, meaning that the filesystem is
+ // not mounted yet.
MountPoint string `bson:"mountpoint"`
}
@@ -410,7 +419,11 @@ func (st *State) SetFilesystemInfo(tag names.FilesystemTag, info FilesystemInfo)
// If the filesystem has parameters, unset them
// when we set info for the first time, ensuring
// that params and info are mutually exclusive.
- _, unsetParams := fs.Params()
+ var unsetParams bool
+ if params, ok := fs.Params(); ok {
+ info.Pool = params.Pool
+ unsetParams = true
+ }
ops := setFilesystemInfoOps(tag, info, unsetParams)
return ops, nil
}
View
@@ -160,6 +160,7 @@ func (s *FilesystemStateSuite) TestFilesystemInfo(c *gc.C) {
filesystemInfo := state.FilesystemInfo{FilesystemId: "fs-123", Size: 456}
err = s.State.SetFilesystemInfo(filesystemTag, filesystemInfo)
c.Assert(err, jc.ErrorIsNil)
+ filesystemInfo.Pool = "loop-pool" // taken from params
s.assertFilesystemInfo(c, filesystemTag, filesystemInfo)
s.assertFilesystemAttachmentUnprovisioned(c, machineTag, filesystemTag)
View
@@ -949,12 +949,11 @@ func (s *MachineSuite) TestMachineSetInstanceInfoSuccess(c *gc.C) {
interfaces := []state.NetworkInterfaceInfo{
{MACAddress: "aa:bb:cc:dd:ee:ff", NetworkName: "net1", InterfaceName: "eth0", IsVirtual: false},
}
- volumes := map[names.VolumeTag]state.VolumeInfo{
- volumeTag: state.VolumeInfo{
- VolumeId: "storage-123",
- Size: 1234,
- },
+ volumeInfo := state.VolumeInfo{
+ VolumeId: "storage-123",
+ Size: 1234,
}
+ volumes := map[names.VolumeTag]state.VolumeInfo{volumeTag: volumeInfo}
err = s.machine.SetInstanceInfo("umbrella/0", "fake_nonce", nil, networks, interfaces, volumes, nil)
c.Assert(err, jc.ErrorIsNil)
c.Assert(s.machine.CheckProvisioned("fake_nonce"), jc.IsTrue)
@@ -977,7 +976,8 @@ func (s *MachineSuite) TestMachineSetInstanceInfoSuccess(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
info, err := volume.Info()
c.Assert(err, jc.ErrorIsNil)
- c.Assert(info, gc.Equals, volumes[volumeTag])
+ volumeInfo.Pool = "loop-pool" // taken from params
+ c.Assert(info, gc.Equals, volumeInfo)
}
func (s *MachineSuite) TestMachineSetProvisionedWhenNotAlive(c *gc.C) {
View
@@ -1225,7 +1225,7 @@ func (s *StateSuite) TestAddMachineWithVolumes(c *gc.C) {
volumeAttachments, err := s.State.MachineVolumeAttachments(m.MachineTag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeAttachments, gc.HasLen, 2)
- if volumeAttachments[0].Volume() == names.NewVolumeTag("1") {
+ if volumeAttachments[0].Volume() == names.NewVolumeTag(m.Id()+"/1") {
va := volumeAttachments
va[0], va[1] = va[1], va[0]
}
View
@@ -115,6 +115,7 @@ type VolumeParams struct {
type VolumeInfo struct {
Serial string `bson:"serial,omitempty"`
Size uint64 `bson:"size"`
+ Pool string `bson:"pool"`
VolumeId string `bson:"volumeid"`
}
@@ -470,7 +471,11 @@ func (st *State) SetVolumeInfo(tag names.VolumeTag, info VolumeInfo) (err error)
// If the volume has parameters, unset them when
// we set info for the first time, ensuring that
// params and info are mutually exclusive.
- _, unsetParams := v.Params()
+ var unsetParams bool
+ if params, ok := v.Params(); ok {
+ info.Pool = params.Pool
+ unsetParams = true
+ }
ops := setVolumeInfoOps(tag, info, unsetParams)
return ops, nil
}
View
@@ -129,6 +129,7 @@ func (s *VolumeStateSuite) TestSetVolumeInfo(c *gc.C) {
volumeInfoSet := state.VolumeInfo{Size: 123}
err = s.State.SetVolumeInfo(volume.VolumeTag(), volumeInfoSet)
c.Assert(err, jc.ErrorIsNil)
+ volumeInfoSet.Pool = "loop-pool" // taken from params
s.assertVolumeInfo(c, volumeTag, volumeInfoSet)
}
@@ -172,6 +173,7 @@ func (s *VolumeStateSuite) TestSetVolumeInfoNoStorageAssigned(c *gc.C) {
volumeInfoSet := state.VolumeInfo{Size: 123}
err = s.State.SetVolumeInfo(volume.VolumeTag(), volumeInfoSet)
c.Assert(err, jc.ErrorIsNil)
+ volumeInfoSet.Pool = "loop-pool" // taken from params
s.assertVolumeInfo(c, volumeTag, volumeInfoSet)
}

0 comments on commit 196ad48

Please sign in to comment.