Fix so that operational store correctly removes bridge-other-configs 56/18156/4
authorEd Warnicke <eaw@cisco.com>
Sun, 12 Apr 2015 00:06:02 +0000 (17:06 -0700)
committerEd Warnicke <eaw@cisco.com>
Mon, 13 Apr 2015 17:48:13 +0000 (10:48 -0700)
Before, if a bridge-other-configs entry was removed on ovsdb, we didn't
remove it from the operational store.

This is an artifact of using *merge* rather than *put*.
Using merge is *still* a good idea for us, but what was happening
was basically this.

Say we got a report in the operational store of

[bridge-other-configs1, bridge-other-configs2]

which we dutifully merged.

Then we got a report of
[bridge-other-configs2]

when that is *merged*... the protocol1 entry is left dangling,
because its a *merge*.  To compensate, we have to be *very*
specific about wanting to remove bridge-other-configs1.

Change-Id: Ic94b67b341bf7233c881e324f494c6701b622131
Signed-off-by: Ed Warnicke <eaw@cisco.com>
southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/transactions/md/OvsdbBridgeUpdateCommand.java

index 8fa3f4f4f0e5caa7c8efac1cdee10c3ea5169911..41079fc7f3d784059d51a97e499cf87d5bcb7ba1 100644 (file)
@@ -32,6 +32,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeExternalIdsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigs;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.BridgeOtherConfigsKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntry;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ProtocolEntryKey;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ManagedNodeEntry;
@@ -83,6 +84,7 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
             transaction.merge(LogicalDatastoreType.OPERATIONAL, bridgeIid, bridgeNode);
             deleteEntries(transaction, protocolEntriesToRemove(bridgeIid,bridge));
             deleteEntries(transaction, externalIdsToRemove(bridgeIid,bridge));
+            deleteEntries(transaction, bridgeOtherConfigsToRemove(bridgeIid,bridge));
         }
     }
 
@@ -93,6 +95,31 @@ public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
         }
     }
 
+    private List<InstanceIdentifier<BridgeOtherConfigs>> bridgeOtherConfigsToRemove(
+            InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
+        Preconditions.checkNotNull(bridgeIid);
+        Preconditions.checkNotNull(bridge);
+        List<InstanceIdentifier<BridgeOtherConfigs>> result =
+                new ArrayList<InstanceIdentifier<BridgeOtherConfigs>>();
+
+        Bridge oldBridge = oldBridgeRows.get(bridge.getUuid());
+
+        if (oldBridge != null && oldBridge.getOtherConfigColumn() != null) {
+            for (Entry<String, String> otherConfig:
+                oldBridge.getOtherConfigColumn().getData().entrySet()) {
+                if (bridge.getOtherConfigColumn() == null
+                        || !bridge.getOtherConfigColumn().getData().containsKey(otherConfig.getKey())) {
+                    InstanceIdentifier<BridgeOtherConfigs> iid = bridgeIid
+                            .augmentation(OvsdbBridgeAugmentation.class)
+                            .child(BridgeOtherConfigs.class,
+                                    new BridgeOtherConfigsKey(otherConfig.getKey()));
+                    result.add(iid);
+                }
+            }
+        }
+        return result;
+    }
+
     private List<InstanceIdentifier<BridgeExternalIds>> externalIdsToRemove(
             InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
         Preconditions.checkNotNull(bridgeIid);