Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: test invocation of newer plugins with an older libcni #307

Merged

Conversation

squeed
Copy link
Member

@squeed squeed commented Oct 14, 2016

This test compiles a trivial client with a fixed version libcni. It then creates and destroys a ptp network using the most recent plugin.

It's basically a simplified version of ptp_test.go in a single file.

@squeed squeed force-pushed the backwards-compatability-tests branch from 099bbd8 to 3bb2044 Compare October 14, 2016 14:59
@dcbw
Copy link
Member

dcbw commented Oct 16, 2016

lgtm

result, err := cniConfig.AddNetwork(netConf, runtimeConf)
fmt.Printf("Result: %+v", result)
if err != nil {
fmt.Printf("noop add failed: %+v", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't the no-op plugin, right? maybe it could read cni add failed instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, good catch.

IfName: ifName,
}

cniConfig := &libcni.CNIConfig{Path: strings.Split(os.Getenv("PATH"), ":")}
Copy link
Contributor

@rosenhouse rosenhouse Oct 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes that the ptp plugin is in the PATH when the tests are run. That appears to be true of the top-level ./test script, but it isn't generally true. For example, if I just run

go test github.com/containernetworking/cni/libcni

from my shell, then I get a failure with error

failed to find plugin "ptp" in path [/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin]

Perhaps you can build the ptp plugin outside of this program, e.g. as part of the new spec you're adding to backwards_compatibility_test.go. Then pass in the path to that binary as an env var (e.g. CNI_PATH) or argument to this program. For an example of how to build a plugin as part of a test-run, look here.

That has the added benefit of making it clearer, when reading the test, that you're running a legacy runtime against a current-version plugin. Because you can see the plugin gets built right in the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll clean this up.
A fun thing about some of the plugin tests is that they need to be run as root. libcni's tests were actually an exception - but not anymore. The test script does a sudo. The tests should probably have a bit of a cleaner warning (or maybe skip) when executed as non-root.

}

func exec() int {
confStr := "{ \"name\": \"default\", \"type\":\"ptp\", \"ipam\":{ \"type\": \"host-local\", \"subnet\": \"10.1.2.0/24\"}}"
Copy link
Contributor

@rosenhouse rosenhouse Oct 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config is not part of the legacy runtime. A user can change it independently of the runtime.

So I'd suggest that this string be declared in the spec It correctly handles the request from a legacy libcni that you're adding to backwards_compatibility_test.go, and then somehow injected into this program (e.g. via env var or command line args).

That would make it clearer, when reading the test, what exactly is being tested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, good point.
Is it safe to say that a runtime will not encounter a config file with a newer CNI version then it understands? I think so, since libcni takes a parsed NetConfig. So while the test matrix has gained another dimension, it's not too bad.

@@ -50,4 +52,17 @@ var _ = Describe("Backwards compatibility", func() {

Expect(os.RemoveAll(pluginPath)).To(Succeed())
})

It("correctly handles the request from a legacy libcni", func() {
example := legacy_examples.V010_Client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit-pick on naming: We tend to use nomenclature like "container runtime" or just "runtime" for the thing that calls CNI plugins. I think the test would read slightly better if the spec and variable names spoke of "legacy runtime" calling a "current-version plugin" or something like that.

@rosenhouse
Copy link
Contributor

Thanks @squeed, this is a great start, the right approach IMHO. I left a few small suggestions to make this test more portable and readable.

@squeed squeed force-pushed the backwards-compatability-tests branch 2 times, most recently from 663303d to 4b5d9ad Compare October 21, 2016 13:19
@squeed
Copy link
Member Author

squeed commented Oct 21, 2016

@rosenhouse thanks for the feedback! Updated.

@dcbw
Copy link
Member

dcbw commented Oct 21, 2016

@squeed needs a fix for gopath/src/github.com/containernetworking/cni/pkg/version/legacy_examples/example_runtime.go:27: syntax error: non-declaration statement outside function body

@squeed squeed force-pushed the backwards-compatability-tests branch from 4b5d9ad to 52d618f Compare October 24, 2016 12:21
@squeed
Copy link
Member Author

squeed commented Oct 24, 2016

@dcbw sorry 'bout that. Off to buy a copy of vim for dummies.

_, err = procIn.Write([]byte(configStr))
Expect(err).NotTo(HaveOccurred())
err = procIn.Close()
Expect(err).NotTo(HaveOccurred())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're just trying to pass a string in as standard input to the cmd, right?

If so, then just set

cmd.Stdin = strings.NewReader(configStr)

before running gexec.Start. No need for StdinPipe with separateWrite and Close calls.

@squeed squeed force-pushed the backwards-compatability-tests branch from 52d618f to 8c6f6e0 Compare October 25, 2016 14:56
@rosenhouse rosenhouse merged commit 7964385 into containernetworking:master Nov 7, 2016
@tomdee tomdee mentioned this pull request Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants