Skip to content

Commit 2cbd5b5

Browse files
committed
Unit test for renderDevicePluginConfigData partitions
Signed-off-by: Andrea Panattoni <apanatto@redhat.com>
1 parent 8363b95 commit 2cbd5b5

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

controllers/sriovnetworknodepolicy_controller_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,5 +618,61 @@ var _ = Describe("SriovNetworkNodePolicyReconciler", Ordered, func() {
618618
// Having drivers in the selector cause the device plugin to fail to select the mellanox devices in the mlxNode
619619
Expect(selectors.Drivers).To(BeEmpty())
620620
})
621+
622+
It("should render device plugin config data when policies configure vfio-pci and netdevice", func() {
623+
node1 := &corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "node1", Labels: map[string]string{"node-role.kubernetes.io/worker": ""}}}
624+
objs := []client.Object{
625+
node1,
626+
&sriovnetworkv1.SriovNetworkNodeState{ObjectMeta: metav1.ObjectMeta{Name: "node1", Namespace: testNamespace}, Status: sriovnetworkv1.SriovNetworkNodeStateStatus{
627+
Interfaces: sriovnetworkv1.InterfaceExts{
628+
{Driver: "ice", DeviceID: "159b", Vendor: "8086", PciAddress: "0000:31:00.0", Name: "ens0"},
629+
},
630+
}},
631+
}
632+
633+
r := &SriovNetworkNodePolicyReconciler{Client: fake.NewClientBuilder().WithObjects(objs...).Build()}
634+
635+
pl := &sriovnetworkv1.SriovNetworkNodePolicyList{
636+
Items: []sriovnetworkv1.SriovNetworkNodePolicy{
637+
{
638+
ObjectMeta: metav1.ObjectMeta{Name: "intel-vfio-pci"},
639+
Spec: sriovnetworkv1.SriovNetworkNodePolicySpec{
640+
ResourceName: "resvfiopci",
641+
DeviceType: "vfio-pci",
642+
NicSelector: sriovnetworkv1.SriovNetworkNicSelector{
643+
Vendor: "8086",
644+
DeviceID: "159b",
645+
PfNames: []string{"ens0#0-9"},
646+
},
647+
NumVfs: 128,
648+
NodeSelector: map[string]string{"node-role.kubernetes.io/worker": ""},
649+
},
650+
},
651+
{
652+
ObjectMeta: metav1.ObjectMeta{Name: "mellanox-rdma"},
653+
Spec: sriovnetworkv1.SriovNetworkNodePolicySpec{
654+
ResourceName: "resnetdevice",
655+
DeviceType: "netdevice",
656+
NicSelector: sriovnetworkv1.SriovNetworkNicSelector{
657+
Vendor: "8086",
658+
DeviceID: "159b",
659+
PfNames: []string{"ens0#10-19"},
660+
},
661+
NumVfs: 128,
662+
NodeSelector: map[string]string{"node-role.kubernetes.io/worker": ""},
663+
},
664+
},
665+
},
666+
}
667+
rcl, err := r.renderDevicePluginConfigData(context.Background(), pl, node1)
668+
Expect(err).ToNot(HaveOccurred())
669+
Expect(len(rcl.ResourceList)).To(Equal(2))
670+
selectors := map[string]string{
671+
rcl.ResourceList[0].ResourceName: string(*rcl.ResourceList[0].Selectors),
672+
rcl.ResourceList[1].ResourceName: string(*rcl.ResourceList[1].Selectors),
673+
}
674+
Expect(selectors).To(HaveKeyWithValue("resvfiopci", `{"vendors":["8086"],"pfNames":["ens0#0-9"],"IsRdma":false,"NeedVhostNet":false}`))
675+
Expect(selectors).To(HaveKeyWithValue("resnetdevice", `{"vendors":["8086"],"pfNames":["ens0#10-19"],"IsRdma":false,"NeedVhostNet":false}`))
676+
})
621677
})
622678
})

0 commit comments

Comments
 (0)