VOL-1437 : Fix display of devices in CLI

Renamed state field in image download proto which caused
json marshalling to fail.

other updates
- unmarshal data properly when pulling data from kv in watch
- do not update unecessarily if watch data matches data in memory
- added ofagent target to python Makefile
- fixed grpc path to update log level which interfered with getdevice

Change-Id: I4fceeb539c3325b6754efe2b68251d83b7367211
diff --git a/db/model/non_persisted_revision.go b/db/model/non_persisted_revision.go
index 765bbaf..27d3d9a 100644
--- a/db/model/non_persisted_revision.go
+++ b/db/model/non_persisted_revision.go
@@ -250,9 +250,9 @@
 	npr.mutex.Lock()
 	defer npr.mutex.Unlock()
 
-	if npr.Config.Data != nil && npr.Config.Data == data {
+	if npr.Config.Data != nil && npr.Config.hashData(npr.Root, data) == npr.Config.Hash {
 		log.Debugw("stored-data-matches-latest", log.Fields{"stored": npr.Config.Data, "provided": data})
-		return nil
+		return npr
 	}
 
 	newRev := NonPersistedRevision{}
@@ -285,10 +285,13 @@
 			existChildMap[child.GetHash()] = i
 		}
 
-		// Identify the revisions that are not present in the existing list and add them
 		for _, newChild := range children {
 			if _, childExists := existChildMap[newChild.GetHash()]; !childExists {
+				// revision is not present in the existing list... add it
 				updatedRev.Children[name] = append(updatedRev.Children[name], newChild)
+			} else {
+				// replace
+				updatedRev.Children[name][existChildMap[newChild.GetHash()]] = newChild
 			}
 		}
 	} else {
diff --git a/db/model/persisted_revision.go b/db/model/persisted_revision.go
index 84b9569..98e80e4 100644
--- a/db/model/persisted_revision.go
+++ b/db/model/persisted_revision.go
@@ -131,7 +131,13 @@
 				if dataPair, err := pr.kvStore.Get(pr.GetHash()); err != nil || dataPair == nil {
 					log.Errorw("update-in-memory--key-retrieval-failed", log.Fields{"key": pr.GetHash(), "error": err})
 				} else {
-					pr.UpdateData(dataPair.Value, pr.GetBranch())
+					data := reflect.New(reflect.TypeOf(pr.GetData()).Elem())
+
+					if err := proto.Unmarshal(dataPair.Value.([]byte), data.Interface().(proto.Message)); err != nil {
+						log.Errorw("update-in-memory--unmarshal-failed", log.Fields{"key": pr.GetHash(), "error": err})
+					} else {
+						pr.UpdateData(data.Interface(), pr.GetBranch())
+					}
 				}
 
 			default: