Fix for service activation and audit issues
Change-Id: I1517f9be1532f384f5236e8d6328c8fda93c1776
diff --git a/database/database.go b/database/database.go
index 0344e7d..664dce9 100644
--- a/database/database.go
+++ b/database/database.go
@@ -99,10 +99,16 @@
// DeleteAllUnderHashKey to delete all values under hash key
func (db *Database) DeleteAllUnderHashKey(ctx context.Context, hashKeyPrefix string) error {
- if err := db.kvc.Delete(ctx, hashKeyPrefix); err != nil {
+ kv, err := db.kvc.List(ctx, hashKeyPrefix)
+ if err != nil {
logger.Errorw(ctx, "The key path doesn't exist", log.Fields{"key": hashKeyPrefix, "Error": err})
return err
}
+ for key := range kv {
+ if err := db.kvc.Delete(ctx, key); err != nil {
+ logger.Errorw(ctx, "Delete key from DB Failed", log.Fields{"key": key, "Error": err})
+ }
+ }
return nil
}
@@ -539,7 +545,7 @@
// DelAllMeter to delete meter info
func (db *Database) DelAllMeter(ctx context.Context, device string) error {
- key := GetKeyPath(DevicePath) + device + "/" + MeterPath
+ key := fmt.Sprintf(GetKeyPath(DeviceMeterPath), device)
if err := db.DeleteAllUnderHashKey(ctx, key); err != nil {
logger.Warnw(ctx, "Delete All failed: The key doesn't exist", log.Fields{"key": key, "Error": err})
return err