VOL-1535: Generate OLT connectivity related alarms in Python OpenOLT adapter

Change-Id: I9b8adba37b5e345bbf6d40c674eb3b72a63d1413
diff --git a/voltha/adapters/openolt/openolt_device.py b/voltha/adapters/openolt/openolt_device.py
index 9024322..50bc24b 100644
--- a/voltha/adapters/openolt/openolt_device.py
+++ b/voltha/adapters/openolt/openolt_device.py
@@ -26,6 +26,7 @@
 from voltha.adapters.openolt.protos import openolt_pb2_grpc, openolt_pb2
 from voltha.adapters.openolt.openolt_utils import OpenoltUtils
 from voltha.extensions.alarms.onu.onu_discovery_alarm import OnuDiscoveryAlarm
+from voltha.extensions.alarms.olt.olt_conn_lost_alarm import OltConnLostAlarm
 
 
 class OpenoltDevice(object):
@@ -159,10 +160,14 @@
 
     def do_state_up(self, event):
         self.log.debug("do_state_up")
+        self.log.debug("olt-connection-lost-alarm-cleared")
+        OltConnLostAlarm(self.alarm_mgr.alarms, serial_number = self.device_info.device_serial_number).clear_alarm()
         self.data_model.olt_oper_up()
 
     def do_state_down(self, event):
         self.log.debug("do_state_down")
+        self.log.debug("olt-connection-lost-alarm-raised")
+        OltConnLostAlarm(self.alarm_mgr.alarms, serial_number = self.device_info.device_serial_number).raise_alarm()
         self.data_model.olt_oper_down()
 
     def post_down(self, event):
diff --git a/voltha/extensions/alarms/olt/olt_conn_lost_alarm.py b/voltha/extensions/alarms/olt/olt_conn_lost_alarm.py
new file mode 100644
index 0000000..bf73302
--- /dev/null
+++ b/voltha/extensions/alarms/olt/olt_conn_lost_alarm.py
@@ -0,0 +1,29 @@
+# Copyright 2017-present Adtran, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from voltha.protos.events_pb2 import AlarmEventType, AlarmEventSeverity, AlarmEventCategory
+from voltha.extensions.alarms.adapter_alarms import AlarmBase
+
+
+class OltConnLostAlarm(AlarmBase):
+    def __init__(self, alarm_mgr, serial_number):
+        super(OltConnLostAlarm, self).__init__(alarm_mgr, object_type='olt connection lost',
+                                               alarm='OLT_CONNECTION_LOST',
+                                               alarm_category=AlarmEventCategory.OLT,
+                                               alarm_type=AlarmEventType.COMMUNICATION,
+                                               alarm_severity=AlarmEventSeverity.CRITICAL)
+        self._serial_number = serial_number
+
+    def get_context_data(self):
+        return {'olt-serial-number': self._serial_number}