Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Using pod network type as default when type is missing in the resource mapping #303

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/functional-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
## Basic Net VM
| Test description | Implemented |
| :---------------- | :-----------: |
| Networked VM import should create started VM | ✓ |
| Networked VM import should create started VM with pod network when type in network resource mapping is 'pod' | ✓ |
| Networked VM import should create started VM with pod network when type in network resource mapping is missing (nil) | ✓ |

### Multiple VMs import
| Test description | Implemented |
Expand Down Expand Up @@ -101,6 +102,7 @@
| :---------------- | :---------:
| Import with missing network resource mapping should be blocked | ✓ |
| Import with network mapping to a non-existing target network should be blocked | ✓ |
| Import with network mapping to unsupported target type should be blocked | ✓ |
| Import with storage mapping to a non-existing target storage class should be blocked | ✓ |
| Import with disk mapping to a non-existing target storage class should be blocked | ✓ |

Expand Down
2 changes: 1 addition & 1 deletion pkg/providers/ovirt/mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func (o *OvirtMapper) getNetworkForNic(vnicProfile *ovirtsdk.VnicProfile) kubevi
}

func (o *OvirtMapper) mapNetworkType(mapping v2vv1alpha1.ResourceMappingItem, kubevirtNet *kubevirtv1.Network) {
if *mapping.Type == networkTypePod {
if mapping.Type == nil || *mapping.Type == networkTypePod {
kubevirtNet.Pod = &kubevirtv1.PodNetwork{}
} else if *mapping.Type == networkTypeMultus {
kubevirtNet.Multus = &kubevirtv1.MultusNetwork{
Expand Down
2 changes: 2 additions & 0 deletions tests/common-vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ var (
PodType = "pod"
// MultusType defines `pod` resource mapping network type
MultusType = "multus"
// UnsupportedType defines non-existing, unsupported `unsupported resource mapping network type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jakub-dzon should the second "`unsupported" be removed from the description ? also there is a missing comma.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second "unsupported" is the the value used as unsupported type:) I will fix the missing punctuation mark.

UnsupportedType = "unsupported"
)
50 changes: 27 additions & 23 deletions tests/ovirt/basic_net_vm_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import (
"github.com/kubevirt/vm-import-operator/tests/utils"
sapi "github.com/machacekondra/fakeovirt/pkg/api/stubbing"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "kubevirt.io/client-go/api/v1"
)

type networkedVmImportTest struct {
type networkedVMImportTest struct {
framework *fwk.Framework
}

Expand All @@ -24,7 +25,7 @@ var _ = Describe("Networked VM import ", func() {
f = fwk.NewFrameworkOrDie("networked-vm-import")
secret corev1.Secret
namespace string
test = networkedVmImportTest{framework: f}
test = networkedVMImportTest{framework: f}
)

BeforeEach(func() {
Expand All @@ -36,12 +37,12 @@ var _ = Describe("Networked VM import ", func() {
secret = s
})

It("should create started VM", func() {
table.DescribeTable("should create started VM with pod network", func(networkType *string) {
vmID := vms.BasicVmID
vmi := utils.VirtualMachineImportCr(vmID, namespace, secret.Name, f.NsPrefix, true)
vmi.Spec.Source.Ovirt.Mappings = &v2vv1alpha1.OvirtMappings{
NetworkMappings: &[]v2vv1alpha1.ResourceMappingItem{
{Source: v2vv1alpha1.Source{ID: &vms.VNicProfile1ID}, Type: &tests.PodType},
{Source: v2vv1alpha1.Source{ID: &vms.VNicProfile1ID}, Type: networkType},
},
}
test.stub(vmID)
Expand All @@ -58,10 +59,13 @@ var _ = Describe("Networked VM import ", func() {

vm := test.validateTargetConfiguration(vmBlueprint.Name)
Expect(vm.Spec.Template.Spec.Volumes[0].DataVolume.Name).To(HaveDefaultStorageClass(f))
})
},
table.Entry("when type in network resource mapping is 'pod'", &tests.PodType),
table.Entry("when type in network resource mapping is missing (nil)", nil),
)
})

func (t *networkedVmImportTest) validateTargetConfiguration(vmName string) *v1.VirtualMachine {
func (t *networkedVMImportTest) validateTargetConfiguration(vmName string) *v1.VirtualMachine {
vmNamespace := t.framework.Namespace.Name
vm, _ := t.framework.KubeVirtClient.VirtualMachine(vmNamespace).Get(vmName, &metav1.GetOptions{})
spec := vm.Spec.Template.Spec
Expand Down Expand Up @@ -105,24 +109,24 @@ func (t *networkedVmImportTest) validateTargetConfiguration(vmName string) *v1.V
return vm
}

func (t *networkedVmImportTest) stub(vmID string) {
diskAttachmentsXml := t.framework.LoadFile("disk-attachments/one.xml")
diskXml := t.framework.LoadTemplate("disks/disk-1.xml", map[string]string{"@DISKSIZE": "46137344"})
domainXml := t.framework.LoadFile("storage-domains/domain-1.xml")
consolesXml := t.framework.LoadFile("graphic-consoles/vnc.xml")
networkXml := t.framework.LoadFile("networks/net-1.xml")
vnicProfileXml := t.framework.LoadFile("vnic-profiles/vnic-profile-1.xml")
vmXml := t.framework.LoadTemplate("vms/basic-vm.xml", map[string]string{"@VMID": vmID})
nicsXml := t.framework.LoadFile("nics/one.xml")
func (t *networkedVMImportTest) stub(vmID string) {
diskAttachmentsXML := t.framework.LoadFile("disk-attachments/one.xml")
diskXML := t.framework.LoadTemplate("disks/disk-1.xml", map[string]string{"@DISKSIZE": "46137344"})
domainXML := t.framework.LoadFile("storage-domains/domain-1.xml")
consolesXML := t.framework.LoadFile("graphic-consoles/vnc.xml")
networkXML := t.framework.LoadFile("networks/net-1.xml")
vnicProfileXML := t.framework.LoadFile("vnic-profiles/vnic-profile-1.xml")
vmXML := t.framework.LoadTemplate("vms/basic-vm.xml", map[string]string{"@VMID": vmID})
nicsXML := t.framework.LoadFile("nics/one.xml")
builder := sapi.NewStubbingBuilder().
StubGet("/ovirt-engine/api/vms/"+vmID+"/diskattachments", &diskAttachmentsXml).
StubGet("/ovirt-engine/api/vms/"+vmID+"/graphicsconsoles", &consolesXml).
StubGet("/ovirt-engine/api/vms/"+vmID+"/nics", &nicsXml).
StubGet("/ovirt-engine/api/disks/disk-1", &diskXml).
StubGet("/ovirt-engine/api/networks/net-1", &networkXml).
StubGet("/ovirt-engine/api/vnicprofiles/vnic-profile-1", &vnicProfileXml).
StubGet("/ovirt-engine/api/storagedomains/domain-1", &domainXml).
StubGet("/ovirt-engine/api/vms/"+vmID, &vmXml)
StubGet("/ovirt-engine/api/vms/"+vmID+"/diskattachments", &diskAttachmentsXML).
StubGet("/ovirt-engine/api/vms/"+vmID+"/graphicsconsoles", &consolesXML).
StubGet("/ovirt-engine/api/vms/"+vmID+"/nics", &nicsXML).
StubGet("/ovirt-engine/api/disks/disk-1", &diskXML).
StubGet("/ovirt-engine/api/networks/net-1", &networkXML).
StubGet("/ovirt-engine/api/vnicprofiles/vnic-profile-1", &vnicProfileXML).
StubGet("/ovirt-engine/api/storagedomains/domain-1", &domainXML).
StubGet("/ovirt-engine/api/vms/"+vmID, &vmXML)
err := t.framework.OvirtStubbingClient.Stub(builder.Build())
if err != nil {
Fail(err.Error())
Expand Down
4 changes: 4 additions & 0 deletions tests/ovirt/resource_mapping_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ var _ = Describe("VM import ", func() {
&[]v2vv1alpha1.ResourceMappingItem{{Source: v2vv1alpha1.Source{ID: &vms.VNicProfile1ID}, Type: &tests.MultusType, Target: v2vv1alpha1.ObjectIdentifier{Name: "no-such-net-attach-def"}}},
nil,
nil),
table.Entry("network mapping to unsupported target type",
&[]v2vv1alpha1.ResourceMappingItem{{Source: v2vv1alpha1.Source{ID: &vms.VNicProfile1ID}, Type: &tests.UnsupportedType, Target: v2vv1alpha1.ObjectIdentifier{Name: "some-network"}}},
nil,
nil),
table.Entry("storage domain mapping to non-existing target storage class",
&[]v2vv1alpha1.ResourceMappingItem{{Source: v2vv1alpha1.Source{ID: &vms.VNicProfile1ID}, Type: &tests.PodType}},
&[]v2vv1alpha1.ResourceMappingItem{{Source: v2vv1alpha1.Source{ID: &vms.StorageDomainID}, Target: v2vv1alpha1.ObjectIdentifier{Name: "no-such-storage-class"}}},
Expand Down