diff options
author | Magesh GV <mageshgv@gmail.com> | 2019-09-26 18:12:10 -0700 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-10-01 08:28:26 +0900 |
commit | 22193807af57c4919ead94bc4c3c3ae022c2e99e (patch) | |
tree | 162fbe71467f9647c857f07641392aed5609afed /pkg | |
parent | 74266996792c5abc598251334ad40eaf72565044 (diff) |
Fix crash on nonexistent vrf delete
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/server/server.go | 8 | ||||
-rw-r--r-- | pkg/server/server_test.go | 25 |
2 files changed, 30 insertions, 3 deletions
diff --git a/pkg/server/server.go b/pkg/server/server.go index d1257cda..d6c54e10 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -2206,9 +2206,11 @@ func (s *BgpServer) DeleteVrf(ctx context.Context, r *api.DeleteVrfRequest) erro return fmt.Errorf("failed to delete VRF %s: neighbor %s is in use", name, n.ID()) } } - vrfMplsLabel := s.globalRib.Vrfs[name].MplsLabel - if vrfMplsLabel > 0 { - s.zclient.releaseMplsLabel(vrfMplsLabel) + + if vrf, ok := s.globalRib.Vrfs[name]; ok { + if vrf.MplsLabel > 0 { + s.zclient.releaseMplsLabel(vrf.MplsLabel) + } } pathList, err := s.globalRib.DeleteVrf(name) if err != nil { diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index ba1489f1..0c005efb 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -1439,4 +1439,29 @@ func TestAddDeletePath(t *testing.T) { assert.Equal(t, len(listRib()), 1) assert.Equal(t, len(s.uuidMap), 1) assert.NotEqual(t, u, r.Uuid) + s.StopBgp(context.Background(), &api.StopBgpRequest{}) +} + +func TestDeleteNonExistingVrf(t *testing.T) { + log.SetLevel(log.DebugLevel) + + s := runNewServer(1, "1.1.1.1", 10179) + addVrf(t, s, "vrf1", "111:111", 1) + req := &api.DeleteVrfRequest{Name: "Invalidvrf"} + if err := s.DeleteVrf(context.Background(), req); err == nil { + t.Fatal("Did not raise error for invalid vrf deletion.", err) + } + s.StopBgp(context.Background(), &api.StopBgpRequest{}) +} + +func TestDeleteVrf(t *testing.T) { + log.SetLevel(log.DebugLevel) + + s := runNewServer(1, "1.1.1.1", 10179) + addVrf(t, s, "vrf1", "111:111", 1) + req := &api.DeleteVrfRequest{Name: "vrf1"} + if err := s.DeleteVrf(context.Background(), req); err != nil { + t.Fatal("Vrf delete failed", err) + } + s.StopBgp(context.Background(), &api.StopBgpRequest{}) } |