[VOL-4045] Fix some race conditions in rw-core

This commit addresses only the race conditions seen during
testing.

Change-Id: I59859a5222c892453f3c089a181d4290e18f1863
diff --git a/rw_core/core/device/agent.go b/rw_core/core/device/agent.go
index 9358d8a..7e401aa 100755
--- a/rw_core/core/device/agent.go
+++ b/rw_core/core/device/agent.go
@@ -328,7 +328,13 @@
 	defer cancel()
 	var desc string
 	operStatus := &common.OperationResp{Code: common.OperationResp_OPERATION_FAILURE}
-	defer agent.logDeviceUpdate(ctx, rpc, prevState, &agent.device.AdminState, operStatus, &desc)
+	defer func() {
+		currAdminState := prevState
+		if d, _ := agent.getDeviceReadOnly(ctx); d != nil {
+			currAdminState = &d.AdminState
+		}
+		agent.logDeviceUpdate(ctx, rpc, prevState, currAdminState, operStatus, &desc)
+	}()
 	var rpce *voltha.RPCEvent
 	defer func() {
 		if rpce != nil {
@@ -383,7 +389,6 @@
 // enableDevice activates a preprovisioned or a disable device
 func (agent *Agent) enableDevice(ctx context.Context) error {
 	//To preserve and use oldDevice state as prev state in new device
-	prevDeviceState := agent.device.AdminState
 	var desc string
 	operStatus := &common.OperationResp{Code: common.OperationResp_OPERATION_FAILURE}
 
@@ -394,6 +399,8 @@
 	}
 	logger.Debugw(ctx, "enable-device", log.Fields{"device-id": agent.deviceID})
 
+	prevDeviceState := agent.device.AdminState
+
 	oldDevice := agent.getDeviceReadOnlyWithoutLock()
 
 	if oldDevice.AdminState == voltha.AdminState_ENABLED {