host-device plugin: result is valid JSON

test:
- feed valid config JSON to plugin
- execute plugin inside the namespace with the test device
This commit is contained in:
Gabriel Rosenhouse
2017-09-12 21:01:58 -07:00
parent 25ca6ccb52
commit c238c93b5e
2 changed files with 17 additions and 6 deletions

View File

@ -15,6 +15,9 @@
package main
import (
"fmt"
"math/rand"
"github.com/containernetworking/cni/pkg/skel"
"github.com/containernetworking/plugins/pkg/ns"
"github.com/containernetworking/plugins/pkg/testutils"
@ -23,15 +26,16 @@ import (
"github.com/vishvananda/netlink"
)
var ifname = "dummy0"
var _ = Describe("base functionality", func() {
var originalNS ns.NetNS
var ifname string
BeforeEach(func() {
var err error
originalNS, err = ns.NewNS()
Expect(err).NotTo(HaveOccurred())
ifname = fmt.Sprintf("dummy-%x", rand.Int31())
})
AfterEach(func() {
@ -61,19 +65,23 @@ var _ = Describe("base functionality", func() {
targetNS, err := ns.NewNS()
Expect(err).NotTo(HaveOccurred())
conf := `{
conf := fmt.Sprintf(`{
"cniVersion": "0.3.0",
"name": "cni-plugin-host-device-test",
"type": "host-device",
"device": ifname
}`
"device": %q
}`, ifname)
args := &skel.CmdArgs{
ContainerID: "dummy",
Netns: targetNS.Path(),
IfName: ifname,
StdinData: []byte(conf),
}
_, _, err = testutils.CmdAddWithResult(targetNS.Path(), ifname, []byte(conf), func() error { return cmdAdd(args) })
err = originalNS.Do(func(ns.NetNS) error {
defer GinkgoRecover()
_, _, err := testutils.CmdAddWithResult(targetNS.Path(), ifname, []byte(conf), func() error { return cmdAdd(args) })
return err
})
Expect(err).NotTo(HaveOccurred())
// assert that dummy0 is now in the target namespace