From 281681924330d996eca988752f3cd95ae1910210 Mon Sep 17 00:00:00 2001 From: "Saikumar, Banoth" Date: Wed, 17 Apr 2024 13:24:44 +0100 Subject: [PATCH] fix(evpn-bridge): missing resource version check for the objects, also return no subscribers found for object if not found any Signed-off-by: Saikumar, Banoth --- pkg/LinuxCIModule/lci.go | 15 +++++++++++++++ pkg/LinuxGeneralModule/lgm.go | 27 ++++++++++++++++++--------- pkg/LinuxVendorModule/ipu/ipu.go | 15 +++++++++++++++ pkg/frr/frr.go | 4 ---- pkg/infradb/infradb.go | 12 ++++++++++++ 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/pkg/LinuxCIModule/lci.go b/pkg/LinuxCIModule/lci.go index 21b47e12..c74f9713 100644 --- a/pkg/LinuxCIModule/lci.go +++ b/pkg/LinuxCIModule/lci.go @@ -46,6 +46,21 @@ func handlebp(objectData *eventbus.ObjectData) { log.Printf("LCI : GetBP error: %s\n", err) return } + if objectData.ResourceVersion != BP.ResourceVersion { + log.Printf("LVM: Mismatch in resoruce version %+v\n and bp resource version %+v\n", objectData.ResourceVersion, BP.ResourceVersion) + comp.Name = lciComp + comp.CompStatus = common.ComponentStatusError + if comp.Timer == 0 { + comp.Timer = 2 * time.Second + } else { + comp.Timer *= 2 + } + err := infradb.UpdateBPStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) + if err != nil { + log.Printf("error in updating bp status: %s\n", err) + } + return + } if len(BP.Status.Components) != 0 { for i := 0; i < len(BP.Status.Components); i++ { if BP.Status.Components[i].Name == "lci" { diff --git a/pkg/LinuxGeneralModule/lgm.go b/pkg/LinuxGeneralModule/lgm.go index 42da0acf..ec64e51a 100644 --- a/pkg/LinuxGeneralModule/lgm.go +++ b/pkg/LinuxGeneralModule/lgm.go @@ -89,12 +89,25 @@ func (h *ModulelgmHandler) HandleEvent(eventType string, objectData *eventbus.Ob func handleLB(objectData *eventbus.ObjectData) { var comp common.Component lb, err := infradb.GetLB(objectData.Name) - if err == nil { - log.Printf("LGM : GetLB Name: %s\n", lb.Name) - } else { + if err != nil { log.Printf("LGM: GetLB error: %s %s\n", err, objectData.Name) return } + if objectData.ResourceVersion != lb.ResourceVersion { + log.Printf("LGM: Mismatch in resoruce version %+v\n and lb resource version %+v\n", objectData.ResourceVersion, lb.ResourceVersion) + comp.Name = lgmComp + comp.CompStatus = common.ComponentStatusError + if comp.Timer == 0 { + comp.Timer = 2 * time.Second + } else { + comp.Timer *= 2 + } + err := infradb.UpdateLBStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) + if err != nil { + log.Printf("error in updating lb status: %s\n", err) + } + return + } if len(lb.Status.Components) != 0 { for i := 0; i < len(lb.Status.Components); i++ { if lb.Status.Components[i].Name == lgmComp { @@ -148,9 +161,7 @@ func handleLB(objectData *eventbus.ObjectData) { func handlesvi(objectData *eventbus.ObjectData) { var comp common.Component svi, err := infradb.GetSvi(objectData.Name) - if err == nil { - log.Printf("LGM : GetSvi Name: %s\n", svi.Name) - } else { + if err != nil { log.Printf("LGM: GetSvi error: %s %s\n", err, objectData.Name) return } @@ -221,9 +232,7 @@ func handlesvi(objectData *eventbus.ObjectData) { func handlevrf(objectData *eventbus.ObjectData) { var comp common.Component vrf, err := infradb.GetVrf(objectData.Name) - if err == nil { - log.Printf("LGM : GetVRF Name: %s\n", vrf.Name) - } else { + if err != nil { log.Printf("LGM: GetVRF error: %s %s\n", err, objectData.Name) return } diff --git a/pkg/LinuxVendorModule/ipu/ipu.go b/pkg/LinuxVendorModule/ipu/ipu.go index d8d669e2..d08dfee5 100644 --- a/pkg/LinuxVendorModule/ipu/ipu.go +++ b/pkg/LinuxVendorModule/ipu/ipu.go @@ -76,6 +76,21 @@ func handlebp(objectData *eventbus.ObjectData) { log.Printf("LVM : GetBP error: %s\n", err) return } + if objectData.ResourceVersion != bp.ResourceVersion { + log.Printf("LVM: Mismatch in resoruce version %+v\n and bp resource version %+v\n", objectData.ResourceVersion, bp.ResourceVersion) + comp.Name = lvmComp + comp.CompStatus = common.ComponentStatusError + if comp.Timer == 0 { + comp.Timer = 2 * time.Second + } else { + comp.Timer *= 2 + } + err := infradb.UpdateBPStatus(objectData.Name, objectData.ResourceVersion, objectData.NotificationID, nil, comp) + if err != nil { + log.Printf("error in updating bp status: %s\n", err) + } + return + } if len(bp.Status.Components) != 0 { for i := 0; i < len(bp.Status.Components); i++ { if bp.Status.Components[i].Name == lvmComp { diff --git a/pkg/frr/frr.go b/pkg/frr/frr.go index 7ea2e3c6..3ea9f568 100644 --- a/pkg/frr/frr.go +++ b/pkg/frr/frr.go @@ -56,8 +56,6 @@ func handlesvi(objectData *eventbus.ObjectData) { return } - log.Printf("FRR :GetSvi Name: %s\n", svi.Name) - if objectData.ResourceVersion != svi.ResourceVersion { log.Printf("FRR: Mismatch in resoruce version %+v\n and svi resource version %+v\n", objectData.ResourceVersion, svi.ResourceVersion) comp.Name = frrComp @@ -132,8 +130,6 @@ func handlevrf(objectData *eventbus.ObjectData) { return } - log.Printf("FRR :GetVRF Name: %s\n", vrf.Name) - if len(vrf.Status.Components) != 0 { for i := 0; i < len(vrf.Status.Components); i++ { if vrf.Status.Components[i].Name == frrComp { diff --git a/pkg/infradb/infradb.go b/pkg/infradb/infradb.go index 4302a10f..1a34e584 100644 --- a/pkg/infradb/infradb.go +++ b/pkg/infradb/infradb.go @@ -74,6 +74,7 @@ func CreateLB(lb *LogicalBridge) error { subscribers := eventbus.EBus.GetSubscribers("logical-bridge") if subscribers == nil { log.Println("CreateLB(): No subscribers for Logical Bridge objects") + return errors.New("no subscribers found for logical bridge") } log.Printf("CreateLB(): Create Logical Bridge: %+v\n", lb) @@ -144,6 +145,7 @@ func DeleteLB(name string) error { subscribers := eventbus.EBus.GetSubscribers("logical-bridge") if subscribers == nil { log.Println("DeleteLB(): No subscribers for Logical Bridge objects") + return errors.New("no subscribers found for logical bridge") } lb := LogicalBridge{} @@ -242,6 +244,7 @@ func UpdateLB(lb *LogicalBridge) error { subscribers := eventbus.EBus.GetSubscribers("logical-bridge") if subscribers == nil { log.Println("UpdateLB(): No subscribers for Logical Bridge objects") + return errors.New("no subscribers found for logical bridge") } err := infradb.client.Set(lb.Name, lb) @@ -386,6 +389,7 @@ func CreateBP(bp *BridgePort) error { subscribers := eventbus.EBus.GetSubscribers("bridge-port") if subscribers == nil { log.Println("CreateBP(): No subscribers for Bridge Port objects") + return errors.New("no subscribers found for bridge port") } // Dimitris: Do I need to add here a check for MAC uniquness in of BP ? @@ -481,6 +485,7 @@ func DeleteBP(name string) error { subscribers := eventbus.EBus.GetSubscribers("bridge-port") if subscribers == nil { log.Println("DeleteBP(): No subscribers for Bridge Port objects") + return errors.New("no subscribers found for bridge port") } bp := BridgePort{} @@ -571,6 +576,7 @@ func UpdateBP(bp *BridgePort) error { subscribers := eventbus.EBus.GetSubscribers("bridge-port") if subscribers == nil { log.Println("UpdateBP(): No subscribers for Bridge Port objects") + return errors.New("no subscribers found for bridge port") } err := infradb.client.Set(bp.Name, bp) @@ -726,6 +732,7 @@ func CreateVrf(vrf *Vrf) error { subscribers := eventbus.EBus.GetSubscribers("vrf") if subscribers == nil { log.Println("CreateVrf(): No subscribers for Vrf objects") + return errors.New("no subscribers found for vrf") } log.Printf("CreateVrf(): Create Vrf: %+v\n", vrf) @@ -798,6 +805,7 @@ func DeleteVrf(name string) error { subscribers := eventbus.EBus.GetSubscribers("vrf") if subscribers == nil { log.Println("DeleteVrf(): No subscribers for Vrf objects") + return errors.New("no subscribers found for vrf") } vrf := Vrf{} @@ -890,6 +898,7 @@ func UpdateVrf(vrf *Vrf) error { subscribers := eventbus.EBus.GetSubscribers("vrf") if subscribers == nil { log.Println("CreateVrf(): No subscribers for Vrf objects") + return errors.New("no subscribers found for vrf") } err := infradb.client.Set(vrf.Name, vrf) @@ -1035,6 +1044,7 @@ func CreateSvi(svi *Svi) error { subscribers := eventbus.EBus.GetSubscribers("svi") if subscribers == nil { log.Println("CreateSvi(): No subscribers for SVI objects") + return errors.New("no subscribers found for svi") } log.Printf("CreateSvi(): Create SVI: %+v\n", svi) @@ -1125,6 +1135,7 @@ func DeleteSvi(name string) error { subscribers := eventbus.EBus.GetSubscribers("svi") if subscribers == nil { log.Println("DeleteSvi(): No subscribers for SVI objects") + return errors.New("no subscribers found for svi") } svi := Svi{} @@ -1212,6 +1223,7 @@ func UpdateSvi(svi *Svi) error { subscribers := eventbus.EBus.GetSubscribers("svi") if subscribers == nil { log.Println("UpdateSvi(): No subscribers for SVI objects") + return errors.New("no subscribers found for svi") } err := infradb.client.Set(svi.Name, svi)