forked from github/multus-cni
Support MacRequest to specify MAC address for interface
This commit is contained in:
committed by
dougbtv
parent
6b573e8c4b
commit
dae85d7781
@@ -44,11 +44,12 @@ func TestMultus(t *testing.T) {
|
||||
}
|
||||
|
||||
type fakePlugin struct {
|
||||
expectedEnv []string
|
||||
expectedConf string
|
||||
expectedIfname string
|
||||
result cnitypes.Result
|
||||
err error
|
||||
expectedEnv []string
|
||||
expectedConf string
|
||||
expectedIfname string
|
||||
expectedMacAddr string
|
||||
result cnitypes.Result
|
||||
err error
|
||||
}
|
||||
|
||||
type fakeExec struct {
|
||||
@@ -59,7 +60,7 @@ type fakeExec struct {
|
||||
plugins []*fakePlugin
|
||||
}
|
||||
|
||||
func (f *fakeExec) addPlugin(expectedEnv []string, expectedIfname, expectedConf string, result *types020.Result, err error) {
|
||||
func (f *fakeExec) addPlugin(expectedEnv []string, expectedIfname, expectedMacAddr, expectedConf string, result *types020.Result, err error) {
|
||||
f.plugins = append(f.plugins, &fakePlugin{
|
||||
expectedEnv: expectedEnv,
|
||||
expectedConf: expectedConf,
|
||||
@@ -123,6 +124,9 @@ func (f *fakeExec) ExecPlugin(pluginPath string, stdinData []byte, environ []str
|
||||
if plugin.expectedIfname != "" {
|
||||
Expect(os.Getenv("CNI_IFNAME")).To(Equal(plugin.expectedIfname))
|
||||
}
|
||||
if plugin.expectedMacAddr != "" {
|
||||
Expect(os.Getenv("MAC")).To(Equal(plugin.expectedMacAddr))
|
||||
}
|
||||
if len(plugin.expectedEnv) > 0 {
|
||||
matchArray(gatherCNIEnv(), plugin.expectedEnv)
|
||||
}
|
||||
@@ -203,7 +207,7 @@ var _ = Describe("multus operations", func() {
|
||||
"cniVersion": "0.2.0",
|
||||
"type": "weave-net"
|
||||
}`
|
||||
fExec.addPlugin(nil, "eth0", expectedConf1, expectedResult1, nil)
|
||||
fExec.addPlugin(nil, "eth0", "", expectedConf1, expectedResult1, nil)
|
||||
|
||||
expectedResult2 := &types020.Result{
|
||||
CNIVersion: "0.2.0",
|
||||
@@ -216,7 +220,7 @@ var _ = Describe("multus operations", func() {
|
||||
"cniVersion": "0.2.0",
|
||||
"type": "other-plugin"
|
||||
}`
|
||||
fExec.addPlugin(nil, "net1", expectedConf2, expectedResult2, nil)
|
||||
fExec.addPlugin(nil, "net1", "", expectedConf2, expectedResult2, nil)
|
||||
|
||||
os.Setenv("CNI_COMMAND", "ADD")
|
||||
os.Setenv("CNI_IFNAME", "eth0")
|
||||
@@ -241,6 +245,83 @@ var _ = Describe("multus operations", func() {
|
||||
|
||||
})
|
||||
|
||||
It("executes delegates with interface name and MAC addr", func() {
|
||||
podNet := `[{"name":"net1",
|
||||
"interfaceRequest": "test1"},
|
||||
{"name":"net2",
|
||||
"macRequest": "c2:11:22:33:44:66"}
|
||||
]`
|
||||
fakePod := testhelpers.NewFakePod("testpod", podNet)
|
||||
net1 := `{
|
||||
"name": "net1",
|
||||
"type": "mynet",
|
||||
"cniVersion": "0.2.0"
|
||||
}`
|
||||
net2 := `{
|
||||
"name": "net2",
|
||||
"type": "mynet2",
|
||||
"cniVersion": "0.2.0"
|
||||
}`
|
||||
args := &skel.CmdArgs{
|
||||
ContainerID: "123456789",
|
||||
Netns: testNS.Path(),
|
||||
IfName: "eth0",
|
||||
Args: fmt.Sprintf("K8S_POD_NAME=%s;K8S_POD_NAMESPACE=%s", fakePod.ObjectMeta.Name, fakePod.ObjectMeta.Namespace),
|
||||
StdinData: []byte(`{
|
||||
"name": "node-cni-network",
|
||||
"type": "multus",
|
||||
"kubeconfig": "/etc/kubernetes/node-kubeconfig.yaml",
|
||||
"delegates": [{
|
||||
"name": "weave1",
|
||||
"cniVersion": "0.2.0",
|
||||
"type": "weave-net"
|
||||
}]
|
||||
}`),
|
||||
}
|
||||
|
||||
fExec := &fakeExec{}
|
||||
expectedResult1 := &types020.Result{
|
||||
CNIVersion: "0.2.0",
|
||||
IP4: &types020.IPConfig{
|
||||
IP: *testhelpers.EnsureCIDR("1.1.1.2/24"),
|
||||
},
|
||||
}
|
||||
expectedConf1 := `{
|
||||
"name": "weave1",
|
||||
"cniVersion": "0.2.0",
|
||||
"type": "weave-net"
|
||||
}`
|
||||
fExec.addPlugin(nil, "eth0", "", expectedConf1, expectedResult1, nil)
|
||||
fExec.addPlugin(nil, "test1", "", net1, &types020.Result{
|
||||
CNIVersion: "0.2.0",
|
||||
IP4: &types020.IPConfig{
|
||||
IP: *testhelpers.EnsureCIDR("1.1.1.3/24"),
|
||||
},
|
||||
}, nil)
|
||||
fExec.addPlugin(nil, "net2", "c2:11:22:33:44:66", net2, &types020.Result{
|
||||
CNIVersion: "0.2.0",
|
||||
IP4: &types020.IPConfig{
|
||||
IP: *testhelpers.EnsureCIDR("1.1.1.4/24"),
|
||||
},
|
||||
}, nil)
|
||||
|
||||
fKubeClient := testhelpers.NewFakeKubeClient()
|
||||
fKubeClient.AddPod(fakePod)
|
||||
fKubeClient.AddNetConfig(fakePod.ObjectMeta.Namespace, "net1", net1)
|
||||
fKubeClient.AddNetConfig(fakePod.ObjectMeta.Namespace, "net2", net2)
|
||||
|
||||
os.Setenv("CNI_COMMAND", "ADD")
|
||||
os.Setenv("CNI_IFNAME", "eth0")
|
||||
result, err := cmdAdd(args, fExec, fKubeClient)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(fExec.addIndex).To(Equal(len(fExec.plugins)))
|
||||
Expect(fKubeClient.PodCount).To(Equal(2))
|
||||
Expect(fKubeClient.NetCount).To(Equal(2))
|
||||
r := result.(*types020.Result)
|
||||
// plugin 1 is the masterplugin
|
||||
Expect(reflect.DeepEqual(r, expectedResult1)).To(BeTrue())
|
||||
})
|
||||
|
||||
It("executes delegates and kubernetes networks", func() {
|
||||
fakePod := testhelpers.NewFakePod("testpod", "net1,net2")
|
||||
net1 := `{
|
||||
@@ -287,14 +368,14 @@ var _ = Describe("multus operations", func() {
|
||||
"cniVersion": "0.2.0",
|
||||
"type": "weave-net"
|
||||
}`
|
||||
fExec.addPlugin(nil, "eth0", expectedConf1, expectedResult1, nil)
|
||||
fExec.addPlugin(nil, "net1", net1, &types020.Result{
|
||||
fExec.addPlugin(nil, "eth0", "", expectedConf1, expectedResult1, nil)
|
||||
fExec.addPlugin(nil, "net1", "", net1, &types020.Result{
|
||||
CNIVersion: "0.2.0",
|
||||
IP4: &types020.IPConfig{
|
||||
IP: *testhelpers.EnsureCIDR("1.1.1.3/24"),
|
||||
},
|
||||
}, nil)
|
||||
fExec.addPlugin(nil, "net2", net2, &types020.Result{
|
||||
fExec.addPlugin(nil, "net2", "", net2, &types020.Result{
|
||||
CNIVersion: "0.2.0",
|
||||
IP4: &types020.IPConfig{
|
||||
IP: *testhelpers.EnsureCIDR("1.1.1.4/24"),
|
||||
|
Reference in New Issue
Block a user