VOL-951: Make OpenOLT adapter pep8

Change-Id: I0fb8ca6e7da4dd83b0149628b5fe57f140d62acf
diff --git a/voltha/adapters/openolt/openolt.py b/voltha/adapters/openolt/openolt.py
index 612ba60..45c8b8e 100644
--- a/voltha/adapters/openolt/openolt.py
+++ b/voltha/adapters/openolt/openolt.py
@@ -17,9 +17,8 @@
 """
 Openolt adapter.
 """
-import structlog
-from twisted.internet import reactor, defer
 from zope.interface import implementer
+import structlog
 
 from openolt_device import OpenoltDevice
 from voltha.adapters.interface import IAdapterInterface
@@ -28,12 +27,12 @@
 from voltha.protos.adapter_pb2 import AdapterConfig
 from voltha.protos.common_pb2 import LogLevel
 from voltha.protos.device_pb2 import DeviceType, DeviceTypes
-from voltha.protos.health_pb2 import HealthStatus
 from voltha.registry import registry
 
 _ = third_party
 log = structlog.get_logger()
 
+
 @implementer(IAdapterInterface)
 class OpenoltAdapter(object):
     name = 'openolt'
@@ -72,7 +71,8 @@
         return self.descriptor
 
     def device_types(self):
-        log.debug('get device_types', interface=self.interface, items=self.supported_device_types)
+        log.debug('get device_types', interface=self.interface,
+                  items=self.supported_device_types)
         return DeviceTypes(items=self.supported_device_types)
 
     def health(self):
@@ -80,7 +80,8 @@
         raise NotImplementedError()
 
     def change_master_state(self, master):
-        log.debug('change_master_state', interface=self.interface, master=master)
+        log.debug('change_master_state', interface=self.interface,
+                  master=master)
         raise NotImplementedError()
 
     def adopt_device(self, device):
@@ -109,10 +110,12 @@
         }
         try:
             reconciled_device = OpenoltDevice(**kwargs)
-            log.debug('reconciled-device-recreated', device_id=reconciled_device.device_id)
+            log.debug('reconciled-device-recreated',
+                      device_id=reconciled_device.device_id)
             self.devices[device.id] = reconciled_device
         except Exception as e:
-            log.error('Failed to reconcile OpenOLT device', error=e, exception_type=type(e).__name__)
+            log.error('Failed to reconcile OpenOLT device', error=e,
+                      exception_type=type(e).__name__)
             del self.devices[device.id]
             raise
         else:
@@ -161,7 +164,7 @@
         raise NotImplementedError()
 
     def self_test_device(self, device):
-        #from voltha.protos.voltha_pb2 import SelfTestResponse
+        # from voltha.protos.voltha_pb2 import SelfTestResponse
         raise NotImplementedError()
 
     def delete_device(self, device):
@@ -182,8 +185,8 @@
         return handler.update_flow_table(flows.items)
 
     def update_flows_incrementally(self, device, flow_changes, group_changes):
-        log.debug('update_flows_incrementally', device=device, flow_changes=flow_changes,
-                  group_changes=group_changes)
+        log.debug('update_flows_incrementally', device=device,
+                  flow_changes=flow_changes, group_changes=group_changes)
         raise NotImplementedError()
 
     def update_pm_config(self, device, pm_configs):
@@ -196,12 +199,14 @@
         handler.send_proxied_message(proxy_address, msg)
 
     def receive_proxied_message(self, proxy_address, msg):
-        log.debug('receive_proxied_message', proxy_address=proxy_address, msg=msg)
+        log.debug('receive_proxied_message', proxy_address=proxy_address,
+                  msg=msg)
         raise NotImplementedError()
 
     def receive_packet_out(self, logical_device_id, egress_port_no, msg):
         log.debug('packet-out', logical_device_id=logical_device_id,
                   egress_port_no=egress_port_no, msg_len=len(msg))
+
         def ldi_to_di(ldi):
             di = self.logical_device_id_to_root_device_id.get(ldi)
             if di is None:
@@ -240,7 +245,8 @@
         raise NotImplementedError()
 
     def receive_onu_detect_state(self, proxy_address, state):
-        log.debug('receive-onu-detect-state', proxy_address=proxy_address, state=state)
+        log.debug('receive-onu-detect-state', proxy_address=proxy_address,
+                  state=state)
         raise NotImplementedError()
 
     def create_tcont(self, device, tcont_data, traffic_descriptor_data):
diff --git a/voltha/adapters/openolt/openolt_device.py b/voltha/adapters/openolt/openolt_device.py
index dea361e..5082552 100644
--- a/voltha/adapters/openolt/openolt_device.py
+++ b/voltha/adapters/openolt/openolt_device.py
@@ -17,7 +17,6 @@
 import structlog
 import threading
 import grpc
-import collections
 import time
 
 from twisted.internet import reactor
@@ -28,10 +27,10 @@
 from voltha.protos.device_pb2 import Port, Device
 from voltha.protos.common_pb2 import OperStatus, AdminState, ConnectStatus
 from voltha.protos.logical_device_pb2 import LogicalDevice
-from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, OFPPS_LINK_DOWN, \
-    OFPPF_1GB_FD, OFPC_GROUP_STATS, OFPC_PORT_STATS, OFPC_TABLE_STATS, \
-    OFPC_FLOW_STATS, ofp_switch_features, ofp_port
-from voltha.protos.logical_device_pb2 import LogicalPort, LogicalDevice
+from voltha.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \
+    OFPPS_LINK_DOWN, OFPPF_1GB_FD, OFPC_GROUP_STATS, OFPC_PORT_STATS, \
+    OFPC_TABLE_STATS, OFPC_FLOW_STATS, ofp_switch_features, ofp_port
+from voltha.protos.logical_device_pb2 import LogicalPort
 from voltha.core.logical_device_agent import mac_str_to_tuple
 from voltha.registry import registry
 from voltha.adapters.openolt.protos import openolt_pb2_grpc, openolt_pb2
@@ -50,12 +49,16 @@
 """
 OpenoltDevice represents an OLT.
 """
+
+
 class OpenoltDevice(object):
 
     states = ['up', 'down']
     transitions = [
-            { 'trigger': 'olt_up', 'source': 'down', 'dest': 'up', 'before': 'olt_indication_up' },
-            { 'trigger': 'olt_down', 'source': 'up', 'dest': 'down', 'before': 'olt_indication_down' }
+            {'trigger': 'olt_up', 'source': 'down', 'dest': 'up',
+             'before': 'olt_indication_up'},
+            {'trigger': 'olt_down', 'source': 'up', 'dest': 'down',
+             'before': 'olt_indication_down'}
     ]
 
     def __init__(self, **kwargs):
@@ -67,7 +70,8 @@
         is_reconciliation = kwargs.get('reconciliation', False)
         self.device_id = device.id
         self.host_and_port = device.host_and_port
-        self.log = structlog.get_logger(id=self.device_id, ip=self.host_and_port)
+        self.log = structlog.get_logger(id=self.device_id,
+                                        ip=self.host_and_port)
         self.proxy = registry('core').get_proxy('/')
 
         # Device already set in the event of reconciliation
@@ -75,17 +79,20 @@
             # It is a new device
             # Update device
             device.root = True
