From dfb53291d3cf9226499439649a12ba7d07501798 Mon Sep 17 00:00:00 2001 From: Quan Tian Date: Wed, 15 Jan 2020 00:27:08 +0800 Subject: [PATCH] Fix vlan plugin returning error when device is already removed DEL can be called multiple times, vlan plugin should return no error if the device is already removed. --- plugins/main/vlan/vlan.go | 2 +- plugins/main/vlan/vlan_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/main/vlan/vlan.go b/plugins/main/vlan/vlan.go index 8f4240697..5a19a6e1a 100644 --- a/plugins/main/vlan/vlan.go +++ b/plugins/main/vlan/vlan.go @@ -207,7 +207,7 @@ func cmdDel(args *skel.CmdArgs) error { err = ns.WithNetNSPath(args.Netns, func(_ ns.NetNS) error { err = ip.DelLinkByName(args.IfName) - if err != nil && err != ip.ErrLinkNotFound { + if err != nil && err == ip.ErrLinkNotFound { return nil } return err diff --git a/plugins/main/vlan/vlan_test.go b/plugins/main/vlan/vlan_test.go index 17e4f39df..01b7a7344 100644 --- a/plugins/main/vlan/vlan_test.go +++ b/plugins/main/vlan/vlan_test.go @@ -292,6 +292,19 @@ var _ = Describe("vlan Operations", func() { return nil }) Expect(err).NotTo(HaveOccurred()) + + // DEL can be called multiple times, make sure no error is returned + // if the device is already removed. + err = originalNS.Do(func(ns.NetNS) error { + defer GinkgoRecover() + + err = testutils.CmdDelWithArgs(args, func() error { + return cmdDel(args) + }) + Expect(err).NotTo(HaveOccurred()) + return nil + }) + Expect(err).NotTo(HaveOccurred()) }) It("configures and deconfigures an CNI V4 vlan link with ADD/CHECK/DEL", func() {