[VOL-4523] ONU SW download fails if the already present stdby image is NOT valid

Change-Id: Ie2c9e96476355af9828f9a8e6fd4256837366573
diff --git a/VERSION b/VERSION
index 3fc585e..43bc05d 100755
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.1.2-dev262
+2.1.2-dev263
diff --git a/internal/pkg/common/interfaces.go b/internal/pkg/common/interfaces.go
index e1ef21f..39b37ba 100755
--- a/internal/pkg/common/interfaces.go
+++ b/internal/pkg/common/interfaces.go
@@ -21,6 +21,7 @@
 	"context"
 	"time"
 
+	me "github.com/opencord/omci-lib-go/v2/generated"
 	"github.com/opencord/voltha-lib-go/v7/pkg/db"
 	"github.com/opencord/voltha-lib-go/v7/pkg/events/eventif"
 	"github.com/opencord/voltha-openonu-adapter-go/internal/pkg/devdb"
@@ -138,10 +139,7 @@
 	IncrementMibDataSync(context.Context)
 
 	GetActiveImageMeID(context.Context) (uint16, error)
-	LockMutexOnuSwImageIndications()
-	UnlockMutexOnuSwImageIndications()
-	GetOnuSwImageIndications() SswImageIndications
-	SetOnuSwImageIndications(SswImageIndications)
+	HandleSwImageIndications(context.Context, uint16, me.AttributeValueMap)
 	GetPersActiveSwVersion() string
 	SetPersActiveSwVersion(string)
 	GetActiveImageVersion(context.Context) string
diff --git a/internal/pkg/mib/mib_sync.go b/internal/pkg/mib/mib_sync.go
index 03937c4..d3f2712 100755
--- a/internal/pkg/mib/mib_sync.go
+++ b/internal/pkg/mib/mib_sync.go
@@ -752,7 +752,7 @@
 						oo.deviceID, entityID)
 				}
 				// need to use function for go lint complexity
-				oo.handleSwImageIndications(ctx, entityID, meAttributes)
+				oo.HandleSwImageIndications(ctx, entityID, meAttributes)
 				return nil
 			case "IpHostConfigData":
 				oo.mutexLastTxParamStruct.RUnlock()
@@ -795,7 +795,8 @@
 	return err
 }
 
-func (oo *OnuDeviceEntry) handleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
+//HandleSwImageIndications updates onuSwImageIndications with the ONU data just received
+func (oo *OnuDeviceEntry) HandleSwImageIndications(ctx context.Context, entityID uint16, meAttributes me.AttributeValueMap) {
 	imageIsCommitted := meAttributes["IsCommitted"].(uint8)
 	imageIsActive := meAttributes["IsActive"].(uint8)
 	imageVersion := cmn.TrimStringFromMeOctet(meAttributes["Version"])
diff --git a/internal/pkg/mib/onu_device_entry.go b/internal/pkg/mib/onu_device_entry.go
index e956622..26c346d 100755
--- a/internal/pkg/mib/onu_device_entry.go
+++ b/internal/pkg/mib/onu_device_entry.go
@@ -945,26 +945,6 @@
 	return oo.omciRebootMessageReceivedChannel
 }
 
-// LockMutexOnuSwImageIndications - TODO: add comment
-func (oo *OnuDeviceEntry) LockMutexOnuSwImageIndications() {
-	oo.mutexOnuSwImageIndications.Lock()
-}
-
-// UnlockMutexOnuSwImageIndications - TODO: add comment
-func (oo *OnuDeviceEntry) UnlockMutexOnuSwImageIndications() {
-	oo.mutexOnuSwImageIndications.Unlock()
-}
-
-// GetOnuSwImageIndications - TODO: add comment
-func (oo *OnuDeviceEntry) GetOnuSwImageIndications() cmn.SswImageIndications {
-	return oo.onuSwImageIndications
-}
-
-// SetOnuSwImageIndications - TODO: add comment
-func (oo *OnuDeviceEntry) SetOnuSwImageIndications(value cmn.SswImageIndications) {
-	oo.onuSwImageIndications = value
-}
-
 // GetPersActiveSwVersion - TODO: add comment
 func (oo *OnuDeviceEntry) GetPersActiveSwVersion() string {
 	oo.MutexPersOnuConfig.RLock()
diff --git a/internal/pkg/swupg/onu_image_status.go b/internal/pkg/swupg/onu_image_status.go
index 0da9e0b..eb4021f 100755
--- a/internal/pkg/swupg/onu_image_status.go
+++ b/internal/pkg/swupg/onu_image_status.go
@@ -109,7 +109,6 @@
 		images.Items = append(images.Items, &image)
 	}
 	logger.Debugw(ctx, "images of the ONU", log.Fields{"images": images})