-            device.serial_number = self.host_and_port # FIXME
+            device.serial_number = self.host_and_port  # FIXME
             device.connect_status = ConnectStatus.REACHABLE
             device.oper_status = OperStatus.ACTIVATING
             self.adapter_agent.update_device(device)
 
         # Initialize the OLT state machine
         self.machine = Machine(model=self, states=OpenoltDevice.states,
-                transitions=OpenoltDevice.transitions,
-                send_event=True, initial='down', ignore_invalid_triggers=True)
-        self.machine.add_transition(trigger='olt_ind_up', source='down', dest='up')
-        self.machine.add_transition(trigger='olt_ind_loss', source='up', dest='down')
+                               transitions=OpenoltDevice.transitions,
+                               send_event=True, initial='down',
+                               ignore_invalid_triggers=True)
+        self.machine.add_transition(trigger='olt_ind_up', source='down',
+                                    dest='up')
+        self.machine.add_transition(trigger='olt_ind_loss', source='up',
+                                    dest='down')
 
         # Initialize gRPC
         self.channel = grpc.insecure_channel(self.host_and_port)
@@ -108,7 +115,6 @@
 
         self.log.debug('openolt-device-created', device_id=self.device_id)
 
-
     def process_indications(self):
 
         self.log.debug('starting-indications-thread')
@@ -120,7 +126,8 @@
                 # get the next indication from olt
                 ind = next(self.indications)
             except Exception as e:
-                self.log.warn('GRPC-connection-lost-stoping-indications-thread', error=e)
+                self.log.warn('GRPC-connection-lost-stoping-indication-thread',
+                              error=e)
                 self.indications_thread_active = False
             else:
                 self.log.debug("rx indication", indication=ind)
@@ -131,9 +138,11 @@
                 elif ind.HasField('intf_ind'):
                     reactor.callFromThread(self.intf_indication, ind.intf_ind)
                 elif ind.HasField('intf_oper_ind'):
-                    reactor.callFromThread(self.intf_oper_indication, ind.intf_oper_ind)
+                    reactor.callFromThread(self.intf_oper_indication,
+                                           ind.intf_oper_ind)
                 elif ind.HasField('onu_disc_ind'):
-                    reactor.callFromThread(self.onu_discovery_indication, ind.onu_disc_ind)
+                    reactor.callFromThread(self.onu_discovery_indication,
+                                           ind.onu_disc_ind)
                 elif ind.HasField('onu_ind'):
                     reactor.callFromThread(self.onu_indication, ind.onu_ind)
                 elif ind.HasField('omci_ind'):
@@ -174,8 +183,9 @@
                     )
                 )
             )
-            ld_initialized = self.adapter_agent.create_logical_device(ld, dpid=dpid)
-            self.logical_device_id = ld_initialized.id
+            ld_init = self.adapter_agent.create_logical_device(ld,
+                                                               dpid=dpid)
+            self.logical_device_id = ld_init.id
         else:
             # logical device already exists
             self.logical_device_id = device.parent_id
@@ -190,7 +200,8 @@
         new_admin_state = event.kwargs.get('admin_state', None)
         new_oper_state = event.kwargs.get('oper_state', None)
         new_connect_state = event.kwargs.get('connect_state', None)
-        self.log.debug("olt indication", olt_ind=olt_indication, admin_state=new_admin_state, oper_state=new_oper_state,
+        self.log.debug("olt indication", olt_ind=olt_indication,
+                       admin_state=new_admin_state, oper_state=new_oper_state,
                        connect_state=new_connect_state)
 
         # Propagating to the children
@@ -198,18 +209,24 @@
         # Children ports
         child_devices = self.adapter_agent.get_child_devices(self.device_id)
         for onu_device in child_devices:
-            uni_no = platform.mk_uni_port_num(onu_device.proxy_address.channel_id, onu_device.proxy_address.onu_id)
-            uni_name = self.port_name(uni_no, Port.ETHERNET_UNI, serial_number=onu_device.serial_number)
+            uni_no = platform.mk_uni_port_num(
+                onu_device.proxy_address.channel_id,
+                onu_device.proxy_address.onu_id)
+            uni_name = self.port_name(uni_no, Port.ETHERNET_UNI,
+                                      serial_number=onu_device.serial_number)
 
             self.onu_ports_down(onu_device, uni_no, uni_name, new_oper_state)
         # Children devices
-        self.adapter_agent.update_child_devices_state(self.device_id, oper_status=new_oper_state,
-                                                      connect_status=ConnectStatus.UNREACHABLE,
-                                                      admin_state=new_admin_state)
+        self.adapter_agent.update_child_devices_state(
+            self.device_id, oper_status=new_oper_state,
+            connect_status=ConnectStatus.UNREACHABLE,
+            admin_state=new_admin_state)
         # Device Ports
-        device_ports = self.adapter_agent.get_ports(self.device_id, Port.ETHERNET_NNI)
+        device_ports = self.adapter_agent.get_ports(self.device_id,
+                                                    Port.ETHERNET_NNI)
         logical_ports_ids = [port.label for port in device_ports]
-        device_ports += self.adapter_agent.get_ports(self.device_id, Port.PON_OLT)
+        device_ports += self.adapter_agent.get_ports(self.device_id,
+                                                     Port.PON_OLT)
 
         for port in device_ports:
             if new_admin_state is not None:
@@ -220,9 +237,11 @@
 
         # Device logical port
         for logical_port_id in logical_ports_ids:
-            logical_port = self.adapter_agent.get_logical_port(self.logical_device_id, logical_port_id)
+            logical_port = self.adapter_agent.get_logical_port(
+                self.logical_device_id, logical_port_id)
             logical_port.ofp_port.state = OFPPS_LINK_DOWN
-            self.adapter_agent.update_logical_port(self.logical_device_id, logical_port)
+            self.adapter_agent.update_logical_port(self.logical_device_id,
+                                                   logical_port)
 
         # Device
         device = self.adapter_agent.get_device(self.device_id)
@@ -237,7 +256,7 @@
 
     def intf_indication(self, intf_indication):
         self.log.debug("intf indication", intf_id=intf_indication.intf_id,
-            oper_state=intf_indication.oper_state)
+                       oper_state=intf_indication.oper_state)
 
         if intf_indication.oper_state == "up":
             oper_status = OperStatus.ACTIVE
@@ -248,8 +267,10 @@
         self.add_port(intf_indication.intf_id, Port.PON_OLT, oper_status)
 
     def intf_oper_indication(self, intf_oper_indication):
-        self.log.debug("Received interface oper state change indication", intf_id=intf_oper_indication.intf_id,
-            type=intf_oper_indication.type, oper_state=intf_oper_indication.oper_state)
+        self.log.debug("Received interface oper state change indication",
+                       intf_id=intf_oper_indication.intf_id,
+                       type=intf_oper_indication.type,
+                       oper_state=intf_oper_indication.oper_state)
 
         if intf_oper_indication.oper_state == "up":
             oper_state = OperStatus.ACTIVE
@@ -263,10 +284,11 @@
                 return
 
             # add_(logical_)port update the port if it exists
-            port_no, label = self.add_port(intf_oper_indication.intf_id, Port.ETHERNET_NNI, oper_state)
+            port_no, label = self.add_port(intf_oper_indication.intf_id,
+                                           Port.ETHERNET_NNI, oper_state)
             self.log.debug("int_oper_indication", port_no=port_no, label=label)
-            self.add_logical_port(port_no, intf_oper_indication.intf_id, oper_state)
-
+            self.add_logical_port(port_no, intf_oper_indication.intf_id,
+                                  oper_state)
 
         elif intf_oper_indication.type == "pon":
             # FIXME - handle PON oper state change
@@ -274,23 +296,28 @@
 
     def onu_discovery_indication(self, onu_disc_indication):
         intf_id = onu_disc_indication.intf_id
