From 00b072dd0b13395272df1ff4fc9ec58baaf42d1f Mon Sep 17 00:00:00 2001 From: Casey Callendrello Date: Wed, 11 Apr 2018 15:03:04 +0200 Subject: [PATCH 1/3] pkg/ip: re-fetch the created link to return creation-time parameters Fixes: #140 --- pkg/ip/link_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/ip/link_linux.go b/pkg/ip/link_linux.go index 843ce8aad..3e5724eae 100644 --- a/pkg/ip/link_linux.go +++ b/pkg/ip/link_linux.go @@ -42,8 +42,14 @@ func makeVethPair(name, peer string, mtu int) (netlink.Link, error) { if err := netlink.LinkAdd(veth); err != nil { return nil, err } + // Re-fetch the link to get its creation-time parameters, e.g. index and mac + veth2, err := netlink.LinkByName(name) + if err != nil { + netlink.LinkDel(veth) // try and clean up the link if possible. + return nil, err + } - return veth, nil + return veth2, nil } func peerExists(name string) bool { From 13e6a4b2baf1e535052cd07359bc04b95bb582da Mon Sep 17 00:00:00 2001 From: Casey Callendrello Date: Wed, 11 Apr 2018 15:10:39 +0200 Subject: [PATCH 2/3] plugins/bridge: Make stricter assertions about the return data --- plugins/main/bridge/bridge_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/main/bridge/bridge_test.go b/plugins/main/bridge/bridge_test.go index ff738ca20..fbbd741ee 100644 --- a/plugins/main/bridge/bridge_test.go +++ b/plugins/main/bridge/bridge_test.go @@ -257,7 +257,14 @@ func (tester *testerV03x) cmdAddTest(tc testCase) { Expect(len(result.Interfaces)).To(Equal(3)) Expect(result.Interfaces[0].Name).To(Equal(BRNAME)) + Expect(result.Interfaces[0].Mac).To(HaveLen(17)) + + Expect(result.Interfaces[1].Name).To(HavePrefix("veth")) + Expect(result.Interfaces[1].Mac).To(HaveLen(17)) + Expect(result.Interfaces[2].Name).To(Equal(IFNAME)) + Expect(result.Interfaces[2].Mac).To(HaveLen(17)) //mac is random + Expect(result.Interfaces[2].Sandbox).To(Equal(tester.targetNS.Path())) // Make sure bridge link exists link, err := netlink.LinkByName(result.Interfaces[0].Name) From 26dafaa0972413c8ac01f44b614cc3dc47094738 Mon Sep 17 00:00:00 2001 From: Casey Callendrello Date: Wed, 11 Apr 2018 15:19:20 +0200 Subject: [PATCH 3/3] plugins/ptp: test for valid data in Interfaces field --- plugins/main/ptp/ptp_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/main/ptp/ptp_test.go b/plugins/main/ptp/ptp_test.go index e68c630ce..85430d11e 100644 --- a/plugins/main/ptp/ptp_test.go +++ b/plugins/main/ptp/ptp_test.go @@ -78,12 +78,14 @@ var _ = Describe("ptp Operations", func() { // Make sure ptp link exists in the target namespace // Then, ping the gateway seenIPs := 0 + + wantMac := "" err = targetNs.Do(func(ns.NetNS) error { defer GinkgoRecover() link, err := netlink.LinkByName(IFNAME) Expect(err).NotTo(HaveOccurred()) - Expect(link.Attrs().Name).To(Equal(IFNAME)) + wantMac = link.Attrs().HardwareAddr.String() for _, ipc := range res.IPs { if *ipc.Interface != 1 { @@ -105,6 +107,17 @@ var _ = Describe("ptp Operations", func() { Expect(seenIPs).To(Equal(numIPs)) + // make sure the interfaces are correct + Expect(res.Interfaces).To(HaveLen(2)) + + Expect(res.Interfaces[0].Name).To(HavePrefix("veth")) + Expect(res.Interfaces[0].Mac).To(HaveLen(17)) + Expect(res.Interfaces[0].Sandbox).To(BeEmpty()) + + Expect(res.Interfaces[1].Name).To(Equal(IFNAME)) + Expect(res.Interfaces[1].Mac).To(Equal(wantMac)) + Expect(res.Interfaces[1].Sandbox).To(Equal(targetNs.Path())) + // Call the plugins with the DEL command, deleting the veth endpoints err = originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover()