Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add BridgeToParent to VSwitchService #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Tejas Kokje <tkokje@digitalocean.com>
Kei Nohguchi <knohguchi@digitalocean.com>
Neal Shrader <nshrader@digitalocean.com>
Sangeetha Srikanth <ssrikanth@digitalocean.com>
John Oberly III <joberly@gmail.com>
11 changes: 11 additions & 0 deletions ovs/vswitch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ func (v *VSwitchService) AddPort(bridge string, port string) error {
return err
}

// BridgeToParent returns the parent bridge of a bridge on Open vSwitch.
// If a bridge has no parent, it returns the bridge from the call.
func (v *VSwitchService) BridgeToParent(bridge string) (string, error) {
out, err := v.exec("br-to-parent", bridge)
if err != nil {
return "", err
}

return string(out), nil
}

// DeleteBridge detaches a bridge from Open vSwitch. The bridge may or may
// not already exist.
func (v *VSwitchService) DeleteBridge(bridge string) error {
Expand Down
35 changes: 35 additions & 0 deletions ovs/vswitch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,41 @@ func TestClientVSwitchAddPortOK(t *testing.T) {
}
}

func TestClientVSwitchBridgeToParentOK(t *testing.T) {
br := "br0-1"
wantBr := "br0"

// Add Timeout option to verify arguments
c := testClient([]OptionFunc{Timeout(1)}, func(cmd string, args ...string) ([]byte, error) {
// Verify command
if want, got := "ovs-vsctl", cmd; want != got {
t.Fatalf("incorrect command:\n- want: %v\n- got: %v",
want, got)
}

// Verify arguments including option flags
wantArgs := []string{"--timeout=1", "br-to-parent", br}
if want, got := wantArgs, args; !reflect.DeepEqual(want, got) {
t.Fatalf("incorrect arguments\n- want: %v\n- got: %v",
want, got)
}

// Add whitespace to verify it is trimmed appropriately
return []byte("\n\n " + wantBr + "\t\n "), nil
})

parentBr, err := c.VSwitch.BridgeToParent(br)
if err != nil {
t.Fatalf("unexpected error for Client.VSwitch.BridgeToParent: %v", err)
}

// Verify function return value
if want, got := wantBr, parentBr; want != got {
t.Fatalf("unexpected bridge:\n- want: %v\n- got: %v",
want, got)
}
}

func TestClientVSwitchDeleteBridgeOK(t *testing.T) {
bridge := "br0"

Expand Down