-        serial_number=onu_disc_indication.serial_number
+        serial_number = onu_disc_indication.serial_number
 
         serial_number_str = self.stringify_serial_number(serial_number)
 
-        self.log.debug("onu discovery indication", intf_id=intf_id, serial_number=serial_number_str)
+        self.log.debug("onu discovery indication", intf_id=intf_id,
+                       serial_number=serial_number_str)
 
-        onu_device = self.adapter_agent.get_child_device(self.device_id, serial_number=serial_number_str)
+        onu_device = self.adapter_agent.get_child_device(
+            self.device_id,
+            serial_number=serial_number_str)
 
         if onu_device is None:
             onu_id = self.new_onu_id(intf_id)
             try:
-                self.add_onu_device(intf_id,
-                        platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
-                        onu_id, serial_number)
+                self.add_onu_device(
+                    intf_id,
+                    platform.intf_id_to_port_no(intf_id, Port.PON_OLT),
+                    onu_id, serial_number)
                 self.log.info("activate-onu", intf_id=intf_id, onu_id=onu_id,
-                        serial_number=serial_number_str)
-                onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,serial_number=serial_number)
+                              serial_number=serial_number_str)
+                onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,
+                                      serial_number=serial_number)
                 self.stub.ActivateOnu(onu)
             except Exception as e:
                 self.log.exception('onu-activation-failed', e=e)
@@ -301,37 +328,45 @@
                     self.adapter_agent.update_device(onu_device)
 
             onu_id = onu_device.proxy_address.onu_id
-            if onu_device.oper_status == OperStatus.DISCOVERED or onu_device.oper_status == OperStatus.ACTIVATING:
-                self.log.debug("ignore onu discovery indication, the onu has been discovered and should be \
-                              activating shorlty", intf_id=intf_id, onu_id=onu_id, state=onu_device.oper_status)
-            elif onu_device.oper_status== OperStatus.ACTIVE:
-                self.log.warn("onu discovery indication whereas onu is supposed to be active",
-                              intf_id=intf_id, onu_id=onu_id, state=onu_device.oper_status)
+            if onu_device.oper_status == OperStatus.DISCOVERED \
+               or onu_device.oper_status == OperStatus.ACTIVATING:
+                self.log.debug("ignore onu discovery indication, \
+                               the onu has been discovered and should be \
+                               activating shorlty", intf_id=intf_id,
+                               onu_id=onu_id, state=onu_device.oper_status)
+            elif onu_device.oper_status == OperStatus.ACTIVE:
+                self.log.warn("onu discovery indication whereas onu is \
+                              supposed to be active",
+                              intf_id=intf_id, onu_id=onu_id,
+                              state=onu_device.oper_status)
             elif onu_device.oper_status == OperStatus.UNKNOWN:
-                self.log.info("onu-in-unknow-state-recovering-form-olt-reboot-activate-onu", intf_id=intf_id, onu_id=onu_id,
-                              serial_number=serial_number_str)
+                self.log.info("onu in unknown state, recovering from olt \
+                              reboot, activate onu", intf_id=intf_id,
+                              onu_id=onu_id, serial_number=serial_number_str)
 
                 onu_device.oper_status = OperStatus.DISCOVERED
                 self.adapter_agent.update_device(onu_device)
 
-                onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id, serial_number=serial_number)
+                onu = openolt_pb2.Onu(intf_id=intf_id, onu_id=onu_id,
+                                      serial_number=serial_number)
                 self.stub.ActivateOnu(onu)
             else:
-                self.log.warn('unexpected state', onu_id=onu_id, onu_device_oper_state=onu_device.oper_status)
+                self.log.warn('unexpected state', onu_id=onu_id,
+                              onu_device_oper_state=onu_device.oper_status)
 
     def onu_indication(self, onu_indication):
         self.log.debug("onu indication", intf_id=onu_indication.intf_id,
-                onu_id=onu_indication.onu_id,
-                serial_number=onu_indication.serial_number,
-                oper_state=onu_indication.oper_state,
-                admin_state=onu_indication.admin_state)
+                       onu_id=onu_indication.onu_id,
+                       serial_number=onu_indication.serial_number,
+                       oper_state=onu_indication.oper_state,
+                       admin_state=onu_indication.admin_state)
 
         if onu_indication.serial_number:
             onu_device = self.adapter_agent.get_child_device(
                     self.device_id,
                     serial_number=self.stringify_serial_number(
                             onu_indication.serial_number))
