Skip to content

Commit ff98e33

Browse files
committed
Fix MAAS storage issues
- report WWN for block devices, and add to volume info; the MAAS provider now checks the id_path to see if it is a WWN, and matches on that. - set the status of volumes created/attached by the machine provisioner when setting instance info. This ensures that volumes show up as "attaching" or "attached" initially, and not "pending" forever for static volumes. - don't attempt to reattach static volumes. Fixes https://bugs.launchpad.net/juju/+bug/1677001
1 parent 302705c commit ff98e33

29 files changed

+187
-11
lines changed

apiserver/common/storagecommon/blockdevices.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func BlockDeviceFromState(in state.BlockDeviceInfo) storage.BlockDevice {
1717
in.Label,
1818
in.UUID,
1919
in.HardwareId,
20+
in.WWN,
2021
in.BusAddress,
2122
in.Size,
2223
in.FilesystemType,
@@ -33,6 +34,12 @@ func MatchingBlockDevice(
3334
attachmentInfo state.VolumeAttachmentInfo,
3435
) (*state.BlockDeviceInfo, bool) {
3536
for _, dev := range blockDevices {
37+
if volumeInfo.WWN != "" {
38+
if volumeInfo.WWN == dev.WWN {
39+
return &dev, true
40+
}
41+
continue
42+
}
3643
if volumeInfo.HardwareId != "" {
3744
if volumeInfo.HardwareId == dev.HardwareId {
3845
return &dev, true

apiserver/common/storagecommon/storage.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ func volumeAttachmentDevicePath(
229229
volumeAttachmentInfo state.VolumeAttachmentInfo,
230230
blockDevice state.BlockDeviceInfo,
231231
) (string, error) {
232-
if volumeInfo.HardwareId != "" || volumeAttachmentInfo.DeviceName != "" || volumeAttachmentInfo.DeviceLink != "" {
232+
if volumeInfo.HardwareId != "" ||
233+
volumeInfo.WWN != "" ||
234+
volumeAttachmentInfo.DeviceName != "" ||
235+
volumeAttachmentInfo.DeviceLink != "" {
233236
// Prefer the volume attachment's information over what is
234237
// in the published block device information.
235238
var deviceLinks []string
@@ -238,6 +241,7 @@ func volumeAttachmentDevicePath(
238241
}
239242
return storage.BlockDevicePath(storage.BlockDevice{
240243
HardwareId: volumeInfo.HardwareId,
244+
WWN: volumeInfo.WWN,
241245
DeviceName: volumeAttachmentInfo.DeviceName,
242246
DeviceLinks: deviceLinks,
243247
})

apiserver/common/storagecommon/storage_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (s *storageAttachmentInfoSuite) SetUpTest(c *gc.C) {
5959
DeviceName: "sda",
6060
DeviceLinks: []string{"/dev/disk/by-id/verbatim"},
6161
HardwareId: "whatever",
62+
WWN: "drbr",
6263
}}
6364
s.st = &fakeStorage{
6465
storageInstance: func(tag names.StorageTag) (state.StorageInstance, error) {
@@ -119,6 +120,17 @@ func (s *storageAttachmentInfoSuite) TestStorageAttachmentInfoPersistentHardware
119120
})
120121
}
121122

123+
func (s *storageAttachmentInfoSuite) TestStorageAttachmentInfoPersistentWWN(c *gc.C) {
124+
s.volume.info.WWN = "drbr"
125+
info, err := storagecommon.StorageAttachmentInfo(s.st, s.storageAttachment, s.machineTag)
126+
c.Assert(err, jc.ErrorIsNil)
127+
s.st.CheckCallNames(c, "StorageInstance", "StorageInstanceVolume", "VolumeAttachment", "BlockDevices")
128+
c.Assert(info, jc.DeepEquals, &storage.StorageAttachmentInfo{
129+
Kind: storage.StorageKindBlock,
130+
Location: filepath.FromSlash("/dev/disk/by-id/wwn-drbr"),
131+
})
132+
}
133+
122134
func (s *storageAttachmentInfoSuite) TestStorageAttachmentInfoMatchingBlockDevice(c *gc.C) {
123135
// The bus address alone is not enough to produce a path to the block
124136
// device; we need to find a published block device with the matching

apiserver/common/storagecommon/volumes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ func VolumeToState(v params.Volume) (names.VolumeTag, state.VolumeInfo, error) {
115115
}
116116
return volumeTag, state.VolumeInfo{
117117
v.Info.HardwareId,
118+
v.Info.WWN,
118119
v.Info.Size,
119120
"", // pool is set by state
120121
v.Info.VolumeId,
@@ -139,6 +140,7 @@ func VolumeInfoFromState(info state.VolumeInfo) params.VolumeInfo {
139140
return params.VolumeInfo{
140141
info.VolumeId,
141142
info.HardwareId,
143+
info.WWN,
142144
info.Pool,
143145
info.Size,
144146
info.Persistent,

apiserver/diskmanager/diskmanager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func stateBlockDeviceInfo(devices []storage.BlockDevice) []state.BlockDeviceInfo
9595
dev.Label,
9696
dev.UUID,
9797
dev.HardwareId,
98+
dev.WWN,
9899
dev.BusAddress,
99100
dev.Size,
100101
dev.FilesystemType,

apiserver/params/storage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ type Volume struct {
172172
type VolumeInfo struct {
173173
VolumeId string `json:"volume-id"`
174174
HardwareId string `json:"hardware-id,omitempty"`
175+
WWN string `json:"wwn,omitempty"`
175176
// Pool is the name of the storage pool used to
176177
// allocate the volume. Juju controllers older
177178
// than 2.2 do not populate this field, so it may

cmd/juju/storage/volume.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type VolumeInfo struct {
3333
// from params.Volume
3434
HardwareId string `yaml:"hardware-id,omitempty" json:"hardware-id,omitempty"`
3535

36+
// from params.Volume
37+
WWN string `yaml:"wwn,omitempty" json:"wwn,omitempty"`
38+
3639
// from params.Volume
3740
Size uint64 `yaml:"size" json:"size"`
3841

@@ -119,6 +122,7 @@ func createVolumeInfo(details params.VolumeDetails) (names.VolumeTag, VolumeInfo
119122
var info VolumeInfo
120123
info.ProviderVolumeId = details.Info.VolumeId
121124
info.HardwareId = details.Info.HardwareId
125+
info.WWN = details.Info.WWN
122126
info.Pool = details.Info.Pool
123127
info.Size = details.Info.Size
124128
info.Persistent = details.Info.Persistent

dependencies.tsv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ github.com/juju/ansiterm git b99631de12cf04a906c1d4e4ec54fb86eae5863d 2016-09-07
2121
github.com/juju/blobstore git 06056004b3d7b54bbb7984d830c537bad00fec21 2015-07-29T11:18:58Z
2222
github.com/juju/bundlechanges git 7725027b95e0d54635e0fb11efc2debdcdf19f75 2016-12-15T16:06:52Z
2323
github.com/juju/cmd git e47739aefe0adb68a401fcd371c0c92c8f6f8d99 2017-04-13T02:13:06Z
24-
github.com/juju/description git c1f554b8467afc4ec5e9175d162cc9a7217436a5 2017-05-09T00:06:37Z
24+
github.com/juju/description git 142fe63614f1a2defb592b6bdf6bd0ee47fdccfd 2017-05-10T01:22:00Z
2525
github.com/juju/errors git 1b5e39b83d1835fa480e0c2ddefb040ee82d58b3 2015-09-16T12:56:42Z
2626
github.com/juju/gnuflag git 4e76c56581859c14d9d87e1ddbe29e1c0f10195f 2016-08-09T16:52:14Z
2727
github.com/juju/go-oracle-cloud git 932a8cea00a1cd5cba3829a672c823955db674ae 2017-04-21T13:45:47Z

provider/maas/volumes.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (mi *maas2Instance) volumes(
323323
// There should be exactly one block device per label.
324324
if len(devices) == 0 {
325325
continue
326-
} else if len(devices) > 0 {
326+
} else if len(devices) > 1 {
327327
// This should never happen, as we only request one block
328328
// device per label. If it does happen, we'll just report
329329
// the first block device and log this warning.
@@ -362,8 +362,13 @@ func (mi *maas2Instance) volumes(
362362
deviceName := idPath[len(devPrefix):]
363363
attachment.DeviceName = deviceName
364364
} else if strings.HasPrefix(idPath, devDiskByIdPrefix) {
365-
hardwareId := idPath[len(devDiskByIdPrefix):]
366-
vol.HardwareId = hardwareId
365+
const wwnPrefix = "wwn-"
366+
id := idPath[len(devDiskByIdPrefix):]
367+
if strings.HasPrefix(id, wwnPrefix) {
368+
vol.WWN = id[len(wwnPrefix):]
369+
} else {
370+
vol.HardwareId = id
371+
}
367372
} else {
368373
// It's neither /dev/<name> nor /dev/disk/by-id/<hardware-id>,
369374
// so set it as the device link and hope for

provider/maas/volumes_test.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ func (s *volumeSuite) TestInstanceVolumesMAAS2(c *gc.C) {
8787
&fakeBlockDevice{name: "sde", idPath: "/dev/disk/by-dname/sde", size: 250362438230},
8888
},
8989
"4": {
90-
&fakeBlockDevice{name: "sdf", idPath: "/dev/disk/by-dname/sdf", size: 280362438231},
90+
&fakeBlockDevice{name: "sdf", idPath: "/dev/disk/by-id/wwn-drbr", size: 280362438231},
91+
},
92+
"5": {
93+
&fakeBlockDevice{name: "sdg", idPath: "/dev/disk/by-dname/sdg", size: 280362438231},
9194
},
9295
},
9396
},
@@ -97,12 +100,13 @@ func (s *volumeSuite) TestInstanceVolumesMAAS2(c *gc.C) {
97100
names.NewVolumeTag("1"),
98101
names.NewVolumeTag("2"),
99102
names.NewVolumeTag("3"),
103+
names.NewVolumeTag("4"),
100104
})
101105
c.Assert(err, jc.ErrorIsNil)
102-
// Expect 3 volumes - root volume is ignored, as are volumes
106+
// Expect 4 volumes - root volume is ignored, as are volumes
103107
// with tags we did not request.
104-
c.Assert(volumes, gc.HasLen, 3)
105-
c.Assert(attachments, gc.HasLen, 3)
108+
c.Assert(volumes, gc.HasLen, 4)
109+
c.Assert(attachments, gc.HasLen, 4)
106110
c.Check(volumes, jc.SameContents, []storage.Volume{{
107111
names.NewVolumeTag("1"),
108112
storage.VolumeInfo{
@@ -122,6 +126,13 @@ func (s *volumeSuite) TestInstanceVolumesMAAS2(c *gc.C) {
122126
VolumeId: "volume-3",
123127
Size: 238764,
124128
},
129+
}, {
130+
names.NewVolumeTag("4"),
131+
storage.VolumeInfo{
132+
VolumeId: "volume-4",
133+
Size: 267374,
134+
WWN: "drbr",
135+
},
125136
}})
126137
c.Assert(attachments, jc.SameContents, []storage.VolumeAttachment{{
127138
names.NewVolumeTag("1"),
@@ -139,6 +150,10 @@ func (s *volumeSuite) TestInstanceVolumesMAAS2(c *gc.C) {
139150
storage.VolumeAttachmentInfo{
140151
DeviceLink: "/dev/disk/by-dname/sdd",
141152
},
153+
}, {
154+
names.NewVolumeTag("4"),
155+
mTag,
156+
storage.VolumeAttachmentInfo{},
142157
}})
143158
}
144159

0 commit comments

Comments
 (0)