Skip to content

Commit

Permalink
Merge pull request #93 from qinqon/remove_bridge_from_result
Browse files Browse the repository at this point in the history
Remove bridge from report
phoracek authored Nov 28, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 8511b68 + efba571 commit 25670b4
Showing 2 changed files with 8 additions and 37 deletions.
20 changes: 1 addition & 19 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
@@ -94,13 +94,6 @@ func loadNetConf(bytes []byte) (*netConf, error) {
return netconf, nil
}

func setupBridge(brName string) *current.Interface {
return &current.Interface{
Name: brName,
Mac: getHardwareAddr(brName),
}
}

func generateRandomMac() net.HardwareAddr {
prefix := []byte{0x02, 0x00, 0x00} // local unicast prefix
suffix := make([]byte, 3)
@@ -244,8 +237,6 @@ func CmdAdd(args *skel.CmdArgs) error {
return err
}

brIface := setupBridge(bridgeName)

contNetns, err := ns.GetNS(args.Netns)
if err != nil {
return fmt.Errorf("failed to open netns %q: %v", args.Netns, err)
@@ -261,17 +252,8 @@ func CmdAdd(args *skel.CmdArgs) error {
return err
}

// Refetch the bridge since its MAC address may change when the first
// veth is added.
if err = refetchIface(brIface); err != nil {
return fmt.Errorf("failed to lookup %q: %v", brIface.Name, err)
}

// Refetch the bridge MAC since it may change when the first veth is added.
brIface.Mac = getHardwareAddr(brIface.Name)

result := &current.Result{
Interfaces: []*current.Interface{brIface, hostIface, contIface},
Interfaces: []*current.Interface{hostIface, contIface},
}

return types.PrintResult(result, netconf.CNIVersion)
25 changes: 7 additions & 18 deletions pkg/plugin/plugin_test.go
Original file line number Diff line number Diff line change
@@ -90,22 +90,11 @@ var _ = Describe("CNI Plugin", func() {
By("Checking that result of ADD command in in expected format")
result, err = current.GetResult(r)
Expect(err).NotTo(HaveOccurred())
Expect(len(result.Interfaces)).To(Equal(3))
Expect(len(result.Interfaces)).To(Equal(2))
Expect(len(result.IPs)).To(Equal(0))

brIface := result.Interfaces[0]
hostIface := result.Interfaces[1]
contIface := result.Interfaces[2]

By("Checking that bridge interface name in the result matches requested")
Expect(brIface.Name).To(Equal(BRIDGE_NAME))

By("Checking that bridge interface MAC in the result matches reality")
brLink, err := netlink.LinkByName(BRIDGE_NAME)
Expect(err).NotTo(HaveOccurred())
brHwaddr, err := net.ParseMAC(brIface.Mac)
Expect(err).NotTo(HaveOccurred())
Expect(brLink.Attrs().HardwareAddr).To(Equal(brHwaddr))
hostIface := result.Interfaces[0]
contIface := result.Interfaces[1]

By("Checking that host interface MAC in the result matches reality")
hostLink, err := netlink.LinkByName(hostIface.Name)
@@ -258,10 +247,10 @@ var _ = Describe("CNI Plugin", func() {

By("Checking that both namespaces have different mac addresses on eth0")
resultOne := attach(targetNsOne, conf, IFNAME, "", "")
contOneIface := resultOne.Interfaces[2]
contOneIface := resultOne.Interfaces[0]

resultTwo := attach(targetNsTwo, conf, IFNAME, "", "")
contTwoIface := resultTwo.Interfaces[2]
contTwoIface := resultTwo.Interfaces[1]

Expect(contOneIface.Mac).NotTo(Equal(contTwoIface.Mac))
})
@@ -286,7 +275,7 @@ var _ = Describe("CNI Plugin", func() {
By("Checking that the mac address on eth0 equals to the requested one")
mac := "0a:00:00:00:00:80"
result := attach(targetNs, conf, IFNAME, mac, "")
contIface := result.Interfaces[2]
contIface := result.Interfaces[1]

Expect(contIface.Mac).To(Equal(mac))
})
@@ -309,7 +298,7 @@ var _ = Describe("CNI Plugin", func() {

OvnPort := "test-port"
result := attach(targetNs, conf, IFNAME, "", OvnPort)
hostIface := result.Interfaces[1]
hostIface := result.Interfaces[0]
output, err := exec.Command("ovs-vsctl", "--colum=external_ids", "find", "Interface", fmt.Sprintf("name=%s", hostIface.Name)).CombinedOutput()
Expect(err).NotTo(HaveOccurred())
Expect(string(output[:len(output)-1])).To(Equal(ovsOutput))

0 comments on commit 25670b4

Please sign in to comment.