Skip to content

Commit

Permalink
Fixing active and bootable behavior on disk attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Bonic committed Jun 14, 2022
1 parent a09763c commit 5b40ea0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
2 changes: 0 additions & 2 deletions disk_attachment_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func (o *oVirtClient) CreateDiskAttachment(
attachmentBuilder.Disk(ovirtsdk.NewDiskBuilder().Id(string(diskID)).MustBuild())
attachmentBuilder.Interface(ovirtsdk.DiskInterface(diskInterface))
attachmentBuilder.Vm(ovirtsdk.NewVmBuilder().Id(string(vmID)).MustBuild())
attachmentBuilder.Active(true)
if params != nil {
if active := params.Active(); active != nil {
attachmentBuilder.Active(*active)
Expand Down Expand Up @@ -96,7 +95,6 @@ func (m *mockClient) CreateDiskAttachment(
diskID: disk.ID(),
diskInterface: diskInterface,
}
attachment.active = true
if params != nil {
if bootable := params.Bootable(); bootable != nil {
attachment.bootable = *bootable
Expand Down
19 changes: 18 additions & 1 deletion disk_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func TestDiskAttachmentCreation(t *testing.T) {
assertDiskAttachmentCount(t, vm, 0)
attachment := assertCanAttachDisk(t, vm, disk)
assertDiskAttachmentMatches(t, attachment, disk, vm)

if attachment.Active() {
t.Fatalf("Incorrect value for 'active' on newly created disk attachment.")
}
if attachment.Bootable() {
t.Fatalf("Incorrect value for 'bootable' on newly created disk attachment.")
}

assertDiskAttachmentCount(t, vm, 1)
assertCanDetachDisk(t, attachment)
}
Expand Down Expand Up @@ -89,7 +97,16 @@ func assertCanDetachDisk(t *testing.T, attachment ovirtclient.DiskAttachment) {
}

func assertCanAttachDisk(t *testing.T, vm ovirtclient.VM, disk ovirtclient.Disk) ovirtclient.DiskAttachment {
attachment, err := vm.AttachDisk(disk.ID(), ovirtclient.DiskInterfaceVirtIO, nil)
return assertCanAttachDiskWithParams(t, vm, disk, nil)
}

func assertCanAttachDiskWithParams(
t *testing.T,
vm ovirtclient.VM,
disk ovirtclient.Disk,
params ovirtclient.CreateDiskAttachmentOptionalParams,
) ovirtclient.DiskAttachment {
attachment, err := vm.AttachDisk(disk.ID(), ovirtclient.DiskInterfaceVirtIO, params)
if err != nil {
t.Fatalf("Failed to create disk attachment (%v)", err)
}
Expand Down
26 changes: 26 additions & 0 deletions template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ func TestTemplateDisk(t *testing.T) {
}
}

func TestTemplateDiskActiveBootable(t *testing.T) {
t.Parallel()
helper := getHelper(t)
disk := assertCanCreateDisk(t, helper)
vm := assertCanCreateVM(t, helper, helper.GenerateTestResourceName(t), nil)
assertCanAttachDiskWithParams(t, vm, disk, ovirtclient.CreateDiskAttachmentParams().MustWithActive(true).MustWithBootable(true))
template := assertCanCreateTemplate(t, helper, vm)

tplDiskAttachments := assertCanListTemplateDiskAttachments(t, template)
if !tplDiskAttachments[0].Active() {
t.Fatalf("Template disk attachment is not active.")
}
if !tplDiskAttachments[0].Bootable() {
t.Fatalf("Template disk attachment is not bootable.")
}

vm2 := assertCanCreateVMFromTemplate(t, helper, helper.GenerateTestResourceName(t), template.ID(), nil)
diskAttachments := assertCanListDiskAttachments(t, vm2)
if !diskAttachments[0].Active() {
t.Fatalf("VM disk attachment is not active.")
}
if !diskAttachments[0].Bootable() {
t.Fatalf("VM disk attachment is not bootable.")
}
}

// TestTemplateDiskCopy Copying template disks between storageDomains.
func TestTemplateDiskCopy(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 5b40ea0

Please sign in to comment.