Removing a tech-profile from the data-model if that's not found in etcd

Change-Id: Ibd2848cf417eed8a06881c6d9d080728db5965e9
diff --git a/xos/synchronizer/steps/sync_tech_profile.py b/xos/synchronizer/steps/sync_tech_profile.py
index dcd5f52..ad16f00 100644
--- a/xos/synchronizer/steps/sync_tech_profile.py
+++ b/xos/synchronizer/steps/sync_tech_profile.py
@@ -16,14 +16,12 @@
 sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
 from helpers import Helpers
-
 import requests
 from multistructlog import create_logger
 from requests.auth import HTTPBasicAuth
 from xossynchronizer.modelaccessor import TechnologyProfile, model_accessor
 from xossynchronizer.steps.syncstep import SyncStep
 from xosconfig import Config
-
 import etcd3
 
 # TODO store ETCD_HOST_URL and ETCD_PORT in the vOLT Service model
@@ -33,26 +31,28 @@
 
 log = create_logger(Config().get("logging"))
 
+
 class SyncTechnologyProfile(SyncStep):
     provides = [TechnologyProfile]
 
     observes = TechnologyProfile
 
-    def update_etcd(self, operation, key, value):
+    def update_etcd(self, operation, key, value=None):
         log.info('Update Etcd store: ', operation=operation, key=PREFIX + key, value=value)
-
         etcd = etcd3.client(host=ETCD_HOST_URL, port=ETCD_PORT)
         if operation == 'PUT':
-           etcd.put(PREFIX + key, value)
-           log.info('Technology Profile [%s] saved successfully to Etcd store' % (PREFIX + key))
+            etcd.put(PREFIX + key, value)
+            log.info('Technology Profile [%s] saved successfully to Etcd store' % (PREFIX + key))
+        elif operation == 'GET':
+            return etcd.get(PREFIX + key)
         elif operation == 'DELETE':
-           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:
-               log.info('Technology Profile [%s] deleted successfully from Etcd store' % 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:
+                log.info('Technology Profile [%s] deleted successfully from Etcd store' % key)
         else:
-           log.warning('Invalid or unsupported Etcd operation: %s' % operation)
+            log.warning('Invalid or unsupported Etcd operation: %s' % operation)
 
     def sync_record(self, model):
 
@@ -61,13 +61,14 @@
         log.info('TechnologyProfile: %s : %s' % (model.technology, model.profile_id))
 
         tp_key = u'/' + model.technology + u'/' + str(model.profile_id)
-        self.update_etcd('PUT', tp_key, model.profile_value)
+        self.update_etcd('PUT', tp_key, value=model.profile_value)
 
     def delete_record(self, model):
         log.info('Deleting TechnologyProfile', object=str(model), **model.tologdict())
 
         log.info('TechnologyProfile: %s : %s' % (model.technology, model.profile_id))
 
-        tp_key = u'/' + model.technology + u'/' + str(model.profile_id)
-        self.update_etcd('DELETE', tp_key, None)
-
+        tp_key = "/%s/%s" % (model.technology, model.profile_id)
+        [existing_tp, metadata] = self.update_etcd('GET', tp_key)
+        if existing_tp is not None:
+            self.update_etcd('DELETE', tp_key)