Skip to content

Commit 19a6cbc

Browse files
committed
Migrate storage docs to use hostid not machineid
1 parent 67a0596 commit 19a6cbc

26 files changed

+441
-166
lines changed

apiserver/common/storagecommon/volumes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func VolumeAttachmentFromState(v state.VolumeAttachment) (params.VolumeAttachmen
144144
}
145145
return params.VolumeAttachment{
146146
v.Volume().String(),
147-
v.Machine().String(),
147+
v.Host().String(),
148148
VolumeAttachmentInfoFromState(info),
149149
}, nil
150150
}

apiserver/facades/agent/storageprovisioner/shim.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ type StorageBackend interface {
8787
RemoveFilesystem(names.FilesystemTag) error
8888
RemoveFilesystemAttachment(names.Tag, names.FilesystemTag) error
8989
RemoveVolume(names.VolumeTag) error
90-
RemoveVolumeAttachment(names.MachineTag, names.VolumeTag) error
90+
RemoveVolumeAttachment(names.Tag, names.VolumeTag) error
9191
DetachFilesystem(names.Tag, names.FilesystemTag) error
9292
DestroyFilesystem(names.FilesystemTag) error
9393
DetachVolume(names.Tag, names.VolumeTag) error

apiserver/facades/agent/storageprovisioner/storageprovisioner.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func NewStorageProvisionerAPIv3(
6363
if !authorizer.AuthMachineAgent() {
6464
return nil, common.ErrPerm
6565
}
66-
canAccessStorageMachine := func(tag names.MachineTag, allowController bool) bool {
66+
canAccessStorageMachine := func(tag names.Tag, allowController bool) bool {
6767
authEntityTag := authorizer.GetAuthTag()
6868
if tag == authEntityTag {
6969
// Machine agents can access volumes
@@ -121,7 +121,7 @@ func NewStorageProvisionerAPIv3(
121121
return false
122122
}
123123
for _, a := range volumeAttachments {
124-
if canAccessStorageMachine(a.Machine(), false) {
124+
if canAccessStorageMachine(a.Host(), false) {
125125
return true
126126
}
127127
}
@@ -623,13 +623,13 @@ func (s *StorageProvisionerAPIv3) VolumeParams(args params.Entities) (params.Vol
623623
volumeAttachmentParams, ok := volumeAttachment.Params()
624624
if !ok {
625625
return params.VolumeParams{}, errors.Errorf(
626-
"volume %q is already attached to machine %q",
626+
"volume %q is already attached to %q",
627627
volumeAttachment.Volume().Id(),
628-
volumeAttachment.Machine().Id(),
628+
names.ReadableString(volumeAttachment.Host()),
629629
)
630630
}
631-
machineTag := volumeAttachment.Machine()
632-
instanceId, err := s.st.MachineInstanceId(machineTag)
631+
hostTag := volumeAttachment.Host()
632+
instanceId, err := s.st.MachineInstanceId(hostTag.(names.MachineTag))
633633
if errors.IsNotProvisioned(err) {
634634
// Leave the attachment until later.
635635
instanceId = ""
@@ -638,7 +638,7 @@ func (s *StorageProvisionerAPIv3) VolumeParams(args params.Entities) (params.Vol
638638
}
639639
volumeParams.Attachment = &params.VolumeAttachmentParams{
640640
tag.String(),
641-
machineTag.String(),
641+
hostTag.String(),
642642
"", // volume ID
643643
string(instanceId),
644644
volumeParams.Provider,
@@ -847,7 +847,7 @@ func (s *StorageProvisionerAPIv3) VolumeAttachmentParams(
847847
if err != nil {
848848
return params.VolumeAttachmentParams{}, err
849849
}
850-
instanceId, err := s.st.MachineInstanceId(volumeAttachment.Machine())
850+
instanceId, err := s.st.MachineInstanceId(volumeAttachment.Host().(names.MachineTag))
851851
if errors.IsNotProvisioned(err) {
852852
// The worker must watch for machine provisioning events.
853853
instanceId = ""
@@ -888,7 +888,7 @@ func (s *StorageProvisionerAPIv3) VolumeAttachmentParams(
888888
}
889889
return params.VolumeAttachmentParams{
890890
volumeAttachment.Volume().String(),
891-
volumeAttachment.Machine().String(),
891+
volumeAttachment.Host().String(),
892892
volumeId,
893893
string(instanceId),
894894
string(providerType),
@@ -1045,7 +1045,7 @@ func (s *StorageProvisionerAPIv3) oneVolumeBlockDevice(
10451045
if err != nil {
10461046
return state.BlockDeviceInfo{}, err
10471047
}
1048-
blockDevices, err := s.sb.BlockDevices(volumeAttachment.Machine())
1048+
blockDevices, err := s.sb.BlockDevices(volumeAttachment.Host().(names.MachineTag))
10491049
if err != nil {
10501050
return state.BlockDeviceInfo{}, err
10511051
}
@@ -1056,9 +1056,9 @@ func (s *StorageProvisionerAPIv3) oneVolumeBlockDevice(
10561056
)
10571057
if !ok {
10581058
return state.BlockDeviceInfo{}, errors.NotFoundf(
1059-
"block device for volume %v on machine %v",
1059+
"block device for volume %v on %v",
10601060
volumeAttachment.Volume().Id(),
1061-
volumeAttachment.Machine().Id(),
1061+
names.ReadableString(volumeAttachment.Host()),
10621062
)
10631063
}
10641064
return *blockDevice, nil

apiserver/facades/agent/storageprovisioner/storageprovisioner_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (s *provisionerSuite) TestVolumeAttachments(c *gc.C) {
295295
}},
296296
{Error: &params.Error{
297297
Code: params.CodeNotProvisioned,
298-
Message: `volume attachment "2" on "0" not provisioned`,
298+
Message: `volume attachment "2" on "machine 0" not provisioned`,
299299
}},
300300
{Error: &params.Error{Message: "permission denied", Code: "unauthorized access"}},
301301
},

apiserver/facades/client/storage/base_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ func (s *baseStorageSuite) constructStorageAccessor() *mockStorageAccessor {
146146
}
147147
s.volume = &mockVolume{tag: s.volumeTag, storage: &s.storageTag}
148148
s.volumeAttachment = &mockVolumeAttachment{
149-
VolumeTag: s.volumeTag,
150-
MachineTag: s.machineTag,
151-
life: state.Alive,
149+
VolumeTag: s.volumeTag,
150+
HostTag: s.machineTag,
151+
life: state.Alive,
152152
}
153153

154154
return &mockStorageAccessor{

apiserver/facades/client/storage/mock_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,18 @@ func (m *mockStorageAttachment) Life() state.Life {
327327
}
328328

329329
type mockVolumeAttachment struct {
330-
VolumeTag names.VolumeTag
331-
MachineTag names.MachineTag
332-
info *state.VolumeAttachmentInfo
333-
life state.Life
330+
VolumeTag names.VolumeTag
331+
HostTag names.Tag
332+
info *state.VolumeAttachmentInfo
333+
life state.Life
334334
}
335335

336336
func (va *mockVolumeAttachment) Volume() names.VolumeTag {
337337
return va.VolumeTag
338338
}
339339

340-
func (va *mockVolumeAttachment) Machine() names.MachineTag {
341-
return va.MachineTag
340+
func (va *mockVolumeAttachment) Host() names.Tag {
341+
return va.HostTag
342342
}
343343

344344
func (va *mockVolumeAttachment) Life() state.Life {

apiserver/facades/client/storage/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ func createVolumeDetails(
554554
stateInfo,
555555
)
556556
}
557-
details.MachineAttachments[attachment.Machine().String()] = attDetails
557+
details.MachineAttachments[attachment.Host().String()] = attDetails
558558
}
559559
}
560560

apiserver/facades/controller/caasunitprovisioner/provisioner.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,6 @@ func (a *Facade) updateStatus(params params.ApplicationUnitParams) (
446446
Data: params.Data,
447447
}
448448
}
449-
logger.Criticalf("AGENT STATUS: %v", agentStatus)
450-
logger.Criticalf("UNIT STATUS: %v", unitStatus)
451449
return agentStatus, unitStatus, nil
452450
}
453451

state/cleanup.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -745,10 +745,10 @@ func cleanupDyingMachineResources(m *Machine) error {
745745
return errors.Trace(err)
746746
}
747747

748-
// Destroy non-detachable machine filesystems first.
749-
filesystems, err := sb.filesystems(bson.D{{"machineid", m.Id()}})
748+
// Destroy non-detachable machine/unit filesystems first.
749+
filesystems, err := sb.filesystems(bson.D{{"hostid", m.Id()}})
750750
if err != nil {
751-
return errors.Annotate(err, "getting machine filesystems")
751+
return errors.Annotate(err, "getting host filesystems")
752752
}
753753
for _, f := range filesystems {
754754
if err := sb.DestroyFilesystem(f.FilesystemTag()); err != nil {
@@ -843,7 +843,7 @@ func cleanupDyingMachineResources(m *Machine) error {
843843
// Non-detachable volumes will be removed along with the machine.
844844
continue
845845
}
846-
if err := sb.DetachVolume(va.Machine(), va.Volume()); err != nil {
846+
if err := sb.DetachVolume(va.Host(), va.Volume()); err != nil {
847847
if IsContainsFilesystem(err) {
848848
// The volume will be destroyed when the
849849
// contained filesystem is removed, whose
@@ -942,12 +942,12 @@ func (st *State) cleanupAttachmentsForDyingVolume(volumeId string) (err error) {
942942
}
943943

944944
var doc volumeAttachmentDoc
945-
fields := bson.D{{"machineid", 1}}
945+
fields := bson.D{{"hostid", 1}}
946946
iter := coll.Find(bson.D{{"volumeid", volumeId}}).Select(fields).Iter()
947947
defer closeIter(iter, &err, "reading volume attachment document")
948948
for iter.Next(&doc) {
949-
machineTag := names.NewMachineTag(doc.Machine)
950-
if err := sb.DetachVolume(machineTag, volumeTag); err != nil {
949+
hostTag := storageAttachmentHost(doc.Host)
950+
if err := sb.DetachVolume(hostTag, volumeTag); err != nil {
951951
return errors.Annotate(err, "destroying volume attachment")
952952
}
953953
}
@@ -973,18 +973,11 @@ func (st *State) cleanupAttachmentsForDyingFilesystem(filesystemId string) (err
973973
defer closer()
974974

975975
var doc filesystemAttachmentDoc
976-
// TODO(caas) - consolidate machineidand hostid
977-
fields := bson.D{{"machineid", 1}, {"hostid", 1}}
976+
fields := bson.D{{"hostid", 1}}
978977
iter := coll.Find(bson.D{{"filesystemid", filesystemId}}).Select(fields).Iter()
979978
defer closeIter(iter, &err, "reading filesystem attachment document")
980979
for iter.Next(&doc) {
981-
var host string
982-
if doc.Host != "" {
983-
host = doc.Host
984-
} else {
985-
host = doc.Machine
986-
}
987-
hostTag := filesystemAttachmentHost(host)
980+
hostTag := storageAttachmentHost(doc.Host)
988981
if err := sb.DetachFilesystem(hostTag, filesystemTag); err != nil {
989982
return errors.Annotate(err, "destroying filesystem attachment")
990983
}

state/filesystem.go

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ type filesystemDoc struct {
116116
Info *FilesystemInfo `bson:"info,omitempty"`
117117
Params *FilesystemParams `bson:"params,omitempty"`
118118

119-
// MachineId is the ID of the machine that a non-detachable
119+
// HostId is the ID of the host that a non-detachable
120120
// volume is initially attached to. We use this to identify
121121
// the filesystem as being non-detachable, and to determine
122122
// which filesystems must be removed along with said machine.
123-
MachineId string `bson:"machineid,omitempty"`
123+
HostId string `bson:"hostid,omitempty"`
124124
}
125125

126126
// filesystemAttachmentDoc records information about a filesystem attachment.
@@ -130,10 +130,7 @@ type filesystemAttachmentDoc struct {
130130
ModelUUID string `bson:"model-uuid"`
131131
Filesystem string `bson:"filesystemid"`
132132

133-
// TODO(caas) - consolidate Machine and Host using upgrade step
134-
Machine string `bson:"machineid"`
135-
Host string `bson:"hostid"`
136-
133+
Host string `bson:"hostid"`
137134
Life Life `bson:"life"`
138135
Info *FilesystemAttachmentInfo `bson:"info,omitempty"`
139136
Params *FilesystemAttachmentParams `bson:"params,omitempty"`
@@ -299,7 +296,7 @@ func (f *filesystemAttachment) Filesystem() names.FilesystemTag {
299296
return names.NewFilesystemTag(f.doc.Filesystem)
300297
}
301298

302-
func filesystemAttachmentHost(id string) names.Tag {
299+
func storageAttachmentHost(id string) names.Tag {
303300
if names.IsValidUnit(id) {
304301
return names.NewUnitTag(id)
305302
}
@@ -308,11 +305,7 @@ func filesystemAttachmentHost(id string) names.Tag {
308305

309306
// Host is required to implement FilesystemAttachment.
310307
func (f *filesystemAttachment) Host() names.Tag {
311-
// TODO(caas) - consolidate host and machine
312-
if f.doc.Host != "" {
313-
return filesystemAttachmentHost(f.doc.Host)
314-
}
315-
return filesystemAttachmentHost(f.doc.Machine)
308+
return storageAttachmentHost(f.doc.Host)
316309
}
317310

318311
// Life is required to implement FilesystemAttachment.
@@ -323,11 +316,7 @@ func (f *filesystemAttachment) Life() Life {
323316
// Info is required to implement FilesystemAttachment.
324317
func (f *filesystemAttachment) Info() (FilesystemAttachmentInfo, error) {
325318
if f.doc.Info == nil {
326-
host := f.doc.Host
327-
if host == "" {
328-
host = f.doc.Machine
329-
}
330-
hostTag := filesystemAttachmentHost(host)
319+
hostTag := storageAttachmentHost(f.doc.Host)
331320
return FilesystemAttachmentInfo{}, errors.NotProvisionedf(
332321
"filesystem attachment %q on %q", f.doc.Filesystem, names.ReadableString(hostTag))
333322
}
@@ -470,7 +459,7 @@ func (sb *storageBackend) FilesystemAttachments(filesystem names.FilesystemTag)
470459
// MachineFilesystemAttachments returns all of the FilesystemAttachments for the
471460
// specified machine.
472461
func (sb *storageBackend) MachineFilesystemAttachments(machine names.MachineTag) ([]FilesystemAttachment, error) {
473-
attachments, err := sb.filesystemAttachments(bson.D{{"machineid", machine.Id()}})
462+
attachments, err := sb.filesystemAttachments(bson.D{{"hostid", machine.Id()}})
474463
if err != nil {
475464
return nil, errors.Annotatef(err, "getting filesystem attachments for %q", names.ReadableString(machine))
476465
}
@@ -520,7 +509,7 @@ func (sb *storageBackend) removeMachineFilesystemsOps(m *Machine) ([]txn.Op, err
520509
// is removed will the filesystem transition to Dead and then be removed.
521510
// Therefore, there may be filesystems that are bound, but not attached,
522511
// to the machine.
523-
machineFilesystems, err := sb.filesystems(bson.D{{"machineid", m.Id()}})
512+
machineFilesystems, err := sb.filesystems(bson.D{{"hostid", m.Id()}})
524513
if err != nil {
525514
return nil, errors.Trace(err)
526515
}
@@ -566,12 +555,12 @@ func isDetachableFilesystemTag(db Database, tag names.FilesystemTag) (bool, erro
566555
if err != nil {
567556
return false, errors.Trace(err)
568557
}
569-
return doc.MachineId == "", nil
558+
return doc.HostId == "", nil
570559
}
571560

572561
// Detachable reports whether or not the filesystem is detachable.
573562
func (f *filesystem) Detachable() bool {
574-
return f.doc.MachineId == ""
563+
return f.doc.HostId == ""
575564
}
576565

577566
func (f *filesystem) pool() string {
@@ -1018,17 +1007,17 @@ func ParseFilesystemAttachmentId(id string) (names.Tag, names.FilesystemTag, err
10181007
}
10191008

10201009
// newFilesystemId returns a unique filesystem ID.
1021-
// If the machine ID supplied is non-empty, the
1010+
// If the host ID supplied is non-empty, the
10221011
// filesystem ID will incorporate it as the
10231012
// filesystem's machine scope.
1024-
func newFilesystemId(mb modelBackend, machineId string) (string, error) {
1013+
func newFilesystemId(mb modelBackend, hostId string) (string, error) {
10251014
seq, err := sequence(mb, "filesystem")
10261015
if err != nil {
10271016
return "", errors.Trace(err)
10281017
}
10291018
id := fmt.Sprint(seq)
1030-
if machineId != "" {
1031-
id = machineId + "/" + id
1019+
if hostId != "" {
1020+
id = hostId + "/" + id
10321021
}
10331022
return id, nil
10341023
}
@@ -1047,7 +1036,7 @@ func (sb *storageBackend) addFilesystemOps(params FilesystemParams, hostId strin
10471036
if err != nil {
10481037
return nil, names.FilesystemTag{}, names.VolumeTag{}, errors.Trace(err)
10491038
}
1050-
origMachineId := hostId
1039+
origHostId := hostId
10511040
hostId, err = sb.validateFilesystemParams(params, hostId)
10521041
if err != nil {
10531042
return nil, names.FilesystemTag{}, names.VolumeTag{}, errors.Annotate(err, "validating filesystem params")
@@ -1113,7 +1102,7 @@ func (sb *storageBackend) addFilesystemOps(params FilesystemParams, hostId strin
11131102
doc.AttachmentCount = 1
11141103
}
11151104
if !detachable {
1116-
doc.MachineId = origMachineId
1105+
doc.HostId = origHostId
11171106
}
11181107
ops = append(ops, sb.newFilesystemOps(doc, statusDoc)...)
11191108
return ops, filesystemTag, volumeTag, nil
@@ -1185,7 +1174,6 @@ func createMachineFilesystemAttachmentsOps(hostId string, attachments []filesyst
11851174
Assert: txn.DocMissing,
11861175
Insert: &filesystemAttachmentDoc{
11871176
Filesystem: attachment.tag.Id(),
1188-
Machine: hostId,
11891177
Host: hostId,
11901178
Params: &paramsCopy,
11911179
},

state/migration_export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,7 @@ func (e *exporter) addVolume(vol *volume, volAttachments []volumeAttachmentDoc)
18071807
va := volumeAttachment{doc}
18081808
logger.Debugf(" attachment %#v", doc)
18091809
args := description.VolumeAttachmentArgs{
1810-
Machine: va.Machine(),
1810+
Machine: va.Host().(names.MachineTag),
18111811
}
18121812
if info, err := va.Info(); err == nil {
18131813
logger.Debugf(" info %#v", info)

0 commit comments

Comments
 (0)