Fixed GDP ignoring pipeconf passed via netcfg

Caused by recent refactoring. It was always using the default one at
device connection.

Change-Id: I8ddf99a8bd2d996dd3e58f93cbc7b23e324fe875
diff --git a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
index 29b86c3..ad0d388 100644
--- a/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
+++ b/providers/general/device/src/main/java/org/onosproject/provider/general/device/impl/GeneralDeviceProvider.java
@@ -548,21 +548,20 @@
     }
 
     private PiPipeconf getPipeconf(DeviceId deviceId, PiPipelineProgrammable pipelineProg) {
-        PiPipeconfId pipeconfId = piPipeconfService.ofDevice(deviceId).orElseGet(() -> {
-            // No pipeconf has been associated with this device.
+        PiPipeconfId pipeconfId = getPipeconfFromCfg(deviceId);
+        if (pipeconfId == null || pipeconfId.id().isEmpty()) {
+            // No pipeconf has been provided in the cfg.
             // Check if device driver provides a default one.
             if (pipelineProg.getDefaultPipeconf().isPresent()) {
-                PiPipeconf defaultPipeconf = pipelineProg.getDefaultPipeconf().get();
+                final PiPipeconf defaultPipeconf = pipelineProg.getDefaultPipeconf().get();
                 log.info("Using default pipeconf {} for {}", defaultPipeconf.id(), deviceId);
-                return defaultPipeconf.id();
+                pipeconfId = defaultPipeconf.id();
             } else {
+                log.warn("Device {} is pipeline programmable but no pipeconf can be associated to it", deviceId);
                 return null;
             }
-        });
-        if (pipeconfId == null) {
-            log.warn("Device {} is pipeline programmable but no pipeconf can be associated to it", deviceId);
-            return null;
         }
+        // Check if registered
         if (!piPipeconfService.getPipeconf(pipeconfId).isPresent()) {
             log.warn("Pipeconf {} is not registered", pipeconfId);
             return null;
@@ -772,6 +771,15 @@
         cfgService.getSubjects(DeviceId.class, GeneralProviderDeviceConfig.class).forEach(this::checkAndConnect);
     }
 
+    private PiPipeconfId getPipeconfFromCfg(DeviceId deviceId) {
+        PiPipeconfConfig config = cfgService.getConfig(
+                deviceId, PiPipeconfConfig.class);
+        if (config == null) {
+            return null;
+        }
+        return config.piPipeconfId();
+    }
+
     private void checkAndConnect(DeviceId deviceId) {
         // Let's try and reconnect to a device which is stored in cfg.
         // One of the following conditions must be satisfied: