Skip to content

Commit

Permalink
add: fail case ut (#4589)
Browse files Browse the repository at this point in the history
Signed-off-by: bobz965 <[email protected]>
  • Loading branch information
bobz965 authored Oct 10, 2024
1 parent 4f80f33 commit 39067cd
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 13 deletions.
63 changes: 63 additions & 0 deletions pkg/ovs/ovn-nb-bfd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func (suite *OvnClientTestSuite) testListBFD() {
t.Parallel()

nbClient := suite.ovnNBClient
failedNbClient := suite.faiedOvnNBClient

lrpName := "test-list-bfd"
dstIP1 := "192.168.124.2"
dstIP2 := "192.168.124.3"
Expand Down Expand Up @@ -96,13 +98,25 @@ func (suite *OvnClientTestSuite) testListBFD() {
}
require.True(t, uuids.IsEqual(strset.New(bfd1.UUID, bfd2.UUID)))
})

t.Run("closed server list failed BFDs", func(t *testing.T) {
t.Parallel()
failedBFD1, err := failedNbClient.CreateBFD(lrpName, dstIP1, minRx1, minTx1, detectMult1)
require.Error(t, err)
require.Nil(t, failedBFD1)
// cache db should be empty
bfdList, err := failedNbClient.ListBFDs(lrpName, dstIP1)
require.NoError(t, err)
require.Len(t, bfdList, 0)
})
}

func (suite *OvnClientTestSuite) testDeleteBFD() {
t := suite.T()
t.Parallel()

nbClient := suite.ovnNBClient
failedNbClient := suite.faiedOvnNBClient
lrpName := "test-del-bfd"
dstIP1 := "192.168.124.4"
dstIP2 := "192.168.124.5"
Expand Down Expand Up @@ -144,13 +158,24 @@ func (suite *OvnClientTestSuite) testDeleteBFD() {
err := nbClient.DeleteBFD(lrpName, "192.168.124.17")
require.NoError(t, err)
})

t.Run("closed server delete non-existent BFD", func(t *testing.T) {
t.Parallel()

_, err := failedNbClient.CreateBFD(lrpName, dstIP1, minRx1, minTx1, detectMult1)
require.Error(t, err)
err = failedNbClient.DeleteBFD(lrpName, "192.168.124.17")
// cache db should be empty
require.NoError(t, err)
})
}