-        else :
+        else:
             onu_device = self.adapter_agent.get_child_device(
                     self.device_id,
                     parent_port_no=platform.intf_id_to_port_no(
@@ -340,91 +375,102 @@
 
         if onu_device is None:
             self.log.error('onu not found', intf_id=onu_indication.intf_id,
-                    onu_id=onu_indication.onu_id)
+                           onu_id=onu_indication.onu_id)
             return
 
         if onu_device.connect_status != ConnectStatus.REACHABLE:
             onu_device.connect_status = ConnectStatus.REACHABLE
             self.adapter_agent.update_device(onu_device)
 
-        if platform.intf_id_from_pon_port_no(onu_device.parent_port_no) != onu_indication.intf_id:
+        if platform.intf_id_from_pon_port_no(onu_device.parent_port_no) \
+           != onu_indication.intf_id:
             self.log.warn('ONU-is-on-a-different-intf-id-now',
-                          previous_intf_id=platform.intf_id_from_pon_port_no(onu_device.parent_port_no),
+                          previous_intf_id=platform.intf_id_from_pon_port_no(
+                              onu_device.parent_port_no),
                           current_intf_id=onu_indication.intf_id)
             # FIXME - handle intf_id mismatch (ONU move?)
 
-
         if onu_device.proxy_address.onu_id != onu_indication.onu_id:
             # FIXME - handle onu id mismatch
-            self.log.warn('ONU-id-mismatch', expected_onu_id=onu_device.proxy_address.onu_id,
+            self.log.warn('ONU-id-mismatch',
+                          expected_onu_id=onu_device.proxy_address.onu_id,
                           received_onu_id=onu_indication.onu_id)
 
-        uni_no = platform.mk_uni_port_num(onu_indication.intf_id, onu_indication.onu_id)
-        uni_name = self.port_name(uni_no, Port.ETHERNET_UNI, serial_number=onu_device.serial_number)
+        uni_no = platform.mk_uni_port_num(onu_indication.intf_id,
+                                          onu_indication.onu_id)
+        uni_name = self.port_name(uni_no, Port.ETHERNET_UNI,
+                                  serial_number=onu_device.serial_number)
 
         self.log.debug('port-number-ready', uni_no=uni_no, uni_name=uni_name)
 
-        #Admin state
+        # Admin state
         if onu_indication.admin_state == 'down':
             if onu_indication.oper_state != 'down':
-                self.log.error('ONU-admin-state-down-and-oper-status-not-down', oper_state=onu_indication.oper_state)
-                onu_indication.oper_state = 'down' # Forcing the oper state change code to execute
+                self.log.error('ONU-admin-state-down-and-oper-status-not-down',
+                               oper_state=onu_indication.oper_state)
+                # Forcing the oper state change code to execute
+                onu_indication.oper_state = 'down'
 
             if onu_device.admin_state != AdminState.DISABLED:
                 onu_device.admin_state = AdminState.DISABLED
                 self.adapter_agent.update(onu_device)
-                self.log.debug('putting-onu-in-disabled-state', onu_serial_number=onu_device.serial_number)
+                self.log.debug('putting-onu-in-disabled-state',
+                               onu_serial_number=onu_device.serial_number)
 
-            #Port and logical port update is taken care of by oper state block
+            # Port and logical port update is taken care of by oper state block
 
         elif onu_indication.admin_state == 'up':
             if onu_device.admin_state != AdminState.ENABLED:
                 onu_device.admin_state = AdminState.ENABLED
                 self.adapter_agent.update(onu_device)
-                self.log.debug('putting-onu-in-enabled-state', onu_serial_number=onu_device.serial_number)
+                self.log.debug('putting-onu-in-enabled-state',
+                               onu_serial_number=onu_device.serial_number)
 
         else:
-            self.log.warn('Invalid-or-not-implemented-admin-state', received_admin_state=onu_indication.admin_state)
+            self.log.warn('Invalid-or-not-implemented-admin-state',
+                          received_admin_state=onu_indication.admin_state)
 
         self.log.debug('admin-state-dealt-with')
 
-        #Operating state
+        # Operating state
         if onu_indication.oper_state == 'down':
-            #Move to discovered state
+            # Move to discovered state
             self.log.debug('onu-oper-state-is-down')
 
             if onu_device.oper_status != OperStatus.DISCOVERED:
                 onu_device.oper_status = OperStatus.DISCOVERED
                 self.adapter_agent.update_device(onu_device)
-            #Set port oper state to Discovered
-
-            self.onu_ports_down(onu_device, uni_no, uni_name, OperStatus.DISCOVERED)
+            # Set port oper state to Discovered
+            self.onu_ports_down(onu_device, uni_no, uni_name,
+                                OperStatus.DISCOVERED)
 
         elif onu_indication.oper_state == 'up':
 
             if onu_device.oper_status != OperStatus.DISCOVERED:
-                self.log.debug("ignore onu indication", intf_id=onu_indication.intf_id,
-                               onu_id=onu_indication.onu_id, state=onu_device.oper_status,
+                self.log.debug("ignore onu indication",
+                               intf_id=onu_indication.intf_id,
+                               onu_id=onu_indication.onu_id,
+                               state=onu_device.oper_status,
                                msg_oper_state=onu_indication.oper_state)
                 return
 
-            #Device was in Discovered state, setting it to active
-
-
-
-            onu_adapter_agent = registry('adapter_loader').get_agent(onu_device.adapter)
+            # Device was in Discovered state, setting it to active
+            onu_adapter_agent = \
+                registry('adapter_loader').get_agent(onu_device.adapter)
             if onu_adapter_agent is None:
-                self.log.error('onu_adapter_agent-could-not-be-retrieved', onu_device=onu_device)
+                self.log.error('onu_adapter_agent-could-not-be-retrieved',
+                               onu_device=onu_device)
                 return
 
-            #Prepare onu configuration
+            # Prepare onu configuration
 
             # onu initialization, base configuration (bridge setup ...)
             def onu_initialization():
 
-                #FIXME: that's definitely cheating
+                # FIXME: that's definitely cheating
                 if onu_device.adapter == 'broadcom_onu':
-                    onu_adapter_agent.adapter.devices_handlers[onu_device.id].message_exchange()
+                    onu_adapter_agent.adapter.devices_handlers[onu_device.id] \
+                            .message_exchange()
                     self.log.debug('broadcom-message-exchange-started')
 
             # tcont creation (onu)
@@ -435,12 +481,12 @@
             gem_port = GemportsConfigData()
             gem_port.gemport_id = platform.mk_gemport_id(onu_indication.onu_id)
 
-            #ports creation/update
+            # ports creation/update
             def port_config():
 
                 # "v_enet" creation (olt)
 
-                #add_port update port when it exists
+                # add_port update port when it exists
                 self.adapter_agent.add_port(
                     self.device_id,
                     Port(
@@ -464,14 +510,17 @@
 
             # FIXME : the asynchronicity has to be taken care of properly
             onu_initialization()
-            reactor.callLater(10, onu_adapter_agent.create_tcont, device=onu_device,
-                                                            tcont_data=tcont, traffic_descriptor_data=None)
-            reactor.callLater(11, onu_adapter_agent.create_gemport, onu_device, gem_port)
+            reactor.callLater(10, onu_adapter_agent.create_tcont,
+                              device=onu_device, tcont_data=tcont,
+                              traffic_descriptor_data=None)
+            reactor.callLater(11, onu_adapter_agent.create_gemport, onu_device,
+                              gem_port)
             reactor.callLater(12, port_config)
             reactor.callLater(12, onu_update_oper_status)
 
         else:
-            self.log.warn('Not-implemented-or-invalid-value-of-oper-state', oper_state=onu_indication.oper_state)
+            self.log.warn('Not-implemented-or-invalid-value-of-oper-state',
+                          oper_state=onu_indication.oper_state)
 
     def onu_ports_down(self, onu_device, uni_no, uni_name, oper_state):
         # Set port oper state to Discovered
@@ -492,42 +541,48 @@
             if onu_port.port_no == uni_no:
                 onu_port_id = onu_port.label
         if onu_port_id is None:
-            self.log.error('matching-onu-port-label-not-found', onu_id=onu_device.id, olt_id=self.device_id,
+            self.log.error('matching-onu-port-label-not-found',
+                           onu_id=onu_device.id, olt_id=self.device_id,
                            onu_ports=onu_ports)
             return
         try:
-            onu_logical_port = self.adapter_agent.get_logical_port(logical_device_id=self.logical_device_id,
-                                                                   port_id=onu_port_id)
+            onu_logical_port = self.adapter_agent.get_logical_port(
+                logical_device_id=self.logical_device_id, port_id=onu_port_id)
             onu_logical_port.ofp_port.state = OFPPS_LINK_DOWN
-            self.adapter_agent.update_logical_port(logical_device_id=self.logical_device_id, port=onu_logical_port)
+            self.adapter_agent.update_logical_port(
+                logical_device_id=self.logical_device_id,
+                port=onu_logical_port)
             self.log.debug('cascading-oper-state-to-port-and-logical-port')
         except KeyError as e:
-            self.log.error('matching-onu-port-label-invalid', onu_id=onu_device.id, olt_id=self.device_id,
-                           onu_ports=onu_ports, onu_port_id=onu_port_id, error=e)
+            self.log.error('matching-onu-port-label-invalid',
+                           onu_id=onu_device.id, olt_id=self.device_id,
+                           onu_ports=onu_ports, onu_port_id=onu_port_id,
+                           error=e)
 
     def omci_indication(self, omci_indication):
 
         self.log.debug("omci indication", intf_id=omci_indication.intf_id,
-                onu_id=omci_indication.onu_id)
+                       onu_id=omci_indication.onu_id)
 
-        onu_device = self.adapter_agent.get_child_device(self.device_id,
-                onu_id=omci_indication.onu_id)
+        onu_device = self.adapter_agent.get_child_device(
+            self.device_id, onu_id=omci_indication.onu_id)
 
         self.adapter_agent.receive_proxied_message(onu_device.proxy_address,
-                omci_indication.pkt)
+                                                   omci_indication.pkt)
 
     def packet_indication(self, pkt_indication):
 
         self.log.debug("packet indication", intf_id=pkt_indication.intf_id,
-                gemport_id=pkt_indication.gemport_id,
-                flow_id=pkt_indication.flow_id)
+                       gemport_id=pkt_indication.gemport_id,
+                       flow_id=pkt_indication.flow_id)
 
         onu_id = platform.onu_id_from_gemport_id(pkt_indication.gemport_id)
-        logical_port_num = platform.mk_uni_port_num(pkt_indication.intf_id, onu_id)
+        logical_port_num = platform.mk_uni_port_num(pkt_indication.intf_id,
+                                                    onu_id)
 
         pkt = Ether(pkt_indication.pkt)
         kw = dict(logical_device_id=self.logical_device_id,
-                logical_port_no=logical_port_num)
+                  logical_port_no=logical_port_num)
         self.adapter_agent.send_packet_in(packet=str(pkt), **kw)
 
     def olt_reachable(self):
@@ -538,35 +593,42 @@
 
     def heartbeat(self):
 
-        self.channel_ready_future.result()  # blocks till gRPC connection is complete
+        # block till gRPC connection is complete
+        self.channel_ready_future.result()
 
         while self.heartbeat_thread_active:
 
             try:
-                heartbeat = self.stub.HeartbeatCheck(openolt_pb2.Empty(), timeout=GRPC_TIMEOUT)
+                heartbeat = self.stub.HeartbeatCheck(openolt_pb2.Empty(),
+                                                     timeout=GRPC_TIMEOUT)
             except Exception as e:
                 self.heartbeat_miss += 1
-                self.log.warn('heartbeat-miss', missed_heartbeat=self.heartbeat_miss, error=e)
+                self.log.warn('heartbeat-miss',
+                              missed_heartbeat=self.heartbeat_miss, error=e)
                 if self.heartbeat_miss == MAX_HEARTBEAT_MISS:
                     self.log.error('lost-connectivity-to-olt')
-                    #TODO : send alarm/notify monitoring system
+                    # TODO : send alarm/notify monitoring system
                     # Using reactor to synchronize update
                     # flagging it as unreachable and in unknow state
-                    reactor.callFromThread(self.olt_down, oper_state=OperStatus.UNKNOWN,
-                                      connect_state=ConnectStatus.UNREACHABLE)
+                    reactor.callFromThread(
+                        self.olt_down,
+                        oper_state=OperStatus.UNKNOWN,
+                        connect_state=ConnectStatus.UNREACHABLE)
 
             else:
                 # heartbeat received
                 if self.heartbeat_signature is None:
                     # Initialize heartbeat signature
                     self.heartbeat_signature = heartbeat.heartbeat_signature
-                    self.log.debug('heartbeat-signature', device_id=self.device_id,
-                                   heartbeat_signature=self.heartbeat_signature)
+                    self.log.debug(
+                        'heartbeat-signature',
+                        device_id=self.device_id,
+                        heartbeat_signature=self.heartbeat_signature)
                 # Check if signature is different
                 if self.heartbeat_signature != heartbeat.heartbeat_signature:
                     # OLT has rebooted
                     self.log.warn('OLT-was-rebooted', device_id=self.device_id)
-                    #TODO: notify monitoring system
+                    # TODO: notify monitoring system
                     self.heartbeat_signature = heartbeat.heartbeat_signature
 
                 else:
@@ -574,14 +636,15 @@
 
                 if self.heartbeat_miss > MAX_HEARTBEAT_MISS:
                     self.log.info('OLT-connection-restored')
-                    #TODO : suppress alarm/notify monitoring system
+                    # TODO : suppress alarm/notify monitoring system
                     # flagging it as reachable again
                     reactor.callFromThread(self.olt_reachable)
 
                 if not self.indications_thread_active:
                     self.log.info('(re)starting-indications-thread')
                     # reset indications thread
-                    self.indications_thread = threading.Thread(target=self.process_indications)
+                    self.indications_thread = threading.Thread(
+                        target=self.process_indications)
                     self.indications_thread.setDaemon(True)
                     self.indications_thread_active = True
                     self.indications_thread.start()
@@ -592,13 +655,10 @@
 
         self.log.debug('stopping-heartbeat-thread', device_id=self.device_id)
 
-
-
     def packet_out(self, egress_port, msg):
         pkt = Ether(msg)
         self.log.info('packet out', egress_port=egress_port,
-                packet=str(pkt).encode("HEX"))
-
+                      packet=str(pkt).encode("HEX"))
 
         # Find port type
         egress_port_type = self.port_type(egress_port)
@@ -620,50 +680,59 @@
 
             send_pkt = binascii.unhexlify(str(payload).encode("HEX"))
 
-            self.log.info('sending-packet-to-ONU', egress_port=egress_port,
-                          intf_id=platform.intf_id_from_pon_port_no(egress_port),
-                          onu_id=platform.onu_id_from_port_num(egress_port),
-                        packet=str(payload).encode("HEX"))
+            self.log.info(
+                'sending-packet-to-ONU', egress_port=egress_port,
+                intf_id=platform.intf_id_from_pon_port_no(egress_port),
+                onu_id=platform.onu_id_from_port_num(egress_port),
+                packet=str(payload).encode("HEX"))
 
-            onu_pkt = openolt_pb2.OnuPacket(intf_id=platform.intf_id_from_pon_port_no(egress_port),
-                    onu_id=platform.onu_id_from_port_num(egress_port), pkt=send_pkt)
+            onu_pkt = openolt_pb2.OnuPacket(
+                intf_id=platform.intf_id_from_pon_port_no(egress_port),
+                onu_id=platform.onu_id_from_port_num(egress_port),
+                pkt=send_pkt)
 
             self.stub.OnuPacketOut(onu_pkt)
 
         elif egress_port_type == Port.ETHERNET_NNI:
-            self.log.info('sending-packet-to-uplink', egress_port=egress_port, packet=str(pkt).encode("HEX"))
+            self.log.info('sending-packet-to-uplink', egress_port=egress_port,
+                          packet=str(pkt).encode("HEX"))
 
             send_pkt = binascii.unhexlify(str(pkt).encode("HEX"))
 
-            uplink_pkt = openolt_pb2.UplinkPacket(intf_id=platform.intf_id_from_nni_port_num(egress_port), pkt=send_pkt)
+            uplink_pkt = openolt_pb2.UplinkPacket(
+                intf_id=platform.intf_id_from_nni_port_num(egress_port),
+                pkt=send_pkt)
 
             self.stub.UplinkPacketOut(uplink_pkt)
 
         else:
-            self.log.warn('Packet-out-to-this-interface-type-not-implemented', egress_port=egress_port,
+            self.log.warn('Packet-out-to-this-interface-type-not-implemented',
+                          egress_port=egress_port,
                           port_type=egress_port_type)
 
     def send_proxied_message(self, proxy_address, msg):
-        omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id, # intf_id
-                onu_id=proxy_address.onu_id, pkt=str(msg))
+        omci = openolt_pb2.OmciMsg(intf_id=proxy_address.channel_id,
+                                   onu_id=proxy_address.onu_id, pkt=str(msg))
         self.stub.OmciMsgOut(omci)
 
     def add_onu_device(self, intf_id, port_no, onu_id, serial_number):
         self.log.info("Adding ONU", port_no=port_no, onu_id=onu_id,
-                serial_number=serial_number)
+                      serial_number=serial_number)
 
         # NOTE - channel_id of onu is set to intf_id
         proxy_address = Device.ProxyAddress(device_id=self.device_id,
-                channel_id=intf_id, onu_id=onu_id, onu_session_id=onu_id)
+                                            channel_id=intf_id, onu_id=onu_id,
+                                            onu_session_id=onu_id)
 
         self.log.info("Adding ONU", proxy_address=proxy_address)
 
         serial_number_str = self.stringify_serial_number(serial_number)
 
