[SEBA-739] Proper ONOS lookup in kubernetes event handler
Correct path for tech-profile sync-step

Change-Id: I48d7536986ddf58d876c4d5bfcafdd89855e8d15
diff --git a/xos/synchronizer/event_steps/kubernetes_event.py b/xos/synchronizer/event_steps/kubernetes_event.py
index 8eed0c4..35d3ac1 100644
--- a/xos/synchronizer/event_steps/kubernetes_event.py
+++ b/xos/synchronizer/event_steps/kubernetes_event.py
@@ -17,10 +17,12 @@
 import json
 import os
 import sys
+sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 from xossynchronizer.event_steps.eventstep import EventStep
 from xossynchronizer.modelaccessor import VOLTService, VOLTServiceInstance, Service
 from xosconfig import Config
 from multistructlog import create_logger
+from helpers import Helpers
 
 log = create_logger(Config().get('logging'))
 
@@ -31,18 +33,6 @@
     def __init__(self, *args, **kwargs):
         super(KubernetesPodDetailsEventStep, self).__init__(*args, **kwargs)
 
-    @staticmethod
-    def get_onos(service):
-        service = Service.objects.get(id=service.id)
-
-        # get the onos_fabric service
-        onos = [s.leaf_model for s in service.subscriber_services if "onos" in s.name.lower()]
-
-        if len(onos) == 0:
-            raise Exception('Cannot find ONOS service in provider_services of Fabric-Crossconnect')
-
-        return onos[0]
-
     def process_event(self, event):
         value = json.loads(event.value)
 
@@ -57,8 +47,9 @@
             return
 
         for service in VOLTService.objects.all():
-            onos = KubernetesPodDetailsEventStep.get_onos(service)
-            if (onos.name.lower() != xos_service.lower()):
+            onos = Helpers.get_onos_service_name(service)
+            # NOTE do we really need to dynamically fetch the ONOS name?
+            if (onos.lower() != xos_service.lower()):
                 continue
 
             for service_instance in service.service_instances.all():
diff --git a/xos/synchronizer/event_steps/test_kubernetes_event.py b/xos/synchronizer/event_steps/test_kubernetes_event.py
index 3bbc4ec..b30c6d5 100644
--- a/xos/synchronizer/event_steps/test_kubernetes_event.py
+++ b/xos/synchronizer/event_steps/test_kubernetes_event.py
@@ -69,7 +69,7 @@
                                                    id=1112,
                                                    backend_code=1,
                                                    backend_status="succeeded",
-                                                   subscriber_services=[self.onos])
+                                                    provider_services=[self.onos])
 
         self.fcsi1 = VOLTServiceInstance(name="myfcsi1",
                                                        owner=self.fcservice,
diff --git a/xos/synchronizer/helpers.py b/xos/synchronizer/helpers.py
index ade07e0..1c52a1a 100644
--- a/xos/synchronizer/helpers.py
+++ b/xos/synchronizer/helpers.py
@@ -30,15 +30,25 @@
         }
 
     @staticmethod
-    def get_onos_voltha_info(olt_service):
-
-        # get the onos_fabric service
+    def get_onos(olt_service):
+        # get the onos service
         onos = [s.leaf_model for s in olt_service.provider_services if "onos" in s.name.lower()]
 
         if len(onos) == 0:
             raise Exception('Cannot find ONOS service in provider_services of vOLTService')
 
-        onos = onos[0]
+        return onos[0]
+
+    @staticmethod
+    def get_onos_service_name(olt_service):
+        onos = Helpers.get_onos(olt_service)
+
+        return onos.name
+
+    @staticmethod
+    def get_onos_voltha_info(olt_service):
+
+        onos = Helpers.get_onos(olt_service)
 
         return {
             'url': Helpers.format_url(onos.rest_hostname),
diff --git a/xos/synchronizer/models/volt.xproto b/xos/synchronizer/models/volt.xproto
index e7fef4b..5abdf6f 100644
--- a/xos/synchronizer/models/volt.xproto
+++ b/xos/synchronizer/models/volt.xproto
@@ -212,6 +212,7 @@
     option verbose_name = "vOLT Service Instance";
     option description = "Represents subscriber tenancy in the VOLT Service";
     option policy_implemented = "True";
+    option sync_implemented = "True";
 
     optional string description = 1 [
         help_text = "Human-readable description",
diff --git a/xos/synchronizer/steps/sync_tech_profile.py b/xos/synchronizer/steps/sync_tech_profile.py
index 01e7da3..3c36f36 100644
--- a/xos/synchronizer/steps/sync_tech_profile.py
+++ b/xos/synchronizer/steps/sync_tech_profile.py
@@ -26,8 +26,10 @@
 
 import etcd3
 
+# TODO store ETCD_HOST_URL and ETCD_PORT in the vOLT Service model
 ETCD_HOST_URL = 'etcd-cluster.default.svc.cluster.local'
 ETCD_PORT = 2379
+PREFIX = "service/voltha/technology_profiles"
 
 log = create_logger(Config().get("logging"))
 
@@ -41,10 +43,10 @@
 
         etcd = etcd3.client(host=ETCD_HOST_URL, port=ETCD_PORT)
         if operation == 'PUT':
-           etcd.put(key, value)
-           log.info('Technology Profile [%s] saved successfully to Etcd store' % key)
+           etcd.put(PREFIX + key, value)
+           log.info('Technology Profile [%s] saved successfully to Etcd store' % (PREFIX + key))
         elif operation == 'DELETE':
-           if False == etcd.delete(key):
+           if False == etcd.delete(PREFIX + key):
                log.error('Error while deleting Technology Profile [%s] from Etcd store' % key)
                raise Exception('Failed to delete Technology Profile')
            else:
diff --git a/xos/synchronizer/test_helpers.py b/xos/synchronizer/test_helpers.py
index a2b392d..89da55b 100644
--- a/xos/synchronizer/test_helpers.py
+++ b/xos/synchronizer/test_helpers.py
@@ -26,6 +26,7 @@
         # create a mock ONOS Service
         onos = Mock()
         onos.name = "ONOS"
+        onos.leaf_model.name = "ONOS"
         onos.leaf_model.rest_hostname = "onos_voltha_url"
         onos.leaf_model.rest_port = 4321
         onos.leaf_model.rest_username = "onos_voltha_user"
@@ -48,6 +49,10 @@
         url = Helpers.format_url("http://onf.com")
         self.assertEqual(url, "http://onf.com")
 
+    def test_get_onos_service_name(self):
+        name = Helpers.get_onos_service_name(self.o)
+        self.assertEqual(name, "ONOS")
+
     def test_get_voltha_info(self):
         voltha_dict = Helpers.get_voltha_info(self.o)