[SDFAB-622] Protect phased recovery from wrong port config

ifacename is used as key when changing the admin state of
a port through GNMI. This patch guarantees that we use the
state contained in the device store to fill the gnmi blob.
This results to be necessary because the requests coming
from the north may be incomplete (without port name).
When this happens, PortNumber class fills the name with
the number which is wrong for the GNMI devices

Change-Id: I308538ae30cfe3fbf62d42c9a059114e8ff5b4b3
diff --git a/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiPortAdminBehaviour.java b/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiPortAdminBehaviour.java
index 666d5b1..7a01ff0 100644
--- a/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiPortAdminBehaviour.java
+++ b/drivers/gnmi/src/main/java/org/onosproject/drivers/gnmi/OpenConfigGnmiPortAdminBehaviour.java
@@ -20,6 +20,7 @@
 import org.onosproject.gnmi.api.GnmiClient;
 import org.onosproject.gnmi.api.GnmiController;
 import org.onosproject.grpc.utils.AbstractGrpcHandlerBehaviour;
+import org.onosproject.net.Port;
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.behaviour.PortAdmin;
 
@@ -70,6 +71,22 @@
                      portNumber, deviceId);
             return;
         }
+
+        /* Requests coming from the north may come without name.
+           When this happens port name equals to port number */
+        if (!portNumber.hasName()) {
+            if (deviceService == null) {
+                log.warn("Cannot update port status of port {} on {} because the device " +
+                                "service is null", portNumber, deviceId);
+                return;
+            }
+            Port devicePort = deviceService.getPort(deviceId, portNumber);
+            if (devicePort != null) {
+                // Some devices may reject the config, make sure we act on the reported port
+                portNumber = devicePort.number();
+            }
+        }
+
         final Gnmi.Path path = Gnmi.Path.newBuilder()
                 .addElem(Gnmi.PathElem.newBuilder().setName("interfaces").build())
                 .addElem(Gnmi.PathElem.newBuilder().setName("interface")