-        self.adapter_agent.add_onu_device(parent_device_id=self.device_id,
-                parent_port_no=port_no, vendor_id=serial_number.vendor_id,
-                proxy_address=proxy_address, root=True,
-                serial_number=serial_number_str, admin_state=AdminState.ENABLED)
+        self.adapter_agent.add_onu_device(
+            parent_device_id=self.device_id, parent_port_no=port_no,
+            vendor_id=serial_number.vendor_id, proxy_address=proxy_address,
+            root=True, serial_number=serial_number_str,
+            admin_state=AdminState.ENABLED)
 
     def port_name(self, port_no, port_type, intf_id=None, serial_number=None):
         if port_type is Port.ETHERNET_NNI:
@@ -676,7 +745,6 @@
             else:
                 return "uni-{}".format(port_no)
 
-
     def port_type(self, port_no):
         ports = self.adapter_agent.get_ports(self.device_id)
         for port in ports:
@@ -684,7 +752,6 @@
                 return port.type
         return None
 
-
     def add_logical_port(self, port_no, intf_id, oper_state):
         self.log.info('adding-logical-port', port_no=port_no)
 
@@ -699,17 +766,19 @@
         else:
             of_oper_state = OFPPS_LINK_DOWN
 
-        ofp = ofp_port(port_no=port_no,
-                hw_addr=mac_str_to_tuple('00:00:00:00:00:%02x' % port_no),
-                name=label, config=0, state=of_oper_state, curr=cap,
-                advertised=cap, peer=cap, curr_speed=curr_speed,
-                max_speed=max_speed)
+        ofp = ofp_port(
+            port_no=port_no,
+            hw_addr=mac_str_to_tuple('00:00:00:00:00:%02x' % port_no),
+            name=label, config=0, state=of_oper_state, curr=cap,
+            advertised=cap, peer=cap, curr_speed=curr_speed,
+            max_speed=max_speed)
 
-        logical_port = LogicalPort(id=label, ofp_port=ofp,
-                device_id=self.device_id, device_port_no=port_no,
-                root_port=True)
+        logical_port = LogicalPort(
+            id=label, ofp_port=ofp, device_id=self.device_id,
+            device_port_no=port_no, root_port=True)
 
-        self.adapter_agent.add_logical_port(self.logical_device_id, logical_port)
+        self.adapter_agent.add_logical_port(self.logical_device_id,
+                                            logical_port)
 
     def add_port(self, intf_id, port_type, oper_status):
         port_no = platform.intf_id_to_port_no(intf_id, port_type)
@@ -717,10 +786,10 @@
         label = self.port_name(port_no, port_type, intf_id)
 
         self.log.info('adding-port', port_no=port_no, label=label,
-                port_type=port_type)
+                      port_type=port_type)
 
         port = Port(port_no=port_no, label=label, type=port_type,
-            admin_state=AdminState.ENABLED, oper_status=oper_status)
+                    admin_state=AdminState.ENABLED, oper_status=oper_status)
 
         self.adapter_agent.add_port(self.device_id, port)
 
@@ -742,16 +811,15 @@
 
     def stringify_vendor_specific(self, vendor_specific):
         return ''.join(str(i) for i in [
-                hex(ord(vendor_specific[0])>>4 & 0x0f)[2:],
+                hex(ord(vendor_specific[0]) >> 4 & 0x0f)[2:],
                 hex(ord(vendor_specific[0]) & 0x0f)[2:],
-                hex(ord(vendor_specific[1])>>4 & 0x0f)[2:],
+                hex(ord(vendor_specific[1]) >> 4 & 0x0f)[2:],
                 hex(ord(vendor_specific[1]) & 0x0f)[2:],
-                hex(ord(vendor_specific[2])>>4 & 0x0f)[2:],
+                hex(ord(vendor_specific[2]) >> 4 & 0x0f)[2:],
                 hex(ord(vendor_specific[2]) & 0x0f)[2:],
-                hex(ord(vendor_specific[3])>>4 & 0x0f)[2:],
+                hex(ord(vendor_specific[3]) >> 4 & 0x0f)[2:],
                 hex(ord(vendor_specific[3]) & 0x0f)[2:]])
 
-
     def update_flow_table(self, flows):
         device = self.adapter_agent.get_device(self.device_id)
         self.log.debug('update flow table')
@@ -761,8 +829,8 @@
             is_down_stream = None
             in_port = fd.get_in_port(flow)
             assert in_port is not None
-            # Right now there is only one NNI port. Get the NNI PORT and compare
-            # with IN_PUT port number. Need to find better way.
+            # Right now there is only one NNI port. Get the NNI PORT and
+            # compare with IN_PUT port number. Need to find better way.
             ports = self.adapter_agent.get_ports(device.id, Port.ETHERNET_NNI)
 
             for port in ports:
@@ -778,7 +846,8 @@
                 try:
                     self.flow_mgr.add_flow(flow, is_down_stream)
                 except Exception as e:
-                    self.log.exception('failed-to-install-flow', e=e, flow=flow)
+                    self.log.exception('failed-to-install-flow', e=e,
+                                       flow=flow)
 
     # There has to be a better way to do this
     def ip_hex(self, ip):
@@ -793,20 +862,23 @@
 
     def stringify_serial_number(self, serial_number):
         return ''.join([serial_number.vendor_id,
-                                     self.stringify_vendor_specific(serial_number.vendor_specific)])
+                        self.stringify_vendor_specific(
+                            serial_number.vendor_specific)])
 
     def disable(self):
-        self.log.info('sending-deactivate-olt-message', device_id=self.device_id)
+        self.log.info('sending-deactivate-olt-message',
+                      device_id=self.device_id)
 
         # Send grpc call
-        #self.stub.DeactivateOlt(openolt_pb2.Empty())
+        # self.stub.DeactivateOlt(openolt_pb2.Empty())
 
-        # Soft deactivate. Turning down hardware should remove flows, but we are not doing that presently
+        # Soft deactivate. Turning down hardware should remove flows,
+        # but we are not doing that presently
 
         # Bring OLT down
-        self.olt_down(oper_state=OperStatus.UNKNOWN, admin_state=AdminState.DISABLED,
-                      connect_state = ConnectStatus.UNREACHABLE)
-
+        self.olt_down(oper_state=OperStatus.UNKNOWN,
+                      admin_state=AdminState.DISABLED,
+                      connect_state=ConnectStatus.UNREACHABLE)
 
     def delete(self):
         self.log.info('delete-olt', device_id=self.device_id)
@@ -831,8 +903,9 @@
         # Enable all child devices
         self.log.info('enabling-child-devices', device_id=self.device_id)
         self.log.info('enabling-child-devices', olt_device_id=self.device_id)
-        self.adapter_agent.update_child_devices_state(parent_device_id=self.device_id,
-                                                     admin_state=AdminState.ENABLED)
+        self.adapter_agent.update_child_devices_state(
+            parent_device_id=self.device_id,
+            admin_state=AdminState.ENABLED)
 
         # Set all ports to enabled
         self.log.info('enabling-all-ports', device_id=self.device_id)
diff --git a/voltha/adapters/openolt/openolt_flow_mgr.py b/voltha/adapters/openolt/openolt_flow_mgr.py
index 367525e..063101b 100644
--- a/voltha/adapters/openolt/openolt_flow_mgr.py
+++ b/voltha/adapters/openolt/openolt_flow_mgr.py
@@ -14,21 +14,20 @@
 # limitations under the License.
 #
 
-import time
-
 from voltha.protos.openflow_13_pb2 import OFPXMC_OPENFLOW_BASIC
 import voltha.core.flow_decomposer as fd
 import openolt_platform as platform
 from voltha.adapters.openolt.protos import openolt_pb2
 
