testing: test invocation of newer plugins with an older libcni
This commit is contained in:
@ -52,7 +52,7 @@ var _ = Describe("Invoking the plugin", func() {
|
||||
}
|
||||
Expect(debug.WriteDebug(debugFilePath)).To(Succeed())
|
||||
|
||||
cniBinPath = filepath.Dir(pathToPlugin)
|
||||
cniBinPath = filepath.Dir(pluginPaths["noop"])
|
||||
pluginConfig = `{ "type": "noop", "some-key": "some-value", "cniVersion": "0.2.0" }`
|
||||
cniConfig = libcni.CNIConfig{Path: []string{cniBinPath}}
|
||||
netConfig = &libcni.NetworkConfig{
|
||||
|
@ -17,12 +17,15 @@ package libcni_test
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/containernetworking/cni/libcni"
|
||||
"github.com/containernetworking/cni/pkg/version/legacy_examples"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/gomega/gexec"
|
||||
)
|
||||
|
||||
var _ = Describe("Backwards compatibility", func() {
|
||||
@ -50,4 +53,31 @@ var _ = Describe("Backwards compatibility", func() {
|
||||
|
||||
Expect(os.RemoveAll(pluginPath)).To(Succeed())
|
||||
})
|
||||
|
||||
It("correctly handles the request from a runtime with an older libcni", func() {
|
||||
// We need to be root (or have CAP_SYS_ADMIN...)
|
||||
if os.Geteuid() != 0 {
|
||||
Fail("must be run as root")
|
||||
}
|
||||
|
||||
example := legacy_examples.V010_Runtime
|
||||
|
||||
binPath, err := example.Build()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
for _, configName := range example.NetConfs {
|
||||
configStr, ok := legacy_examples.NetConfs[configName]
|
||||
if !ok {
|
||||
Fail("Invalid config name " + configName)
|
||||
}
|
||||
|
||||
cmd := exec.Command(binPath, pluginDirs...)
|
||||
cmd.Stdin = strings.NewReader(configStr)
|
||||
|
||||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Eventually(session).Should(gexec.Exit(0))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -15,6 +15,10 @@
|
||||
package libcni_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/onsi/gomega/gexec"
|
||||
@ -27,17 +31,35 @@ func TestLibcni(t *testing.T) {
|
||||
RunSpecs(t, "Libcni Suite")
|
||||
}
|
||||
|
||||
const packagePath = "github.com/containernetworking/cni/plugins/test/noop"
|
||||
var plugins = map[string]string{
|
||||
"noop": "github.com/containernetworking/cni/plugins/test/noop",
|
||||
"ptp": "github.com/containernetworking/cni/plugins/main/ptp",
|
||||
"host-local": "github.com/containernetworking/cni/plugins/ipam/host-local",
|
||||
}
|
||||
|
||||
var pathToPlugin string
|
||||
var pluginPaths map[string]string
|
||||
var pluginDirs []string // array of plugin dirs
|
||||
|
||||
var _ = SynchronizedBeforeSuite(func() []byte {
|
||||
var err error
|
||||
pathToPlugin, err = gexec.Build(packagePath)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
return []byte(pathToPlugin)
|
||||
dirs := make([]string, 0, len(plugins))
|
||||
|
||||
for name, packagePath := range plugins {
|
||||
execPath, err := gexec.Build(packagePath)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
dirs = append(dirs, fmt.Sprintf("%s=%s", name, execPath))
|
||||
}
|
||||
|
||||
return []byte(strings.Join(dirs, ":"))
|
||||
}, func(crossNodeData []byte) {
|
||||
pathToPlugin = string(crossNodeData)
|
||||
pluginPaths = make(map[string]string)
|
||||
for _, str := range strings.Split(string(crossNodeData), ":") {
|
||||
kvs := strings.SplitN(str, "=", 2)
|
||||
if len(kvs) != 2 {
|
||||
Fail("Invalid inter-node data...")
|
||||
}
|
||||
pluginPaths[kvs[0]] = kvs[1]
|
||||
pluginDirs = append(pluginDirs, filepath.Dir(kvs[1]))
|
||||
}
|
||||
})
|
||||
|
||||
var _ = SynchronizedAfterSuite(func() {}, func() {
|
||||
|
Reference in New Issue
Block a user