Skip to content

Commit ca7fdd8

Browse files
committed
add cmdCheckDel test without daemon
Signed-off-by: Sunyanan Choochotkaew <sunyanan.choochotkaew1@ibm.com>
1 parent 3c10291 commit ca7fdd8

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

cni/plugins/main/multi-nic/multi-nic_test.go

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ func buildOneConfig(cniVersion string, orig *NetConf, prevResult types.Result) (
125125

126126
}
127127

128-
func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
129-
log.Printf("multinicAddCheckDelTest")
130-
log.Printf("%s", conf)
128+
func multinicAddTest(conf, masterName string, originalNS, targetNS ns.NetNS) types.Result {
129+
log.Printf("Add %s", conf)
131130
// Unmarshal to pull out CNI spec version
132131
rawConfig := make(map[string]interface{})
133132
err := json.Unmarshal([]byte(conf), &rawConfig)
@@ -176,6 +175,23 @@ func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.Ne
176175
return nil
177176
})
178177
Expect(err).NotTo(HaveOccurred())
178+
return result
179+
}
180+
181+
func multinicCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS, result types.Result) {
182+
log.Printf("CheckDel %s", conf)
183+
// Unmarshal to pull out CNI spec version
184+
rawConfig := make(map[string]interface{})
185+
err := json.Unmarshal([]byte(conf), &rawConfig)
186+
Expect(err).NotTo(HaveOccurred())
187+
cniVersion := rawConfig["cniVersion"].(string)
188+
189+
args := &skel.CmdArgs{
190+
ContainerID: "dummy",
191+
Netns: targetNS.Path(),
192+
IfName: "net1",
193+
StdinData: []byte(conf),
194+
}
179195

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

247+
func multinicAddCheckDelTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
248+
log.Printf("multinicAddCheckDelTest")
249+
result := multinicAddTest(conf, masterName, originalNS, targetNS)
250+
multinicCheckDelTest(conf, masterName, originalNS, targetNS, result)
251+
}
252+
253+
func multinicDelWithoutDaemonTest(conf, masterName string, originalNS, targetNS ns.NetNS) {
254+
log.Printf("multinicDelWithoutDaemonTest")
255+
result := multinicAddTest(conf, masterName, originalNS, targetNS)
256+
confWithoutDaemon := strings.ReplaceAll(conf, BRIDGE_HOST_IP, "")
257+
multinicCheckDelTest(confWithoutDaemon, masterName, originalNS, targetNS, result)
258+
}
259+
231260
type tester interface {
232261
// verifyResult minimally verifies the Result and returns the interface's MAC address
233262
verifyResult(result types.Result, name string) string
@@ -405,6 +434,7 @@ var _ = Describe("Operations", func() {
405434
`, BRIDGE_HOST_IP, daemonPort)
406435
conf := getConfig(ver, multiNICIPAM, masterNets)
407436
multinicAddCheckDelTest(conf, "", originalNS, targetNS)
437+
multinicDelWithoutDaemonTest(conf, "", originalNS, targetNS)
408438
})
409439
It(fmt.Sprintf("[%s] configures and deconfigures link with ADD/DEL (single-nic IPAM)", ver), func() {
410440
conf := getConfig(ver, singleNICIPAM, masterNets)

0 commit comments

Comments
 (0)