Move fetching of device info out of openolt_grpc
Change-Id: I83fdc837b1ef9b1444867c1f77da40e27883d388
diff --git a/voltha/adapters/openolt/openolt_device.py b/voltha/adapters/openolt/openolt_device.py
index 0672037..928d1aa 100644
--- a/voltha/adapters/openolt/openolt_device.py
+++ b/voltha/adapters/openolt/openolt_device.py
@@ -14,7 +14,6 @@
# limitations under the License.
#
import binascii
-import grpc
import structlog
import time
from scapy.layers.l2 import Ether, Dot1Q
@@ -59,7 +58,8 @@
{'trigger': 'go_state_connected',
'source': 'state_init',
'dest': 'state_connected',
- 'before': 'do_state_connected'},
+ 'before': 'do_state_connected',
+ 'after': 'post_connected'},
{'trigger': 'go_state_up',
'source': ['state_connected', 'state_down'],
'dest': 'state_up',
@@ -119,11 +119,13 @@
def post_init(self, event):
self.log.debug('post_init')
- # Initialize gRPC
+
+ # FIXME
time.sleep(10)
+
self._grpc = OpenoltGrpc(self.host_and_port, self)
- self.log.info('openolt-device-created')
+ reactor.callInThread(self.get_device_info)
def do_state_connected(self, event):
self.log.debug("do_state_connected")
@@ -156,6 +158,9 @@
self.stats_mgr = self.stats_mgr_class(self, self.log, self.platform,
self.data_model)
+ def post_connected(self, event):
+ self._grpc.start()
+
def do_state_up(self, event):
self.log.debug("do_state_up")
self.data_model.olt_oper_up()
@@ -451,3 +456,32 @@
def simulate_alarm(self, alarm):
self.alarm_mgr.simulate_alarm(alarm)
+
+ def get_device_info(self):
+ self.log.debug('get_device_info')
+ timeout = 60*60
+ delay = 1
+ exponential_back_off = False
+ while True:
+ try:
+ self.device_info \
+ = self._grpc.stub.GetDeviceInfo(openolt_pb2.Empty())
+ break
+ except Exception as e:
+ if delay > timeout:
+ self.log.error("openolt grpc timed out connecting to olt")
+ return
+ else:
+ self.log.warn(
+ "openolt grpc retry connecting to olt in %ds: %s"
+ % (delay, repr(e)))
+ time.sleep(delay)
+ if exponential_back_off:
+ delay += delay
+ else:
+ delay += 1
+
+ self.log.info('openolt grpc connected to olt',
+ device_info=self.device_info)
+
+ self.go_state_connected()
diff --git a/voltha/adapters/openolt/openolt_grpc.py b/voltha/adapters/openolt/openolt_grpc.py
index 726270b..e1299db 100644
--- a/voltha/adapters/openolt/openolt_grpc.py
+++ b/voltha/adapters/openolt/openolt_grpc.py
@@ -17,7 +17,6 @@
import structlog
import grpc
import threading
-import time
from twisted.internet import reactor
from voltha.northbound.kafka.kafka_proxy import kafka_send_pb
from voltha.adapters.openolt.protos import openolt_pb2_grpc, openolt_pb2
@@ -32,7 +31,9 @@
self.host_and_port = host_and_port
self.channel = grpc.insecure_channel(self.host_and_port)
self.channel_ready_future = grpc.channel_ready_future(self.channel)
+ self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
+ def start(self):
try:
# Start indications thread
self.log.debug('openolt grpc starting')
@@ -51,37 +52,6 @@
def indications_thread(self):
- self.log.debug('openolt grpc connecting to olt')
-
- self.stub = openolt_pb2_grpc.OpenoltStub(self.channel)
-
- timeout = 60*60
- delay = 1
- exponential_back_off = False
- while True:
- try:
- self.device.device_info \
- = self.stub.GetDeviceInfo(openolt_pb2.Empty())
- break
- except Exception as e:
- if delay > timeout:
- self.log.error("openolt grpc timed out connecting to olt")
- return
- else:
- self.log.warn(
- "openolt grpc retry connecting to olt in %ds: %s"
- % (delay, repr(e)))
- time.sleep(delay)
- if exponential_back_off:
- delay += delay
- else:
- delay += 1
-
- self.log.info('openolt grpc connected to olt',
- device_info=self.device.device_info)
-
- self.device.go_state_connected()
-
self.indications = self.stub.EnableIndication(openolt_pb2.Empty())
while True: