Skip to content

Commit

Permalink
This PR fixes oVirt#82 and check that vnic doesn't has same network
Browse files Browse the repository at this point in the history
  • Loading branch information
mgold1234 committed Feb 10, 2022
1 parent 8f13077 commit 9f00269
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
23 changes: 16 additions & 7 deletions client_nic_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestDuplicateVMNICCreationWithSameName(t *testing.T) {
assertNICCount(t, vm, 0)
}

func TestDuplicateVMNICCreationWithSameNameAndDiffNetwork(t *testing.T) {
func TestDuplicateVMNICCreationWithSameNameAndDiffVNICProfile(t *testing.T) {
t.Parallel()
helper := getHelper(t)
nicName := "test_duplicate_name"
Expand All @@ -79,12 +79,21 @@ func TestDuplicateVMNICCreationWithSameNameAndDiffNetwork(t *testing.T) {
ovirtclient.CreateNICParams())
assertNICCount(t, vm, 1)
DiffVNICProfile, _ := assertCanFindDiffVNICProfile(helper, helper.GetVNICProfileID())
assertCannotCreateNICWithSameNameDiffNetwork(
t,
vm,
nicName,
DiffVNICProfile,
ovirtclient.CreateNICParams())
if DiffVNICProfile == "" {
assertCannotCreateNICWithSameName(
t,
helper,
vm,
nicName,
ovirtclient.CreateNICParams())
} else {
assertCannotCreateNICWithVNICProfile(
t,
vm,
nicName,
DiffVNICProfile,
ovirtclient.CreateNICParams())
}
assertNICCount(t, vm, 1)
assertCanRemoveNIC(t, nic1)
assertNICCount(t, vm, 0)
Expand Down
13 changes: 7 additions & 6 deletions client_nic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ func assertCannotCreateNICWithSameName(
name string,
params ovirtclient.BuildableNICParameters,
) {
nic, _ := vm.CreateNIC(name, helper.GetVNICProfileID(), params)
if nic != nil {

_, err := vm.CreateNIC(name, helper.GetVNICProfileID(), params)
if err == nil {
t.Fatalf("create 2 NICs with same name %s", name)
}
}

func assertCannotCreateNICWithSameNameDiffNetwork(
func assertCannotCreateNICWithVNICProfile(
t *testing.T,
vm ovirtclient.VM,
name string,
diffVNICProfile string,
params ovirtclient.BuildableNICParameters,
) {
nic, _ := vm.CreateNIC(name, diffVNICProfile, params)
if nic != nil {
t.Fatalf("create 2 NICs with same name %s", name)
_, err := vm.CreateNIC(name, diffVNICProfile, params)
if err == nil {
t.Fatalf("create 2 NICs with same name %s and different VNICProfile (%v)", name, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion client_vnicprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,5 @@ func assertCanFindDiffVNICProfile(helper ovirtclient.TestHelper, vnicProfileID s
return vnicID, nil
}
}
return vnicProfileID, fmt.Errorf("failed to find different VNIC profile ID for testing, use the exiting one")
return "", fmt.Errorf("failed to find different VNIC profile ID for testing, use the exiting one")
}

0 comments on commit 9f00269

Please sign in to comment.