Skip to content

Commit cdcee82

Browse files
committed
host-device: Return interface name in result
Signed-off-by: Sriram Yagnaraman <sriram.yagnaraman@ericsson.com>
1 parent 6e7fb60 commit cdcee82

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

plugins/main/host-device/host-device.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func cmdAdd(args *skel.CmdArgs) error {
131131
defer containerNs.Close()
132132

133133
result := &current.Result{}
134+
result.Interfaces = []*current.Interface{{
135+
Name: args.IfName,
136+
Sandbox: containerNs.Path(),
137+
}}
138+
134139
var contDev netlink.Link
135140
if !cfg.DPDKMode {
136141
hostDev, err := getLink(cfg.Device, cfg.HWAddr, cfg.KernelPath, cfg.PCIAddr, cfg.auxDevice)
@@ -143,11 +148,10 @@ func cmdAdd(args *skel.CmdArgs) error {
143148
return fmt.Errorf("failed to move link %v", err)
144149
}
145150

146-
result.Interfaces = []*current.Interface{{
147-
Name: contDev.Attrs().Name,
148-
Mac: contDev.Attrs().HardwareAddr.String(),
149-
Sandbox: containerNs.Path(),
150-
}}
151+
// Override the device name with the name in the container namespace
152+
result.Interfaces[0].Name = contDev.Attrs().Name
153+
// Set the MAC address of the interface
154+
result.Interfaces[0].Mac = contDev.Attrs().HardwareAddr.String()
151155
}
152156

153157
if cfg.IPAM.Type == "" {

plugins/main/host-device/host-device_test.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func buildOneConfig(name, cniVersion string, orig *Net, prevResult types.Result)
218218

219219
type tester interface {
220220
expectInterfaces(result types.Result, name, mac, sandbox string)
221-
expectDpdkInterfaceIP(result types.Result, ipAddress string)
221+
expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string)
222222
}
223223

224224
type testerBase struct{}
@@ -256,11 +256,16 @@ func (t *testerV10x) expectInterfaces(result types.Result, name, mac, sandbox st
256256
}))
257257
}
258258

259-
func (t *testerV10x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
259+
func (t *testerV10x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
260260
// check that the result was sane
261261
res, err := types100.NewResultFromResult(result)
262262
Expect(err).NotTo(HaveOccurred())
263-
Expect(res.Interfaces).To(BeEmpty())
263+
Expect(res.Interfaces).To(Equal([]*types100.Interface{
264+
{
265+
Name: name,
266+
Sandbox: sandbox,
267+
},
268+
}))
264269
Expect(res.IPs).To(HaveLen(1))
265270
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
266271
}
@@ -278,11 +283,16 @@ func (t *testerV04x) expectInterfaces(result types.Result, name, mac, sandbox st
278283
}))
279284
}
280285

281-
func (t *testerV04x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
286+
func (t *testerV04x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
282287
// check that the result was sane
283288
res, err := types040.NewResultFromResult(result)
284289
Expect(err).NotTo(HaveOccurred())
285-
Expect(res.Interfaces).To(BeEmpty())
290+
Expect(res.Interfaces).To(Equal([]*types100.Interface{
291+
{
292+
Name: name,
293+
Sandbox: sandbox,
294+
},
295+
}))
286296
Expect(res.IPs).To(HaveLen(1))
287297
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
288298
}
@@ -300,11 +310,16 @@ func (t *testerV03x) expectInterfaces(result types.Result, name, mac, sandbox st
300310
}))
301311
}
302312

303-
func (t *testerV03x) expectDpdkInterfaceIP(result types.Result, ipAddress string) {
313+
func (t *testerV03x) expectDpdkInterfaceIP(result types.Result, name, sandbox, ipAddress string) {
304314
// check that the result was sane
305315
res, err := types040.NewResultFromResult(result)
306316
Expect(err).NotTo(HaveOccurred())
307-
Expect(res.Interfaces).To(BeEmpty())
317+
Expect(res.Interfaces).To(Equal([]*types100.Interface{
318+
{
319+
Name: name,
320+
Sandbox: sandbox,
321+
},
322+
}))
308323
Expect(res.IPs).To(HaveLen(1))
309324
Expect(res.IPs[0].Address.String()).To(Equal(ipAddress))
310325
}
@@ -598,7 +613,7 @@ var _ = Describe("base functionality", func() {
598613

599614
// check that the result was sane
600615
t := newTesterByVersion(ver)
601-
t.expectDpdkInterfaceIP(resI, targetIP)
616+
t.expectDpdkInterfaceIP(resI, cniName, targetNS.Path(), targetIP)
602617

603618
// call CmdDel
604619
_ = originalNS.Do(func(ns.NetNS) error {
@@ -870,7 +885,7 @@ var _ = Describe("base functionality", func() {
870885

871886
// check that the result was sane
872887
t := newTesterByVersion(ver)
873-
t.expectDpdkInterfaceIP(resI, targetIP)
888+
t.expectDpdkInterfaceIP(resI, cniName, targetNS.Path(), targetIP)
874889

875890
// call CmdCheck
876891
n := &Net{}

0 commit comments

Comments
 (0)