Skip to content

Commit

Permalink
Simplify gobgp integration test and set BGP log level to debug
Browse files Browse the repository at this point in the history
This commit simplifies the test to reduce failure potential and enables
debug logging for BGP processes to improve issue diagnosis.

Signed-off-by: Hongliang Liu <hongliang.liu@broadcom.com>
  • Loading branch information
hongliangl committed Nov 13, 2024
1 parent b6d4238 commit 7367e9b
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 163 deletions.
28 changes: 28 additions & 0 deletions pkg/agent/bgp/gobgp/gobgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func (s *Server) Stop(ctx context.Context) error {
return nil
}

func (s *Server) SetLogLevel(ctx context.Context, level bgp.LogLevel) error {
setLevelRequest := &gobgpapi.SetLogLevelRequest{Level: convertLogLevelToGoBGPLogLevel(level)}
if err := s.server.SetLogLevel(ctx, setLevelRequest); err != nil {
return err
}
return nil
}

func (s *Server) AddPeer(ctx context.Context, peerConf bgp.PeerConfig) error {
peer, err := convertPeerConfigToGoBGPPeer(peerConf)
if err != nil {
Expand Down Expand Up @@ -318,6 +326,26 @@ func convertGoBGPSessionStateToSessionState(s gobgpapi.PeerState_SessionState) b
}
}

func convertLogLevelToGoBGPLogLevel(level bgp.LogLevel) gobgpapi.SetLogLevelRequest_Level {
switch level {
case bgp.Panic:
return gobgpapi.SetLogLevelRequest_PANIC
case bgp.Fatal:
return gobgpapi.SetLogLevelRequest_FATAL
case bgp.Error:
return gobgpapi.SetLogLevelRequest_ERROR
case bgp.Warn:
return gobgpapi.SetLogLevelRequest_WARN
case bgp.Info:
return gobgpapi.SetLogLevelRequest_INFO
case bgp.Debug:
return gobgpapi.SetLogLevelRequest_DEBUG
case bgp.Trace:
return gobgpapi.SetLogLevelRequest_TRACE
}
return -1
}

func isValidIPString(ip string) bool {
return net.IsIPv6String(ip) || net.IsIPv4String(ip)
}
20 changes: 20 additions & 0 deletions pkg/agent/bgp/gobgp/gobgp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,23 @@ func TestConvertGoBGPSessionStateToSessionState(t *testing.T) {
assert.Equal(t, test.expected, output)
}
}

func TestConvertLogLevelToGoBGPLogLevel(t *testing.T) {
tests := []struct {
input bgp.LogLevel
expected gobgpapi.SetLogLevelRequest_Level
}{
{bgp.Panic, gobgpapi.SetLogLevelRequest_PANIC},
{bgp.Fatal, gobgpapi.SetLogLevelRequest_FATAL},
{bgp.Error, gobgpapi.SetLogLevelRequest_ERROR},
{bgp.Warn, gobgpapi.SetLogLevelRequest_WARN},
{bgp.Info, gobgpapi.SetLogLevelRequest_INFO},
{bgp.Debug, gobgpapi.SetLogLevelRequest_DEBUG},
{bgp.Trace, gobgpapi.SetLogLevelRequest_TRACE},
}

for _, test := range tests {
output := convertLogLevelToGoBGPLogLevel(test.input)
assert.Equal(t, test.expected, output)
}
}
15 changes: 15 additions & 0 deletions pkg/agent/bgp/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type Interface interface {
// AddPeer adds a new BGP peer.
AddPeer(ctx context.Context, peerConf PeerConfig) error

// SetLogLevel sets log level for the BGP process.
SetLogLevel(ctx context.Context, level LogLevel) error

// UpdatePeer updates an existing BGP peer.
UpdatePeer(ctx context.Context, peerConf PeerConfig) error

Expand All @@ -59,6 +62,18 @@ type GlobalConfig struct {
ListenPort int32
}

type LogLevel int32

const (
Panic LogLevel = 0
Fatal LogLevel = 1
Error LogLevel = 2
Warn LogLevel = 3
Info LogLevel = 4
Debug LogLevel = 5
Trace LogLevel = 6
)

type SessionState string

const (
Expand Down
14 changes: 14 additions & 0 deletions pkg/agent/bgp/testing/mock_bgp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7367e9b

Please sign in to comment.