-HSIA_FLOW_INDEX = 0 # FIXME
-DHCP_FLOW_INDEX = 1 # FIXME
-EAPOL_FLOW_INDEX = 2 # FIXME
-EAPOL_DOWNLINK_FLOW_INDEX = 3 # FIXME
+HSIA_FLOW_INDEX = 0  # FIXME
+DHCP_FLOW_INDEX = 1  # FIXME
+EAPOL_FLOW_INDEX = 2  # FIXME
+EAPOL_DOWNLINK_FLOW_INDEX = 3  # FIXME
 
 # FIXME - see also BRDCM_DEFAULT_VLAN in broadcom_onu.py
 DEFAULT_MGMT_VLAN = 4091
 
+
 class OpenOltFlowMgr(object):
 
     def __init__(self, log, stub):
@@ -47,43 +46,43 @@
             if field.type == fd.ETH_TYPE:
                 classifier_info['eth_type'] = field.eth_type
                 self.log.debug('field-type-eth-type',
-                        eth_type=classifier_info['eth_type'])
+                               eth_type=classifier_info['eth_type'])
             elif field.type == fd.IP_PROTO:
                 classifier_info['ip_proto'] = field.ip_proto
                 self.log.debug('field-type-ip-proto',
-                        ip_proto=classifier_info['ip_proto'])
+                               ip_proto=classifier_info['ip_proto'])
             elif field.type == fd.IN_PORT:
                 classifier_info['in_port'] = field.port
                 self.log.debug('field-type-in-port',
-                        in_port=classifier_info['in_port'])
+                               in_port=classifier_info['in_port'])
             elif field.type == fd.VLAN_VID:
                 classifier_info['vlan_vid'] = field.vlan_vid & 0xfff
                 self.log.debug('field-type-vlan-vid',
-                        vlan=classifier_info['vlan_vid'])
+                               vlan=classifier_info['vlan_vid'])
             elif field.type == fd.VLAN_PCP:
                 classifier_info['vlan_pcp'] = field.vlan_pcp
                 self.log.debug('field-type-vlan-pcp',
-                        pcp=classifier_info['vlan_pcp'])
+                               pcp=classifier_info['vlan_pcp'])
             elif field.type == fd.UDP_DST:
                 classifier_info['udp_dst'] = field.udp_dst
                 self.log.debug('field-type-udp-dst',
-                        udp_dst=classifier_info['udp_dst'])
+                               udp_dst=classifier_info['udp_dst'])
             elif field.type == fd.UDP_SRC:
                 classifier_info['udp_src'] = field.udp_src
                 self.log.debug('field-type-udp-src',
-                        udp_src=classifier_info['udp_src'])
+                               udp_src=classifier_info['udp_src'])
             elif field.type == fd.IPV4_DST:
                 classifier_info['ipv4_dst'] = field.ipv4_dst
                 self.log.debug('field-type-ipv4-dst',
-                        ipv4_dst=classifier_info['ipv4_dst'])
+                               ipv4_dst=classifier_info['ipv4_dst'])
             elif field.type == fd.IPV4_SRC:
                 classifier_info['ipv4_src'] = field.ipv4_src
                 self.log.debug('field-type-ipv4-src',
-                        ipv4_dst=classifier_info['ipv4_src'])
+                               ipv4_dst=classifier_info['ipv4_src'])
             elif field.type == fd.METADATA:
                 classifier_info['metadata'] = field.table_metadata
                 self.log.debug('field-type-metadata',
-                        metadata=classifier_info['metadata'])
+                               metadata=classifier_info['metadata'])
             else:
                 raise NotImplementedError('field.type={}'.format(
                     field.type))
@@ -92,8 +91,8 @@
             if action.type == fd.OUTPUT:
                 action_info['output'] = action.output.port
                 self.log.debug('action-type-output',
-                        output=action_info['output'],
-                        in_port=classifier_info['in_port'])
+                               output=action_info['output'],
+                               in_port=classifier_info['in_port'])
             elif action.type == fd.POP_VLAN:
                 action_info['pop_vlan'] = True
                 self.log.debug('action-type-pop-vlan', in_port=in_port)
@@ -101,34 +100,37 @@
                 action_info['push_vlan'] = True
                 action_info['tpid'] = action.push.ethertype
                 self.log.debug('action-type-push-vlan',
-                        push_tpid=action_info['tpid'], in_port=in_port)
+                               push_tpid=action_info['tpid'], in_port=in_port)
                 if action.push.ethertype != 0x8100:
                     self.log.error('unhandled-tpid',
-                           ethertype=action.push.ethertype)
+                                   ethertype=action.push.ethertype)
             elif action.type == fd.SET_FIELD:
                 # action_info['action_type'] = 'set_field'
                 _field = action.set_field.field.ofb_field
                 assert (action.set_field.field.oxm_class ==
                         OFPXMC_OPENFLOW_BASIC)
                 self.log.debug('action-type-set-field',
-                        field=_field, in_port=in_port)
+                               field=_field, in_port=in_port)
                 if _field.type == fd.VLAN_VID:
                     self.log.debug('set-field-type-vlan-vid',
-                            vlan_vid=_field.vlan_vid & 0xfff)
+                                   vlan_vid=_field.vlan_vid & 0xfff)
                     action_info['vlan_vid'] = (_field.vlan_vid & 0xfff)
                 else:
                     self.log.error('unsupported-action-set-field-type',
-                            field_type=_field.type)
+                                   field_type=_field.type)
             else:
                 self.log.error('unsupported-action-type',
-                        action_type=action.type, in_port=in_port)
+                               action_type=action.type, in_port=in_port)
 
         # FIXME - Why ignore downstream flows?
         if is_down_stream is False:
-            intf_id = platform.intf_id_from_uni_port_num(classifier_info['in_port'])
-            onu_id = platform.onu_id_from_port_num(classifier_info['in_port'])
-            self.divide_and_add_flow(intf_id, onu_id, classifier_info, action_info)
-        #else:
+            intf_id = platform.intf_id_from_uni_port_num(
+                classifier_info['in_port'])
+            onu_id = platform.onu_id_from_port_num(
+                classifier_info['in_port'])
+            self.divide_and_add_flow(intf_id, onu_id, classifier_info,
+                                     action_info)
+        # else:
         #    self.log.info('ignore downstream flow', flow=flow,
         #            classifier_info=classifier_info,
         #            action_info=action_info)
@@ -144,8 +146,9 @@
             elif classifier['ip_proto'] == 2:
                 self.log.debug('igmp flow add ignored')
             else:
-                self.log.debug("Invalid-Classifier-to-handle", classifier=classifier,
-                        action=action)
+                self.log.debug("Invalid-Classifier-to-handle",
+                               classifier=classifier,
+                               action=action)
         elif 'eth_type' in classifier:
             if classifier['eth_type'] == 0x888e:
                 self.log.debug('eapol flow add')
@@ -153,8 +156,9 @@
         elif 'push_vlan' in action:
             self.add_data_flow(intf_id, onu_id, classifier, action)
         else:
-            self.log.debug('Invalid-flow-type-to-handle', classifier=classifier,
-                    action=action)
+            self.log.debug('Invalid-flow-type-to-handle',
+                           classifier=classifier,
+                           action=action)
 
     def add_data_flow(self, intf_id, onu_id, uplink_classifier, uplink_action):
 
