From 2ec5bdc52b8641d619639ddc5681a65de85dad60 Mon Sep 17 00:00:00 2001 From: Takushi Fujiwara Date: Sun, 29 Sep 2019 18:13:29 +0000 Subject: [PATCH] Change LinkSetMaster's master argument type. (*Bridge -> Link) LinkSetMaster also works with Bond device. So this PR changes the type of master argument to Link. --- link_linux.go | 4 ++-- link_test.go | 59 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/link_linux.go b/link_linux.go index 665c482..5318c2c 100644 --- a/link_linux.go +++ b/link_linux.go @@ -709,13 +709,13 @@ func (h *Handle) LinkSetVfGUID(link Link, vf int, vfGuid net.HardwareAddr, guidT // LinkSetMaster sets the master of the link device. // Equivalent to: `ip link set $link master $master` -func LinkSetMaster(link Link, master *Bridge) error { +func LinkSetMaster(link Link, master Link) error { return pkgHandle.LinkSetMaster(link, master) } // LinkSetMaster sets the master of the link device. // Equivalent to: `ip link set $link master $master` -func (h *Handle) LinkSetMaster(link Link, master *Bridge) error { +func (h *Handle) LinkSetMaster(link Link, master Link) error { index := 0 if master != nil { masterBase := master.Attrs() diff --git a/link_test.go b/link_test.go index c444483..e4ac17f 100644 --- a/link_test.go +++ b/link_test.go @@ -857,20 +857,7 @@ func TestLinkAddDelBridgeMaster(t *testing.T) { } } -func TestLinkSetUnsetResetMaster(t *testing.T) { - tearDown := setUpNetlinkTest(t) - defer tearDown() - - master := &Bridge{LinkAttrs: LinkAttrs{Name: "foo"}} - if err := LinkAdd(master); err != nil { - t.Fatal(err) - } - - newmaster := &Bridge{LinkAttrs: LinkAttrs{Name: "bar"}} - if err := LinkAdd(newmaster); err != nil { - t.Fatal(err) - } - +func testLinkSetUnsetResetMaster(t *testing.T, master, newmaster Link) { slave := &Dummy{LinkAttrs{Name: "baz"}} if err := LinkAdd(slave); err != nil { t.Fatal(err) @@ -923,6 +910,50 @@ func TestLinkSetUnsetResetMaster(t *testing.T) { if err := LinkDel(slave); err != nil { t.Fatal(err) } +} + +func TestLinkSetUnsetResetMaster(t *testing.T) { + tearDown := setUpNetlinkTest(t) + defer tearDown() + + master := &Bridge{LinkAttrs: LinkAttrs{Name: "foo"}} + if err := LinkAdd(master); err != nil { + t.Fatal(err) + } + + newmaster := &Bridge{LinkAttrs: LinkAttrs{Name: "bar"}} + if err := LinkAdd(newmaster); err != nil { + t.Fatal(err) + } + + testLinkSetUnsetResetMaster(t, master, newmaster) + + if err := LinkDel(newmaster); err != nil { + t.Fatal(err) + } + + if err := LinkDel(master); err != nil { + t.Fatal(err) + } +} + +func TestLinkSetUnsetResetMasterBond(t *testing.T) { + tearDown := setUpNetlinkTest(t) + defer tearDown() + + master := NewLinkBond(LinkAttrs{Name: "foo"}) + master.Mode = BOND_MODE_BALANCE_RR + if err := LinkAdd(master); err != nil { + t.Fatal(err) + } + + newmaster := NewLinkBond(LinkAttrs{Name: "bar"}) + newmaster.Mode = BOND_MODE_BALANCE_RR + if err := LinkAdd(newmaster); err != nil { + t.Fatal(err) + } + + testLinkSetUnsetResetMaster(t, master, newmaster) if err := LinkDel(newmaster); err != nil { t.Fatal(err)