VOL-2727: Only attempt to add tcont/gem if its actually new

When adding the tcont or gem to the handler
pon cache return true or false if its actually unique
and added to the cache.  This prevents the tp task
from adding potentially the same alloc id to a different
tcont id

Also remove unused code.

Change-Id: Iee1b7698c84b0790c624fe67c32b6ea215c8eab5
diff --git a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
index b5789aa..acfafe2 100644
--- a/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
+++ b/python/adapters/brcm_openomci_onu/brcm_openomci_onu_handler.py
@@ -381,9 +381,11 @@
 
         tcont = OnuTCont.create(self, tcont=tcontdict)
 
-        self._pon.add_tcont(tcont)
-        new_tconts.append(tcont)
-        self.log.debug('pon-add-tcont', tcont=tcont)
+        success = self._pon.add_tcont(tcont)
+        if success:
+            new_tconts.append(tcont)
+            self.log.debug('pon-add-tcont', tcont=tcont)
+
         return new_tconts
 
     # Called when there is an olt up indication, providing the gem port id chosen by the olt handler
@@ -419,11 +421,11 @@
             gemdict['uni_id'] = uni_id
 
             gem_port = OnuGemPort.create(self, gem_port=gemdict)
-            new_gem_ports.append(gem_port)
 
-            self._pon.add_gem_port(gem_port, True)
-
-            self.log.debug('pon-add-gemport', gem_port=gem_port)
+            success = self._pon.add_gem_port(gem_port, True)
+            if success:
+                new_gem_ports.append(gem_port)
+                self.log.debug('pon-add-gemport', gem_port=gem_port)
 
         return new_gem_ports
 
@@ -527,6 +529,9 @@
                 self.log.info('downloading-tech-profile-configuration', uni_id=uni_id, tp_id=tp_id)
                 self.log.debug("tconts-gems-to-install", tconts=tconts, gem_ports=gem_ports)
 
+                self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
+                self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
+
                 self._tp_service_specific_task[uni_id][tp_path] = \
                     BrcmTpSetupTask(self.omci_agent, self, uni_id, tconts, gem_ports, tp_id)
                 self._deferred = \
@@ -661,14 +666,14 @@
             # due to additional tasks on different UNIs. So, it we cannot use the pon_port affter
             # this initializer
             tcont = None
-            self.log.debug("tconts", tconts=list(self.pon_port.tconts.values()))
+            self.log.debug("current-cached-tconts", tconts=list(self.pon_port.tconts.values()))
             for tc in list(self.pon_port.tconts.values()):
                 if tc.alloc_id == alloc_id:
                     tcont = tc
                     self.pon_port.remove_tcont(tc.alloc_id, False)
 
             gem_port = None
-            self.log.debug("gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
+            self.log.debug("current-cached-gem-ports", gem_ports=list(self.pon_port.gem_ports.values()))
             for gp in list(self.pon_port.gem_ports.values()):
                 if gp.gem_id == gem_port_id:
                     gem_port = gp
@@ -726,7 +731,7 @@
         self._pm_metrics.update(pm_config)
 
     def remove_onu_flows(self, device, flows):
-        self.log.debug('remove_onu_flows', device_id=device.id)
+        self.log.debug('remove-onu-flows')
 
         # no point in removing omci flows if the device isnt reachable
         if device.connect_status != ConnectStatus.REACHABLE or \
@@ -791,13 +796,7 @@
                     self.log.exception('failed-to-remove-flow', e=e)
 
     def add_onu_flows(self, device, flows):
-        self.log.debug('function-entry', flows=flows)
-
-        #
-        # We need to proxy through the OLT to get to the ONU
-        # Configuration from here should be using OMCI
-        #
-        # self.log.info('bulk-flow-update', device_id=device.id, flows=flows)
+        self.log.debug('add-onu-flows')
 
         # no point in pushing omci flows if the device isnt reachable
         if device.connect_status != ConnectStatus.REACHABLE or \
diff --git a/python/adapters/brcm_openomci_onu/pon_port.py b/python/adapters/brcm_openomci_onu/pon_port.py
index f644ec8..634fd7e 100644
--- a/python/adapters/brcm_openomci_onu/pon_port.py
+++ b/python/adapters/brcm_openomci_onu/pon_port.py
@@ -171,32 +171,14 @@
         """
 
         if not self._valid:
-            return  # Deleting
+            return False # Deleting
 
         if not reflow and tcont.alloc_id in self._tconts:
-            return  # already created
+            return False # already created
 
         self.log.info('add-tcont', tcont=tcont.alloc_id, reflow=reflow)
         self._tconts[tcont.alloc_id] = tcont
-
-    def update_tcont_td(self, alloc_id, new_td):
-
-        tcont = self._tconts.get(alloc_id)
-
-        if tcont is None:
-            return  # not-found
-
-        tcont.traffic_descriptor = new_td
-
-        # TODO: Not yet implemented
-        # TODO: How does this affect ONU tcont settings?
-        # try:
-        #    results = yield tcont.add_to_hardware(self._handler.omci)
-        # except Exception as e:
-        #    self.log.exception('tcont', tcont=tcont, e=e)
-        #    # May occur with xPON provisioning, use hw-resync to recover
-        #    results = 'resync needed'
-        # returnValue(results)
+        return True
 
     @inlineCallbacks
     def remove_tcont(self, alloc_id, remove_from_hw=True):
@@ -234,15 +216,16 @@
         """
 
         if not self._valid:
-            return  # Deleting
+            return False # Deleting
 
         if not reflow and (gem_port.gem_id, gem_port.direction) in self._gem_ports:
-            return  # nop
+            return False # nop
 
         # The gem_port entity id is set to be same as gem_id
         gem_port.entity_id = gem_port.gem_id
         self.log.info('add-gem-port', gem_port=gem_port, reflow=reflow)
         self._gem_ports[(gem_port.gem_id, gem_port.direction)] = gem_port
+        return True
 
     @inlineCallbacks
     def remove_gem_id(self, gem_id, direction, remove_from_hw=True):