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 11, 2022
1 parent 0fbd0c1 commit 8d94d81
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
23 changes: 7 additions & 16 deletions client_nic_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,13 @@ func TestDuplicateVMNICCreationWithSameNameDiffVNICProfileSameNetwork(t *testing
nicName,
ovirtclient.CreateNICParams())
assertNICCount(t, vm, 1)
DiffVNICProfileSameNetwork, _ := assertCanFindDiffVNICProfileSameNetwork(helper, helper.GetVNICProfileID())
if DiffVNICProfileSameNetwork == "" {
assertCannotCreateNICWithSameName(
t,
helper,
vm,
nicName,
ovirtclient.CreateNICParams())
} else {
assertCannotCreateNICWithVNICProfile(
t,
vm,
nicName,
DiffVNICProfileSameNetwork,
ovirtclient.CreateNICParams())
}
DiffVNICProfileSameNetwork, _ := assertCanFindDiffVNICProfileSameNetwork(t, helper, helper.GetVNICProfileID())
assertCannotCreateNICWithVNICProfile(
t,
vm,
nicName,
DiffVNICProfileSameNetwork,
ovirtclient.CreateNICParams())
assertNICCount(t, vm, 1)
assertCanRemoveNIC(t, nic1)
assertNICCount(t, vm, 0)
Expand Down
15 changes: 4 additions & 11 deletions client_vnicprofile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,15 @@ func assertCanFindDiffVNICProfileDiffNetwork(helper ovirtclient.TestHelper, vnic
"failed to find different VNIC profile ID and Different Network for testing, use the exiting one")
}

func assertCanFindDiffVNICProfileSameNetwork(helper ovirtclient.TestHelper, vnicProfileID string) (string, error) {
func assertCanFindDiffVNICProfileSameNetwork(t *testing.T, helper ovirtclient.TestHelper, vnicProfileID string) (string, error) {
client := helper.GetClient()
newVNICProfile := assertCanCreateVNICProfile(t, helper)
existVNICProfile, err := client.GetVNICProfile(vnicProfileID)
if err != nil {
return "", fmt.Errorf("failed to verify VNIC profile ID %s", vnicProfileID)
}
networkID := existVNICProfile.NetworkID()
vnicProfiles, err := client.ListVNICProfiles()
if err != nil {
return "", fmt.Errorf("failed to list VNIC profiles (%w)", err)
}
for _, vnicProfile := range vnicProfiles {
vnicID := vnicProfile.ID()
if vnicID != vnicProfileID && vnicProfile.NetworkID() == networkID {
return vnicID, nil
}
if newVNICProfile.NetworkID() == existVNICProfile.NetworkID() {
return newVNICProfile.ID(), nil
}
return "", fmt.Errorf(
"failed to find different VNIC profile ID and same Network for testing, use the exiting one")
Expand Down

0 comments on commit 8d94d81

Please sign in to comment.