@@ -173,27 +177,30 @@
         # will take care of handling all the p bits.
         # We need to revisit when mulitple gem port per p bits is needed.
         self.add_hsia_flow(intf_id, onu_id, uplink_classifier, uplink_action,
-                downlink_classifier, downlink_action, HSIA_FLOW_INDEX)
+                           downlink_classifier, downlink_action,
+                           HSIA_FLOW_INDEX)
 
     def add_hsia_flow(self, intf_id, onu_id, uplink_classifier, uplink_action,
-                downlink_classifier, downlink_action, hsia_id):
+                      downlink_classifier, downlink_action, hsia_id):
 
         gemport_id = platform.mk_gemport_id(onu_id)
         flow_id = platform.mk_flow_id(intf_id, onu_id, hsia_id)
 
-        self.log.debug('add upstream flow', onu_id=onu_id, classifier=uplink_classifier,
-                action=uplink_action, gemport_id=gemport_id, flow_id=flow_id)
+        self.log.debug('add upstream flow', onu_id=onu_id,
+                       classifier=uplink_classifier, action=uplink_action,
+                       gemport_id=gemport_id, flow_id=flow_id)
 
         flow = openolt_pb2.Flow(
-                onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
-                access_intf_id=intf_id, gemport_id=gemport_id,
-                classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action))
-
+            onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
+            access_intf_id=intf_id, gemport_id=gemport_id,
+            classifier=self.mk_classifier(uplink_classifier),
+            action=self.mk_action(uplink_action))
 
         self.stub.FlowAdd(flow)
 
         self.log.debug('add downstream flow', classifier=downlink_classifier,
-                action=downlink_action, gemport_id=gemport_id, flow_id=flow_id)
+                       action=downlink_action, gemport_id=gemport_id,
+                       flow_id=flow_id)
 
         flow = openolt_pb2.Flow(
                 onu_id=onu_id, flow_id=flow_id, flow_type="downstream",
@@ -216,18 +223,20 @@
         flow_id = platform.mk_flow_id(intf_id, onu_id, DHCP_FLOW_INDEX)
 
         upstream_flow = openolt_pb2.Flow(
-                onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
-                access_intf_id=intf_id, gemport_id=gemport_id,
-                classifier=self.mk_classifier(classifier), action=self.mk_action(action))
+            onu_id=onu_id, flow_id=flow_id, flow_type="upstream",
+            access_intf_id=intf_id, gemport_id=gemport_id,
+            classifier=self.mk_classifier(classifier),
+            action=self.mk_action(action))
 
         self.stub.FlowAdd(upstream_flow)
 
     def add_eapol_flow(self, intf_id, onu_id, uplink_classifier, uplink_action,
-            uplink_eapol_id=EAPOL_FLOW_INDEX,
-            downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX,
-            vlan_id=DEFAULT_MGMT_VLAN):
+                       uplink_eapol_id=EAPOL_FLOW_INDEX,
+                       downlink_eapol_id=EAPOL_DOWNLINK_FLOW_INDEX,
+                       vlan_id=DEFAULT_MGMT_VLAN):
 
-        self.log.debug('add eapol flow', classifier=uplink_classifier, action=uplink_action)
+        self.log.debug('add eapol flow', classifier=uplink_classifier,
+                       action=uplink_action)
 
         downlink_classifier = dict(uplink_classifier)
         downlink_action = dict(uplink_action)
@@ -242,22 +251,24 @@
         uplink_action['trap_to_host'] = True
 
         upstream_flow = openolt_pb2.Flow(
-                onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream",
-                access_intf_id=intf_id,gemport_id=gemport_id,
-                classifier=self.mk_classifier(uplink_classifier), action=self.mk_action(uplink_action))
+            onu_id=onu_id, flow_id=uplink_flow_id, flow_type="upstream",
+            access_intf_id=intf_id, gemport_id=gemport_id,
+            classifier=self.mk_classifier(uplink_classifier),
+            action=self.mk_action(uplink_action))
 
         self.stub.FlowAdd(upstream_flow)
 
         # Add Downstream EAPOL Flow.
-        downlink_flow_id = platform.mk_flow_id(intf_id, onu_id, downlink_eapol_id)
+        downlink_flow_id = platform.mk_flow_id(intf_id, onu_id,
+                                               downlink_eapol_id)
         downlink_classifier['pkt_tag_type'] = 'single_tag'
         downlink_classifier['vlan_vid'] = vlan_id
 
         downstream_flow = openolt_pb2.Flow(
-                onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream",
-                access_intf_id=intf_id, gemport_id=gemport_id,
-                classifier=self.mk_classifier(downlink_classifier), action=self.mk_action(downlink_action))
-
+            onu_id=onu_id, flow_id=downlink_flow_id, flow_type="downstream",
+            access_intf_id=intf_id, gemport_id=gemport_id,
+            classifier=self.mk_classifier(downlink_classifier),
+            action=self.mk_action(downlink_action))
 
         self.stub.FlowAdd(downstream_flow)
 
@@ -298,15 +309,15 @@
     def mk_action(self, action_info):
         action = openolt_pb2.Action()
 
-	if 'pop_vlan' in action_info:
-	    action.o_vid = action_info['vlan_vid']
+        if 'pop_vlan' in action_info:
+            action.o_vid = action_info['vlan_vid']
             action.cmd.remove_outer_tag = True
-	elif 'push_vlan' in action_info:
-	    action.o_vid = action_info['vlan_vid']
+        elif 'push_vlan' in action_info:
+            action.o_vid = action_info['vlan_vid']
             action.cmd.add_outer_tag = True
-	elif 'trap_to_host' in action_info:
+        elif 'trap_to_host' in action_info:
             action.cmd.trap_to_host = True
-	else:
-	    self.log.info('Invalid-action-field')
-	    return
+        else:
+            self.log.info('Invalid-action-field')
+            return
         return action
diff --git a/voltha/adapters/openolt/openolt_platform.py b/voltha/adapters/openolt/openolt_platform.py
index 581c15d..d1d7c92 100644
--- a/voltha/adapters/openolt/openolt_platform.py
+++ b/voltha/adapters/openolt/openolt_platform.py
@@ -92,40 +92,50 @@
 
 """
 
+
 def mk_uni_port_num(intf_id, onu_id):
     return intf_id << 11 | onu_id << 4
 
+
 def mk_alloc_id(onu_id, idx=0):
     # FIXME - driver should do prefixing 1 << 10 as it is Maple specific
-    #return 1<<10 | onu_id<<6 | idx
-    return 1023 + onu_id # FIXME
+    # return 1<<10 | onu_id<<6 | idx
+    return 1023 + onu_id  # FIXME
+
 
 def mk_gemport_id(onu_id, idx=0):
-    return 1<<10 | onu_id<<3 | idx
+    return 1 << 10 | onu_id << 3 | idx
+
 
 def onu_id_from_gemport_id(gemport_id):
-    return (gemport_id & ~(1<<10)) >> 3
+    return (gemport_id & ~(1 << 10)) >> 3
+
 
 def mk_flow_id(intf_id, onu_id, idx):
-    return intf_id<<11 | onu_id<<4  | idx
+    return intf_id << 11 | onu_id << 4 | idx
+
 
 def onu_id_from_port_num(port_num):
     return (port_num >> 4) & 0x7F
 
+
 def intf_id_from_uni_port_num(port_num):
     return (port_num >> 11) & 0xF
 
+
 def intf_id_from_pon_port_no(port_no):
     return port_no & 0xF
 
+
 def intf_id_to_port_no(intf_id, intf_type):
     if intf_type is Port.ETHERNET_NNI:
         # FIXME - Remove hardcoded '128'
         return intf_id + 128
     elif intf_type is Port.PON_OLT:
-        return 0x2<<28 | intf_id
+        return 0x2 << 28 | intf_id
     else:
         raise Exception('Invalid port type')
 
+
 def intf_id_from_nni_port_num(port_num):
     return port_num - 128