host-device: Return interface name in result

Signed-off-by: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
This commit is contained in:
Sriram Yagnaraman
2025-02-20 13:41:38 +01:00
committed by Casey Callendrello
parent 44ec80b7cc
commit bd8da2000a
2 changed files with 33 additions and 14 deletions

View File

@@ -131,6 +131,11 @@ func cmdAdd(args *skel.CmdArgs) error {
defer containerNs.Close()
result := &current.Result{}
result.Interfaces = []*current.Interface{{
Name: args.IfName,
Sandbox: containerNs.Path(),
}}
var contDev netlink.Link
if !cfg.DPDKMode {
hostDev, err := getLink(cfg.Device, cfg.HWAddr, cfg.KernelPath, cfg.PCIAddr, cfg.auxDevice)
@@ -143,11 +148,10 @@ func cmdAdd(args *skel.CmdArgs) error {
return fmt.Errorf("failed to move link %v", err)
}
result.Interfaces = []*current.Interface{{
Name: contDev.Attrs().Name,
Mac: contDev.Attrs().HardwareAddr.String(),
Sandbox: containerNs.Path(),
}}
// Override the device name with the name in the container namespace
result.Interfaces[0].Name = contDev.Attrs().Name
// Set the MAC address of the interface
result.Interfaces[0].Mac = contDev.Attrs().HardwareAddr.String()
}
if cfg.IPAM.Type == "" {

View File

@@ -218,7 +218,7 @@ func buildOneConfig(name, cniVersion string, orig *Net, prevResult types.Result)
type tester interface {
expectInterfaces(result types.Result, name, mac, sandbox string)
expectDpdkInterfaceIP(result types.Result, ipAddress string)
expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string)
}
type testerBase struct{}
@@ -256,11 +256,16 @@ func (t *testerV10x) expectInterfaces(result types.Result, name, mac, sandbox st
}))
}
func (t *testerV10x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
func (t *testerV10x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
// check that the result was sane
res, err := types100.NewResultFromResult(result)
Expect(err).NotTo(HaveOccurred())
Expect(res.Interfaces).To(BeEmpty())
Expect(res.Interfaces).To(Equal([]*types100.Interface{
{
Name: name,
Sandbox: sandbox,
},
}))
Expect(res.IPs).To(HaveLen(1))
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
}
@@ -278,11 +283,16 @@ func (t *testerV04x) expectInterfaces(result types.Result, name, mac, sandbox st
}))
}
func (t *testerV04x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
func (t *testerV04x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
// check that the result was sane
res, err := types040.NewResultFromResult(result)
Expect(err).NotTo(HaveOccurred())
Expect(res.Interfaces).To(BeEmpty())
Expect(res.Interfaces).To(Equal([]*types040.Interface{
{
Name: name,
Sandbox: sandbox,
},
}))
Expect(res.IPs).To(HaveLen(1))
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
}
@@ -300,11 +310,16 @@ func (t *testerV03x) expectInterfaces(result types.Result, name, mac, sandbox st
}))
}
func (t *testerV03x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
func (t *testerV03x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
// check that the result was sane
res, err := types040.NewResultFromResult(result)
Expect(err).NotTo(HaveOccurred())
Expect(res.Interfaces).To(BeEmpty())
Expect(res.Interfaces).To(Equal([]*types040.Interface{
{
Name: name,
Sandbox: sandbox,
},
}))
Expect(res.IPs).To(HaveLen(1))
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
}
@@ -598,7 +613,7 @@ var _ = Describe("base functionality", func() {
// check that the result was sane
t := newTesterByVersion(ver)
t.expectDpdkInterfaceIP(resI, targetIP)
t.expectDpdkInterfaceIP(resI, cniName, targetNS.Path(), targetIP)
// call CmdDel
_ = originalNS.Do(func(ns.NetNS) error {
@@ -870,7 +885,7 @@ var _ = Describe("base functionality", func() {
// check that the result was sane
t := newTesterByVersion(ver)
t.expectDpdkInterfaceIP(resI, targetIP)
t.expectDpdkInterfaceIP(resI, cniName, targetNS.Path(), targetIP)
// call CmdCheck
n := &Net{}