VOL-2514: Clean up mib download task under load

- under load mib download task is falsely tried again
  seemingly due to exception handling.  simplify a bit
  now that most work has been removed from this task

- also strobe watchdog after successful omci_cc call

- do not start pm/test jobs until mib is in sync
  also start at a random offset

- any task failures now try again in the same way and do
  not overwrite the instance deferred.
  also retry at a random offset

- one less core reason update

Change-Id: I2563f9228194c8a605e1981cb115b499d3c89c4d
diff --git a/python/adapters/brcm_openomci_onu/omci/brcm_mib_download_task.py b/python/adapters/brcm_openomci_onu/omci/brcm_mib_download_task.py
index b0fe3d8..678fd54 100644
--- a/python/adapters/brcm_openomci_onu/omci/brcm_mib_download_task.py
+++ b/python/adapters/brcm_openomci_onu/omci/brcm_mib_download_task.py
@@ -141,8 +141,8 @@
                        error_mask=error_mask, failed_mask=failed_mask,
                        unsupported_mask=unsupported_mask)
 
+        self.strobe_watchdog()
         if status == RC.Success:
-            self.strobe_watchdog()
             return True
 
         elif status == RC.InstanceExists:
@@ -161,37 +161,17 @@
         try:
             self.log.info('perform-download')
 
-            if self._handler.enabled and len(self._handler.uni_ports) > 0:
-                yield self._handler.core_proxy.device_reason_update(self.device_id, 'performing-initial-mib-download')
+            # Provision the initial bridge configuration
+            yield self.perform_initial_bridge_setup()
 
-            try:
-                # Lock the UNI ports to prevent any alarms during initial configuration
-                # of the ONU
-                self.strobe_watchdog()
-
+            for uni_port in self._handler.uni_ports:
                 # Provision the initial bridge configuration
-                yield self.perform_initial_bridge_setup()
+                yield self.perform_uni_initial_bridge_setup(uni_port)
 
-                for uni_port in self._handler.uni_ports:
-                    # Provision the initial bridge configuration
-                    yield self.perform_uni_initial_bridge_setup(uni_port)
-
-                self.deferred.callback('initial-download-success')
-
-            except TimeoutError as e:
-                self.log.error('initial-download-failure', e=e)
-                self.deferred.errback(failure.Failure(e))
-
-            except Exception as e:
-                self.log.exception('initial-download-failure', e=e)
-                self.deferred.errback(failure.Failure(e))
-
-            else:
-                e = MibResourcesFailure('Required resources are not available',
-                                        len(self._handler.uni_ports))
-                self.deferred.errback(failure.Failure(e))
-        except BaseException as e:
-            self.log.debug('cannot-start-mib-download', exception=e)
+            self.deferred.callback('initial-download-success')
+        except Exception as e:
+            self.log.error('initial-download-failure', e=e)
+            self.deferred.errback(failure.Failure(e))
 
     @inlineCallbacks
     def perform_initial_bridge_setup(self):
diff --git a/python/adapters/brcm_openomci_onu/omci/brcm_uni_lock_task.py b/python/adapters/brcm_openomci_onu/omci/brcm_uni_lock_task.py
index 3884620..eb090e1 100644
--- a/python/adapters/brcm_openomci_onu/omci/brcm_uni_lock_task.py
+++ b/python/adapters/brcm_openomci_onu/omci/brcm_uni_lock_task.py
@@ -81,6 +81,7 @@
         super(BrcmUniLockTask, self).start()
         self._local_deferred = reactor.callLater(0, self.perform_lock)
 
+    @inlineCallbacks
     def perform_lock(self):
         """
         Perform the lock/unlock
@@ -99,29 +100,29 @@
                 for entity_id in pptp_list:
                     msg = PptpEthernetUniFrame(entity_id,
                                                attributes=dict(administrative_state=state))
-                    self._send_omci_msg(msg)
+                    yield self._send_omci_msg(msg)
 
                 for entity_id in veip_list:
                     msg = VeipUniFrame(entity_id,
                                        attributes=dict(administrative_state=state))
-                    self._send_omci_msg(msg)
+                    yield self._send_omci_msg(msg)
 
                 msg = OntGFrame(attributes={'administrative_state': state})
-                self._send_omci_msg(msg)
+                yield self._send_omci_msg(msg)
             else:
                 # ontg must be unlocked first, then unis
                 msg = OntGFrame(attributes={'administrative_state': state})
-                self._send_omci_msg(msg)
+                yield self._send_omci_msg(msg)
 
                 for entity_id in pptp_list:
                     msg = PptpEthernetUniFrame(entity_id,
                                                attributes=dict(administrative_state=state))
-                    self._send_omci_msg(msg)
+                    yield self._send_omci_msg(msg)
 
                 for entity_id in veip_list:
                     msg = VeipUniFrame(entity_id,
                                        attributes=dict(administrative_state=state))
-                    self._send_omci_msg(msg)
+                    yield self._send_omci_msg(msg)
 
             self.deferred.callback('setting-uni-lock-state-finished')