Andrea Campanella
Committed by Gerrit Code Review

ONOS-3829 Fixed bug with inconsistent parent's behaviours when merging drivers

Change-Id: If7b1924b034b0d8ce806410bb9efa4f5258c14f6
...@@ -20,6 +20,7 @@ import com.google.common.collect.Lists; ...@@ -20,6 +20,7 @@ import com.google.common.collect.Lists;
20 import com.google.common.collect.Maps; 20 import com.google.common.collect.Maps;
21 import org.slf4j.Logger; 21 import org.slf4j.Logger;
22 22
23 +import java.util.ArrayList;
23 import java.util.List; 24 import java.util.List;
24 import java.util.Map; 25 import java.util.Map;
25 import java.util.Objects; 26 import java.util.Objects;
...@@ -110,8 +111,20 @@ public class DefaultDriver implements Driver { ...@@ -110,8 +111,20 @@ public class DefaultDriver implements Driver {
110 // Merge the properties. 111 // Merge the properties.
111 ImmutableMap.Builder<String, String> properties = ImmutableMap.builder(); 112 ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
112 properties.putAll(this.properties).putAll(other.properties()); 113 properties.putAll(this.properties).putAll(other.properties());
114 + List<Driver> completeParents = new ArrayList<>();
113 115
114 - return new DefaultDriver(name, other.parents(), 116 + if (parents != null) {
117 + parents.forEach(parent -> other.parents().forEach(otherParent -> {
118 + if (otherParent.name().equals(parent.name())) {
119 + completeParents.add(parent.merge(otherParent));
120 + } else if (!completeParents.contains(otherParent)) {
121 + completeParents.add(otherParent);
122 + } else if (!completeParents.contains(parent)) {
123 + completeParents.add(parent);
124 + }
125 + }));
126 + }
127 + return new DefaultDriver(name, completeParents.size() > 0 ? completeParents : other.parents(),
115 manufacturer, hwVersion, swVersion, 128 manufacturer, hwVersion, swVersion,
116 ImmutableMap.copyOf(behaviours), properties.build()); 129 ImmutableMap.copyOf(behaviours), properties.build());
117 } 130 }
......