VOL-1434 - Fix OLT disable

- Add admin_state to OpenOLT adapter.
- Core not to delete flows on device disable as flow removal
(if needed) should be initiated from ONOS.
- Ignore indications when admin disabled.

Change-Id: Id846ac0f26ebba53f1f7bc30f60bc131d19756ca
diff --git a/voltha/adapters/openolt/openolt_device.py b/voltha/adapters/openolt/openolt_device.py
index 07f49cd..7911265 100644
--- a/voltha/adapters/openolt/openolt_device.py
+++ b/voltha/adapters/openolt/openolt_device.py
@@ -83,6 +83,8 @@
     def __init__(self, **kwargs):
         super(OpenoltDevice, self).__init__()
 
+        self.admin_state = "up"
+
         self.adapter_agent = kwargs['adapter_agent']
         self.device_num = kwargs['device_num']
         device = kwargs['device']
@@ -355,6 +357,18 @@
             else:
                 self.log.debug("rx indication", indication=ind)
 
+                if self.admin_state is "down":
+                    if ind.HasField('intf_oper_ind') \
+                            and (ind.intf_oper_ind.type == "nni"):
+                        self.log.warn('olt is admin down, allow nni ind',
+                                      admin_state=self.admin_state,
+                                      indications=ind)
+                    else:
+                        self.log.warn('olt is admin down, ignore indication',
+                                      admin_state=self.admin_state,
+                                      indications=ind)
+                        continue
+
                 # indication handlers run in the main event loop
                 if ind.HasField('olt_ind'):
                     reactor.callFromThread(self.olt_indication, ind.olt_ind)
@@ -387,6 +401,13 @@
                     self.log.warn('unknown indication type')
 
     def olt_indication(self, olt_indication):
+        '''
+        if self.admin_state is "up":
+            if olt_indication.oper_state == "up":
+                self.go_state_up()
+            elif olt_indication.oper_state == "down":
+                self.go_state_down()
+        '''
         if olt_indication.oper_state == "up":
             self.go_state_up()
         elif olt_indication.oper_state == "down":
@@ -959,8 +980,7 @@
         try:
             # Send grpc call
             self.stub.DisableOlt(openolt_pb2.Empty())
-            # The resulting indication will bring the OLT down
-            # self.go_state_down()
+            self.admin_state = "down"
             self.log.info('openolt device disabled')
         except Exception as e:
             self.log.error('Failure to disable openolt device', error=e)
@@ -997,6 +1017,7 @@
             self.log.error('Failure to reenable openolt device', error=e)
         else:
             self.log.info('openolt device reenabled')
+            self.admin_state = "up"
 
     def activate_onu(self, intf_id, onu_id, serial_number,
                      serial_number_str):
diff --git a/voltha/core/device_agent.py b/voltha/core/device_agent.py
index 77d341e..5466fa9 100644
--- a/voltha/core/device_agent.py
+++ b/voltha/core/device_agent.py
@@ -374,7 +374,7 @@
             self.log.debug('disable-device', device=device, dry_run=dry_run)
             if not dry_run:
                 # Remove all flows before disabling device
-                self._delete_all_flows()
+                # self._delete_all_flows()
                 yield self.adapter_agent.disable_device(device)
         except Exception, e:
             self.log.exception('error', e=e)