VOL-1452 Changes to activate olt. Merge latest.

Change-Id: I2c66cb5589bd4274be1cc9d0fddadc2527f5d8b4
diff --git a/python/adapters/openolt/openolt_device.py b/python/adapters/openolt/openolt_device.py
index ea5e8e2..162f323 100644
--- a/python/adapters/openolt/openolt_device.py
+++ b/python/adapters/openolt/openolt_device.py
@@ -21,7 +21,7 @@
 import structlog
 import time
 from twisted.internet import reactor
-from twisted.internet.defer import inlineCallbacks
+from twisted.internet.defer import inlineCallbacks, returnValue
 from scapy.layers.l2 import Ether, Dot1Q
 from transitions import Machine
 
@@ -135,7 +135,7 @@
                                send_event=True, initial='state_null')
         self.go_state_init()
 
-    def create_logical_device(self, device_info):
+def create_logical_device(self, device_info):
         dpid = device_info.device_id
         serial_number = device_info.device_serial_number
 
@@ -160,7 +160,7 @@
         sw_desc = device_info.firmware_version
         hw_desc = device_info.model
         if device_info.hardware_version: hw_desc += '-' + device_info.hardware_version
-	"""
+
         # Create logical OF device
         ld = LogicalDevice(
             root_device_id=self.device_id,
@@ -179,27 +179,13 @@
             )
         )
         ld_init = self.adapter_agent.create_logical_device(ld,
-	
-	nni_port = Port(
-                port_no=info.nni_port,
-                label='NNI facing Ethernet port',
-                type=Port.ETHERNET_NNI,
-                oper_status=OperStatus.ACTIVE
-            )
-            self.nni_port = nni_port
-            yield self.core_proxy.port_created(device.id, nni_port)
-            yield self.core_proxy.port_created(device.id, Port(
-                port_no=1,
-                label='PON port',
-                type=Port.PON_OLT,
-                oper_status=OperStatus.ACTIVE
-            ))                                                           dpid=dpid)
-	"""
+                                                           dpid=dpid)
+
         self.logical_device_id = ld_init.id
 
         device = self.adapter_agent.get_device(self.device_id)
         device.serial_number = serial_number
-        self.adapter_agent.device_update(device)
+        self.adapter_agent.update_device(device)
 
         self.dpid = dpid
         self.serial_number = serial_number
@@ -293,7 +279,7 @@
                                               self.logical_device_id,
                                               self.platform)
         self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform)
-        self.bw_mgr = self.bw_mgr_class(self.log, self.proxy)
+        self.bw_mgr = self.bw_mgr_class(self.log, self.adapter_agent)
 
         device.vendor = device_info.vendor
         device.model = device_info.model
@@ -303,19 +289,15 @@
         # TODO: check for uptime and reboot if too long (VOL-1192)
 
         device.connect_status = ConnectStatus.REACHABLE
+	device.mac_address = "AA:BB:CC:DD:EE:FF"
         self.adapter_agent.device_update(device)
  
-    @inlineCallbacks
     def do_state_up(self, event):
         self.log.debug("do_state_up")
 
-        device = yield self.adapter_agent.get_device(self.device_id)
-	self.log.debug("do_state_up set  device active", device=device)
-        # Update phys OF device
-        #device.parent_id = self.logical_device_id
-        device.oper_status = OperStatus.ACTIVE
-	self.log.debug("Updating to Active", device=device)
-        self.adapter_agent.device_update(device)
+	self.adapter_agent.device_state_update(self.device_id,
+                                                      connect_status=ConnectStatus.REACHABLE,
+                                                      oper_status=OperStatus.ACTIVE)
 
     def do_state_down(self, event):
         self.log.debug("do_state_down")
@@ -881,6 +863,7 @@
             mac = ':%02x' % ((port_no >> (i * 8)) & 0xff) + mac
         return '00:00' + mac
 
+    @inlineCallbacks
     def add_port(self, intf_id, port_type, oper_status):
         port_no = self.platform.intf_id_to_port_no(intf_id, port_type)
 
@@ -892,9 +875,10 @@
         port = Port(port_no=port_no, label=label, type=port_type,
                     admin_state=AdminState.ENABLED, oper_status=oper_status)
 
-        self.adapter_agent.add_port(self.device_id, port)
+	yield self.adapter_agent.port_created(self.device_id, port)
+        #self.adapter_agent.add_port(self.device_id, port)
 
-        return port_no, label
+        returnValue(port_no, label)
 
     def delete_logical_port(self, child_device):
         logical_ports = self.proxy.get('/logical_devices/{}/ports'.format(
diff --git a/python/compose/adapters-openolt.yml b/python/compose/adapters-openolt.yml
index d9599ae..dba89cf 100644
--- a/python/compose/adapters-openolt.yml
+++ b/python/compose/adapters-openolt.yml
@@ -28,6 +28,8 @@
       "--name=openolt",
       "--kafka_adapter=${DOCKER_HOST_IP}:9092",
       "--kafka_cluster=${DOCKER_HOST_IP}:9092",
+      "--backend=etcd",
+      "--etcd=${DOCKER_HOST_IP}:2379"
       "--core_topic=rwcore"
     ]
     networks: