Skip to content

Commit

Permalink
Merge pull request #106 from sunya-ch/v1.0.4
Browse files Browse the repository at this point in the history
Make sure execPlugin execute regardless of ipam return
  • Loading branch information
sunya-ch authored May 15, 2023
2 parents 18ff99b + ca7fdd8 commit ea62b6d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 24 deletions.
37 changes: 16 additions & 21 deletions cni/plugins/main/multi-nic/multi-nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func cmdDel(args *skel.CmdArgs) error {
}

n, deviceType, err := loadConf(args)
if err != nil {
if err != nil && n == nil {
utils.Logger.Debug(fmt.Sprintf("fail to load conf: %v", err))
return nil
}
Expand All @@ -192,7 +192,6 @@ func cmdDel(args *skel.CmdArgs) error {
err = ipam.ExecDel(n.IPAM.Type, injectedStdIn)
if err != nil {
utils.Logger.Debug(fmt.Sprintf("Failed ipam.ExecDel %s: %v", err, string(injectedStdIn)))
return nil
}
}

Expand All @@ -201,14 +200,14 @@ func cmdDel(args *skel.CmdArgs) error {
if n.NetConf.RawPrevResult != nil {
if err = version.ParsePrevResult(&n.NetConf); err != nil {
utils.Logger.Debug(fmt.Sprintf("could not parse prevResult: %v", err))
return nil
}
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
if err != nil {
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
return nil
} else {
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
if err != nil {
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
}
}
} else {
}
if result == nil {
result = &current.Result{CNIVersion: current.ImplementedSpecVersion}
}

Expand All @@ -224,7 +223,6 @@ func cmdDel(args *skel.CmdArgs) error {
}
if err != nil {
utils.Logger.Debug(fmt.Sprintf("Fail loading %v: %v", string(args.StdinData), err))
return nil
}
if len(confBytesArray) == 0 {
utils.Logger.Debug(fmt.Sprintf("zero config on cmdDel: %v (%d)", string(args.StdinData), len(n.Masters)))
Expand All @@ -237,7 +235,6 @@ func cmdDel(args *skel.CmdArgs) error {
_, err := execPlugin(deviceType, command, confBytes, args, ifName, false)
if err != nil {
utils.Logger.Debug(fmt.Sprintf("Fail execPlugin %v: %v", string(confBytes), err))
return nil
}
}
return nil
Expand All @@ -249,7 +246,7 @@ func cmdCheck(args *skel.CmdArgs) error {
}

n, deviceType, err := loadConf(args)
if err != nil {
if err != nil && n == nil {
utils.Logger.Debug(fmt.Sprintf("fail to load conf: %v", err))
return nil
}
Expand All @@ -259,14 +256,14 @@ func cmdCheck(args *skel.CmdArgs) error {
if n.NetConf.RawPrevResult != nil {
if err = version.ParsePrevResult(&n.NetConf); err != nil {
utils.Logger.Debug(fmt.Sprintf("could not parse prevResult: %v", err))
return nil
}
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
if err != nil {
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
return nil
} else {
result, err = current.NewResultFromResult(n.NetConf.PrevResult)
if err != nil {
utils.Logger.Debug(fmt.Sprintf("could not convert result to current version: %v", err))
}
}
} else {
}
if result == nil {
result = &current.Result{CNIVersion: current.ImplementedSpecVersion}
}

Expand All @@ -282,7 +279,6 @@ func cmdCheck(args *skel.CmdArgs) error {
}
if err != nil {
utils.Logger.Debug(fmt.Sprintf("Fail loading %v: %v", string(args.StdinData), err))
return nil
}
if len(confBytesArray) == 0 {
utils.Logger.Debug(fmt.Sprintf("zero config on cmdCheck: %v (%d)", string(args.StdinData), len(n.Masters)))
Expand All @@ -295,7 +291,6 @@ func cmdCheck(args *skel.CmdArgs) error {
_, err := execPlugin(deviceType, command, confBytes, args, ifName, false)
if err != nil {
utils.Logger.Debug(fmt.Sprintf("Fail execPlugin %v: %v", string(confBytes), err))
return nil
}
}
return nil
Expand Down
36 changes: 33 additions & 3 deletions cni/plugins/main/multi-nic/multi-nic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ func buildOneConfig(cniVersion string, orig *NetConf, prevResult types.Result) (

}

func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
log.Printf("multinicAddCheckDelTest")
log.Printf("%s", conf)
func multinicAddTest(conf, masterName string, originalNS, targetNS ns.NetNS) types.Result {
log.Printf("Add %s", conf)
// Unmarshal to pull out CNI spec version
rawConfig := make(map[string]interface{})
err := json.Unmarshal([]byte(conf), &rawConfig)
Expand Down Expand Up @@ -176,6 +175,23 @@ func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.Ne
return nil
})
Expect(err).NotTo(HaveOccurred())
return result
}

func multinicCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS, result types.Result) {
log.Printf("CheckDel %s", conf)
// Unmarshal to pull out CNI spec version
rawConfig := make(map[string]interface{})
err := json.Unmarshal([]byte(conf), &rawConfig)
Expect(err).NotTo(HaveOccurred())
cniVersion := rawConfig["cniVersion"].(string)

args := &skel.CmdArgs{
ContainerID: "dummy",
Netns: targetNS.Path(),
IfName: "net1",
StdinData: []byte(conf),
}

n := &NetConf{}
err = json.Unmarshal([]byte(conf), &n)
Expand Down Expand Up @@ -228,6 +244,19 @@ func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.Ne
Expect(err).NotTo(HaveOccurred())
}

func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
log.Printf("multinicAddCheckDelTest")
result := multinicAddTest(conf, masterName, originalNS, targetNS)
multinicCheckDelTest(conf, masterName, originalNS, targetNS, result)
}

func multinicDelWithoutDaemonTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
log.Printf("multinicDelWithoutDaemonTest")
result := multinicAddTest(conf, masterName, originalNS, targetNS)
confWithoutDaemon := strings.ReplaceAll(conf, BRIDGE_HOST_IP, "")
multinicCheckDelTest(confWithoutDaemon, masterName, originalNS, targetNS, result)
}

type tester interface {
// verifyResult minimally verifies the Result and returns the interface's MAC address
verifyResult(result types.Result, name string) string
Expand Down Expand Up @@ -405,6 +434,7 @@ var _ = Describe("Operations", func() {
`, BRIDGE_HOST_IP, daemonPort)
conf := getConfig(ver, multiNICIPAM, masterNets)
multinicAddCheckDelTest(conf, "", originalNS, targetNS)
multinicDelWithoutDaemonTest(conf, "", originalNS, targetNS)
})
It(fmt.Sprintf("[%s] configures and deconfigures link with ADD/DEL (single-nic IPAM)", ver), func() {
conf := getConfig(ver, singleNICIPAM, masterNets)
Expand Down

0 comments on commit ea62b6d

Please sign in to comment.