-
Notifications
You must be signed in to change notification settings - Fork 21
/
disk_uploadimage_test.go
99 lines (81 loc) · 2.53 KB
/
disk_uploadimage_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package ovirtclient_test
import (
"fmt"
"testing"
ovirtclient "github.com/ovirt/go-ovirt-client/v3"
)
func assertCanUploadDiskImage(t *testing.T, helper ovirtclient.TestHelper, disk ovirtclient.Disk) {
fh, size := getTestImageFile(t)
originalSize := disk.ProvisionedSize()
if originalSize < size {
if _, err := disk.Update(
ovirtclient.UpdateDiskParams().MustWithProvisionedSize(size),
); err != nil {
t.Fatalf("Failed to resize disk from %d to %d bytes. (%v)", originalSize, size, err)
}
}
client := helper.GetClient()
if err := client.UploadToDisk(disk.ID(), size, fh); err != nil {
t.Fatalf("Failed to upload disk image to disk %s. (%v)", disk.ID(), err)
}
}
func assertCanUploadFullyFunctionalDiskImage(t *testing.T, helper ovirtclient.TestHelper, disk ovirtclient.Disk) {
fh, size, virtualSize := getFullTestImage(t)
originalSize := disk.ProvisionedSize()
if originalSize < virtualSize {
if _, err := disk.Update(
ovirtclient.UpdateDiskParams().MustWithProvisionedSize(virtualSize),
); err != nil {
t.Fatalf("Failed to resize disk from %d to %d bytes. (%v)", originalSize, virtualSize, err)
}
}
client := helper.GetClient()
if err := client.UploadToDisk(disk.ID(), size, fh); err != nil {
t.Fatalf("Failed to upload disk image to disk %s. (%v)", disk.ID(), err)
}
}
func TestImageUploadDiskCreated(t *testing.T) {
t.Parallel()
fh, size := getTestImageFile(t)
helper := getHelper(t)
client := helper.GetClient()
imageName := fmt.Sprintf("client_test_%s", helper.GenerateRandomID(5))
uploadResult, err := client.UploadToNewDisk(
helper.GetStorageDomainID(),
ovirtclient.ImageFormatRaw,
size,
ovirtclient.CreateDiskParams().MustWithSparse(true).MustWithAlias(imageName),
fh,
)
if err != nil {
t.Fatal(fmt.Errorf("failed to upload image (%w)", err))
}
disk, err := client.GetDisk(uploadResult.Disk().ID())
if err != nil {
t.Fatal(fmt.Errorf("failed to fetch disk after image upload (%w)", err))
}
if err := client.RemoveDisk(disk.ID()); err != nil {
t.Fatal(err)
}
}
func TestImageUploadToExistingDisk(t *testing.T) {
t.Parallel()
helper := getHelper(t)
client := helper.GetClient()
imageName := fmt.Sprintf("client_test_%s", helper.GenerateRandomID(5))
disk, err := client.CreateDisk(
helper.GetStorageDomainID(),
ovirtclient.ImageFormatRaw,
uint64(1048576),
ovirtclient.CreateDiskParams().MustWithSparse(true).MustWithAlias(imageName),
)
if disk != nil {
defer func() {
_ = disk.Remove()
}()
}
if err != nil {
t.Fatal(err)
}
assertCanUploadDiskImage(t, helper, disk)
}