-	oo.updateOnuSwImageIndications(ctx, &images)
 	oo.updateOnuSwImagePersistentData(ctx)
 	return &images, nil
 }
@@ -214,15 +213,16 @@
 	meAttributes := msgObj.Attributes
 	logger.Debugw(ctx, "processAttributesReceived", log.Fields{"attributes": meAttributes, "device-id": oo.deviceID})
 
-	for k := range oo.requestedAttributes {
-
-		if msgObj.Result != me.Success && k != cImgProductCode && k != cImgImageHash {
+	if _, ok := oo.requestedAttributes[cImgVersion]; ok {
+		if msgObj.Result != me.Success {
 			logger.Errorw(ctx, "processAttributesReceived retrieval of mandatory attributes failed",
 				log.Fields{"device-id": oo.deviceID})
 			return fmt.Errorf("process-image-status-response-error")
 		}
+		oo.pDevEntry.HandleSwImageIndications(ctx, msgObj.EntityInstance, meAttributes)
+	}
+	for k := range oo.requestedAttributes {
 		switch k {
-
 		// mandatory attributes
 		case cImgIsCommitted:
 			if meAttributes[cImgIsCommitted].(uint8) == cmn.SwIsCommitted {
@@ -270,50 +270,6 @@
 	return nil
 }
 
-func (oo *OnuImageStatus) updateOnuSwImageIndications(ctx context.Context, images *voltha.OnuImages) {
-
-	oo.pDevEntry.LockMutexOnuSwImageIndications()
-	onuSwImageIndications := oo.pDevEntry.GetOnuSwImageIndications()
-	validActiveImageFound := false
-	for i := cmn.FirstSwImageMeID; i <= cmn.SecondSwImageMeID; i++ {
-		if images.Items[i].IsActive && images.Items[i].IsValid {
-			onuSwImageIndications.ActiveEntityEntry.EntityID = uint16(i)
-			onuSwImageIndications.ActiveEntityEntry.Valid = images.Items[i].IsValid
-			onuSwImageIndications.ActiveEntityEntry.Version = images.Items[i].Version
-			if images.Items[i].IsCommited {
-				onuSwImageIndications.ActiveEntityEntry.IsCommitted = cmn.SwIsCommitted
-			} else {
-				onuSwImageIndications.ActiveEntityEntry.IsCommitted = cmn.SwIsUncommitted
-			}
-			validActiveImageFound = true
-			break
-		}
-	}
-	if !validActiveImageFound {
-		onuSwImageIndications.ActiveEntityEntry.Valid = false
-	}
-	validInactiveImageFound := false
-	for i := cmn.FirstSwImageMeID; i <= cmn.SecondSwImageMeID; i++ {
-		if !images.Items[i].IsActive && images.Items[i].IsValid {
-			onuSwImageIndications.InActiveEntityEntry.EntityID = uint16(i)
-			onuSwImageIndications.InActiveEntityEntry.Valid = images.Items[i].IsValid
-			onuSwImageIndications.InActiveEntityEntry.Version = images.Items[i].Version
-			if images.Items[i].IsCommited {
-				onuSwImageIndications.InActiveEntityEntry.IsCommitted = cmn.SwIsCommitted
-			} else {
-				onuSwImageIndications.InActiveEntityEntry.IsCommitted = cmn.SwIsUncommitted
-			}
-			validInactiveImageFound = true
-			break
-		}
-	}
-	if !validInactiveImageFound {
-		onuSwImageIndications.InActiveEntityEntry.Valid = false
-	}
-	oo.pDevEntry.SetOnuSwImageIndications(onuSwImageIndications)
-	oo.pDevEntry.UnlockMutexOnuSwImageIndications()
-}
-
 func (oo *OnuImageStatus) updateOnuSwImagePersistentData(ctx context.Context) {
 
 	activeImageVersion := oo.pDevEntry.GetActiveImageVersion(ctx)