func (suite *OvnClientTestSuite) testListDownBFDs() {
t := suite.T()
t.Parallel()

nbClient := suite.ovnNBClient
failedNbClient := suite.faiedOvnNBClient
lrpName := "test-list-down-bfd"
dstIP1 := "192.168.124.6"
dstIP2 := "192.168.124.7"
Expand All @@ -163,6 +188,10 @@ func (suite *OvnClientTestSuite) testListDownBFDs() {
bfd1, err := nbClient.CreateBFD(lrpName, dstIP1, minRx, minTx, detectMult)
require.NoError(t, err)
require.NotNil(t, bfd1)
// closed server create failed BFD
failedBFD1, err := failedNbClient.CreateBFD(lrpName, dstIP1, minRx, minTx, detectMult)
require.Error(t, err)
require.Nil(t, failedBFD1)

bfd2, err := nbClient.CreateBFD(lrpName, dstIP2, minRx, minTx, detectMult)
require.NoError(t, err)
Expand All @@ -183,10 +212,16 @@ func (suite *OvnClientTestSuite) testListDownBFDs() {

err = nbClient.UpdateBFD(bfd1)
require.NoError(t, err)
// closed server update failed BFD
err = failedNbClient.UpdateBFD(bfd1)
require.NoError(t, err)
err = nbClient.UpdateBFD(bfd2)
require.NoError(t, err)
err = nbClient.UpdateBFD(bfd3)
require.NoError(t, err)
// update not exist bfd
err = nbClient.UpdateBFD(&ovnnb.BFD{UUID: "not-exist"})
require.Error(t, err)

// Test listing down BFDs for specific IP
downBFDs, err := nbClient.ListDownBFDs(dstIP1)
Expand Down Expand Up @@ -466,6 +501,7 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() {
t.Parallel()

nbClient := suite.ovnNBClient
failedNbClient := suite.faiedOvnNBClient

t.Run("BFD status change with wrong table", func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -604,6 +640,28 @@ func (suite *OvnClientTestSuite) testBfdUpdateL3HAHandler() {

nbClient.bfdUpdateL3HAHandler(ovnnb.BFDTable, bfd, &newBfd)
})

t.Run("failed client update BFD status", func(t *testing.T) {
t.Parallel()

lrpName := "test-failed-client-bfd-update"
dstIP := "192.168.124.28"
minRx, minTx, detectMult := 101, 102, 19

failedBFD, err := failedNbClient.CreateBFD(lrpName, dstIP, minRx, minTx, detectMult)
require.Error(t, err)
require.Nil(t, failedBFD)
newBfd := &ovnnb.BFD{
LogicalPort: lrpName,
UUID: "test-failed-client-bfd-update",
DstIP: dstIP,
MinRx: &minRx,
MinTx: &minTx,
DetectMult: &detectMult,
}
err = failedNbClient.UpdateBFD(newBfd)
require.NoError(t, err)
})
}

func (suite *OvnClientTestSuite) testBfdDelL3HAHandler() {
Expand Down Expand Up @@ -645,3 +703,8 @@ func (suite *OvnClientTestSuite) testBfdDelL3HAHandler() {
nbClient.bfdDelL3HAHandler(ovnnb.BFDTable, bfd)
})
}

func (suite *OvnClientTestSuite) testMonitorBFDs() {
nbClient := suite.ovnNBClient
nbClient.MonitorBFD()
}
52 changes: 39 additions & 13 deletions pkg/ovs/ovn-nb-suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,53 @@ type OvnClientTestSuite struct {
suite.Suite
ovnNBClient *OVNNbClient
ovnSBClient *OVNSbClient

faiedOvnNBClient *OVNNbClient
}

func emptyNbDatabaseModel() (model.ClientDBModel, error) {
return model.NewClientDBModel("OVN_Northbound", map[string]model.Model{})
}

func (suite *OvnClientTestSuite) SetupSuite() {
fmt.Println("set up OvnClient test suite")
clientSchema := ovnnb.Schema()
clientDBModel, err := ovnnb.FullDatabaseModel()
fmt.Println("set up ovn client test suite")
// setup ovn nb client
nbClientSchema := ovnnb.Schema()
nbClientDBModel, err := ovnnb.FullDatabaseModel()
require.NoError(suite.T(), err)

_, sock := newOVSDBServer(suite.T(), clientDBModel, clientSchema)
endpoint := fmt.Sprintf("unix:%s", sock)
require.FileExists(suite.T(), sock)
_, nbSock := newOVSDBServer(suite.T(), nbClientDBModel, nbClientSchema)
nbEndpoint := fmt.Sprintf("unix:%s", nbSock)
require.FileExists(suite.T(), nbSock)

ovnNBClient, err := newOvnNbClient(suite.T(), endpoint, 10)
ovnNBClient, err := newOvnNbClient(suite.T(), nbEndpoint, 10)
require.NoError(suite.T(), err)
suite.ovnNBClient = ovnNBClient

clientSchema = ovnsb.Schema()
clientDBModel, err = ovnsb.FullDatabaseModel()
// setup failed case ovn nb client
emptyNbDBModel, err := emptyNbDatabaseModel()
require.NoError(suite.T(), err)

server1, nbSock1 := newOVSDBServer(suite.T(), emptyNbDBModel, nbClientSchema)
nbEndpoint1 := fmt.Sprintf("unix:%s", nbSock1)
require.FileExists(suite.T(), nbSock1)
faiedOvnNBClient, err := newOvnNbClient(suite.T(), nbEndpoint1, 10)
require.NoError(suite.T(), err)
suite.faiedOvnNBClient = faiedOvnNBClient
// close the server to simulate the failed case
server1.Close()
require.NoFileExists(suite.T(), nbSock1)

// setup ovn sb client
sbClientSchema := ovnsb.Schema()
sbClientDBModel, err := ovnsb.FullDatabaseModel()
require.NoError(suite.T(), err)

_, sock = newOVSDBServer(suite.T(), clientDBModel, clientSchema)
endpoint = fmt.Sprintf("unix:%s", sock)
require.FileExists(suite.T(), sock)
_, sbSock := newOVSDBServer(suite.T(), sbClientDBModel, sbClientSchema)
sbEndpoint := fmt.Sprintf("unix:%s", sbSock)
require.FileExists(suite.T(), sbSock)

ovnSBClient, err := newOvnSbClient(suite.T(), endpoint, 10)
ovnSBClient, err := newOvnSbClient(suite.T(), sbEndpoint, 10)
require.NoError(suite.T(), err)
suite.ovnSBClient = ovnSBClient
}
Expand Down Expand Up @@ -371,6 +393,10 @@ func (suite *OvnClientTestSuite) Test_BfdDelL3HAHandler() {
suite.testBfdDelL3HAHandler()
}

func (suite *OvnClientTestSuite) Test_MonitorBFDs() {
suite.testMonitorBFDs()
}

/* gateway_chassis unit test */
func (suite *OvnClientTestSuite) Test_CreateGatewayChassises() {
suite.testCreateGatewayChassises()
Expand Down

0 comments on commit 39067cd

Please sign in to comment.