SEBA-749 Implemented on demand api code for test action in pyvoltha

Change-Id: Ib7a50bcfdb2f2f28b50406f92539415c92fcd0f1
diff --git a/VERSION b/VERSION
index a4c8060..951d17f 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.3.22
+2.3.23
diff --git a/pyvoltha/adapters/extensions/omci/tasks/omci_test_request.py b/pyvoltha/adapters/extensions/omci/tasks/omci_test_request.py
index f64fda0..44d97c8 100644
--- a/pyvoltha/adapters/extensions/omci/tasks/omci_test_request.py
+++ b/pyvoltha/adapters/extensions/omci/tasks/omci_test_request.py
@@ -28,7 +28,7 @@
 from voltha_protos.events_pb2 import MetricInformation, MetricMetaData
 from voltha_protos.events_pb2 import Event, EventType, EventCategory, \
     EventSubCategory, EventHeader
-from voltha_protos.events_pb2 import Event
+from google.protobuf.timestamp_pb2 import Timestamp
 import six
 
 RC = ReasonCodes
@@ -57,7 +57,7 @@
     def __init__(self, core_proxy, omci_agent, device_id, entity_class,
                  serial_number,
                  logical_device_id,
-                 exclusive=True, allow_failure=False, **kwargs):
+                 exclusive=True, uuid=None, allow_failure=False, **kwargs):
         """
         Class initialization
 
@@ -92,6 +92,7 @@
         self.serial_number = serial_number
         self.logical_device_id = logical_device_id
         self.core_proxy = core_proxy
+        self.uuid = uuid
         topic = 'omci-rx:{}:{}'.format(self.device_id, 'Test_Result')
         self.msg = self.event_bus.subscribe(topic, self.process_messages)
 
@@ -158,14 +159,15 @@
 
         :return: (dict) Event header
         """
-        return EventHeader(id=self.format_id(event),
-                           category=category,
-                           sub_category=sub_category,
-                           type=_type,
-                           type_version="0.1",
-                           raised_ts=raised_ts,
-                           reported_ts=arrow.utcnow().timestamp
-                           )
+        hdr = EventHeader(id=self.format_id(event),
+                          category=category,
+                          sub_category=sub_category,
+                          type=_type,
+                          type_version="0.1",
+                          raised_ts=raised_ts
+                          )
+        hdr.reported_ts.GetCurrentTime()
+        return hdr
 
     def publish_metrics(self, data, event_name, onu_device_id):
         """
@@ -181,15 +183,19 @@
                                     logical_device_id=self.logical_device_id,
                                     serial_no=self.serial_number,
                                     device_id=onu_device_id,
+                                    uuid=self.uuid,
                                     context={
                                         'events': event_name
                                     }),
             metrics=data)
         self.log.info('Publish-Test-Result')
+        raised_ts = Timestamp()
+        raised_ts.GetCurrentTime()
         event_header = self.get_event_header(EventType.KPI_EVENT2,
                                              EventCategory.EQUIPMENT,
-                                             EventSubCategory.ONU, "KPI_EVENT",
-                                             arrow.utcnow().timestamp)
+                                             EventSubCategory.ONU,
+                                             "KPI_EVENT",
+                                             raised_ts)
         kpi_event = KpiEvent2(
             type=KpiEventType.slice,
             ts=arrow.utcnow().float_timestamp,
diff --git a/pyvoltha/adapters/kafka/adapter_request_facade.py b/pyvoltha/adapters/kafka/adapter_request_facade.py
index 4780153..72bf076 100644
--- a/pyvoltha/adapters/kafka/adapter_request_facade.py
+++ b/pyvoltha/adapters/kafka/adapter_request_facade.py
@@ -30,9 +30,11 @@
 from voltha_protos.device_pb2 import Device, Port, ImageDownload, SimulateAlarmRequest
 from voltha_protos.openflow_13_pb2 import FlowChanges, FlowGroups, Flows, \
     FlowGroupChanges, ofp_packet_out
+from voltha_protos.voltha_pb2 import OmciTestRequest
 from pyvoltha.adapters.kafka.kafka_inter_container_library import IKafkaMessagingProxy, \
     get_messaging_proxy, KAFKA_OFFSET_LATEST, KAFKA_OFFSET_EARLIEST, ARG_FROM_TOPIC
 
+
 log = structlog.get_logger()
 
 class MacAddressError(BaseException):
@@ -78,6 +80,21 @@
     #     yield kafka_proxy.subscribe(topic=device_topic, group_id=device_topic, target_cls=self, offset=KAFKA_OFFSET_EARLIEST)
     #     log.debug("subscribed-to-topic", topic=device_topic)
 
+    def start_omci_test(self, device, omcitestrequest, **kwargs):
+        if not device:
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="device-invalid")
+        if not omcitestrequest:
+            return False, Error(code=ErrorCode.INVALID_PARAMETERS,
+                                reason="omcitestrequest-invalid")
+
+        d = Device()
+        device.Unpack(d)
+        omci_test = OmciTestRequest()
+        omcitestrequest.Unpack(omci_test)
+        result = self.adapter.start_omci_test(d, omci_test.uuid)
+        return True, result
+
     def adopt_device(self, device, **kwargs):
         d = Device()
         if device:
diff --git a/requirements.txt b/requirements.txt
index f7af3a3..016156c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -18,4 +18,4 @@
 structlog==19.2.0
 transitions==0.6.4
 txaioetcd==0.3.0
-voltha-protos==3.2.3
+voltha-protos==3.2.8