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

[WIP] HA unit tests #128

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ deb:

.PHONY: unit-test
unit-test:
go test -v
go test -v -ginkgo.label-filter=$(labels)

.PHONY: fmt
fmt: goimports ## Run goimports against code.
Expand Down
5 changes: 5 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func main() {
log.Infof("Client")
log.Infof(" servers: %v", CLI.Client.Server)
var err error
var serverCount = 0

if CLI.Client.Verbose {
log.SetLevel(log.DebugLevel)
Expand Down Expand Up @@ -139,6 +140,10 @@ func main() {
}

for _, server := range CLI.Client.Server {
serverCount++
if serverCount == 3 {
panic(fmt.Errorf("can not connect to more than 2 servers"))
}
if err := m.AddPeer(server, ""); err != nil {
panic(fmt.Errorf("failed to add server: %v", err))
}
Expand Down
26 changes: 14 additions & 12 deletions metalbond.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,20 @@ func (m *MetalBond) GetSubscribedVnis() []VNI {
return vnis
}

func (m *MetalBond) getHAPeerIfExists(target *metalBondPeer) *metalBondPeer {
m.mtxPeers.RLock()
defer m.mtxPeers.RUnlock()

for _, peer := range m.peers {
if peer.localAddr != target.localAddr {
return peer
}
}
return nil
}

func (m *MetalBond) addReceivedRoute(fromPeer *metalBondPeer, vni VNI, dest Destination, hop NextHop) error {
err := m.routeTable.AddNextHop(vni, dest, hop, fromPeer)
err := m.routeTable.AddNextHopHAAware(vni, dest, hop, fromPeer)
if err != nil {
return fmt.Errorf("Cannot add route to route table: %v", err)
}
Expand All @@ -326,16 +338,11 @@ func (m *MetalBond) addReceivedRoute(fromPeer *metalBondPeer, vni VNI, dest Dest
m.log().Errorf("Could not distribute route to peers: %v", err)
}

err = m.client.AddRoute(vni, dest, hop)
if err != nil {
m.log().Errorf("Client.AddRoute call failed: %v", err)
}

return nil
}

func (m *MetalBond) removeReceivedRoute(fromPeer *metalBondPeer, vni VNI, dest Destination, hop NextHop) error {
err, remaining := m.routeTable.RemoveNextHop(vni, dest, hop, fromPeer)
err, remaining := m.routeTable.RemoveNextHopHAAware(vni, dest, hop, fromPeer)
if err != nil {
return fmt.Errorf("Cannot remove route from route table: %v", err)
}
Expand All @@ -352,11 +359,6 @@ func (m *MetalBond) removeReceivedRoute(fromPeer *metalBondPeer, vni VNI, dest D
}
}

err = m.client.RemoveRoute(vni, dest, hop)
if err != nil {
m.log().Errorf("Client.RemoveRoute call failed: %v", err)
}

return nil
}

Expand Down
Loading
Loading