forked from oVirt/go-ovirt-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_nic_test.go
75 lines (67 loc) · 2 KB
/
client_nic_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
package ovirtclient_test
import (
"testing"
ovirtclient "github.com/ovirt/go-ovirt-client"
)
func assertCanUpdateNICName(t *testing.T, nic ovirtclient.NIC, name string) ovirtclient.NIC {
newNIC, err := nic.Update(ovirtclient.UpdateNICParams().MustWithName(name))
if err != nil {
t.Fatalf("failed to update NIC (%v)", err)
}
if newNIC.Name() != name {
t.Fatalf("NIC name not changed after update call")
}
return newNIC
}
func assertCanCreateNIC(
t *testing.T,
helper ovirtclient.TestHelper,
vm ovirtclient.VM,
name string,
params ovirtclient.BuildableNICParameters,
) ovirtclient.NIC {
nic, err := vm.CreateNIC(name, helper.GetVNICProfileID(), params)
if err != nil {
t.Fatalf("failed to create NIC on VM %s", vm.ID())
}
if nic.VMID() != vm.ID() {
t.Fatalf("VM ID mismatch between NIC and VM (%s != %s)", nic.VMID(), vm.ID())
}
return nic
}
func assertCannotCreateNIC(
t *testing.T,
helper ovirtclient.TestHelper,
vm ovirtclient.VM,
name string,
params ovirtclient.BuildableNICParameters,
) {
nic, _ := vm.CreateNIC(name, helper.GetVNICProfileID(), params)
if nic != nil {
t.Fatalf("create 2 NICs with same name %s", name)
}
}
func assertCanRemoveNIC(t *testing.T, nic ovirtclient.NIC) {
if err := nic.Remove(); err != nil {
t.Fatalf("failed to remove NIC %s (%v)", nic.ID(), err)
}
}
func assertNICCount(t *testing.T, vm ovirtclient.VM, n int) {
nics, err := vm.ListNICs()
if err != nil {
t.Fatalf("failed to list NICs on VM %s", vm.ID())
}
if len(nics) != n {
t.Fatalf("unexpected number of NICs after NIC removal on VM %s: %d instead of %d", vm.ID(), len(nics), n)
}
}
func assertCanUpdateNICVNICProfile(t *testing.T, nic ovirtclient.NIC, vnicProfileID string) ovirtclient.NIC {
newNIC, err := nic.Update(ovirtclient.UpdateNICParams().MustWithVNICProfileID(vnicProfileID))
if err != nil {
t.Fatalf("failed to update NIC with new VNIC profile ID (%v)", err)
}
if newNIC.VNICProfileID() != vnicProfileID {
t.Fatalf("VNIC profile ID not changed after update")
}
return newNIC
}