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.
This commit is contained in:
Takushi Fujiwara 2019-09-29 18:13:29 +00:00 committed by Alessandro Boch
parent ac5f4df047
commit 2ec5bdc52b
2 changed files with 47 additions and 16 deletions

View File

@ -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()

View File

@ -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)