Merge "Fix updating assigned mano-role breaks permission" into projects
diff --git a/common/python/rift/mano/dts/subscriber/core.py b/common/python/rift/mano/dts/subscriber/core.py
index 63cb321..7bf94f6 100644
--- a/common/python/rift/mano/dts/subscriber/core.py
+++ b/common/python/rift/mano/dts/subscriber/core.py
@@ -114,8 +114,11 @@
             except Exception as e:
                 self.log.exception(e)
 
-            finally:
+            try:
                 xact_info.respond_xpath(rwdts.XactRspCode.ACK)
+            except rift.tasklets.dts.ResponseError as e:
+                self._log.error("Reg handle is None during action {} for {}: {}".
+                                format(action, self.__class__, e))
 
         reg_event = asyncio.Event(loop=self.loop)
 
@@ -166,9 +169,15 @@
             if xact.xact is None:
                 if action == rwdts.AppconfAction.INSTALL:
                     try:
-                        for cfg in self.reg.elements:
-                            if self.callback:
-                                self.callback(cfg, rwdts.QueryAction.CREATE)
+                        if self.reg:
+                            for cfg in self.reg.elements:
+                                if self.callback:
+                                    self.callback(cfg, rwdts.QueryAction.CREATE)
+
+                        else:
+                            self._log.error("Reg handle is None during action {} for {}".
+                                            format(action, self.__class__))
+
                     except Exception as e:
                         self._log.exception("Adding config {} during restart failed: {}".
                                             format(cfg, e))
@@ -193,7 +202,12 @@
             """ on prepare callback """
             self._log.debug("Subscriber DTS prepare for project %s: %s",
                             self.project, xact_info.query_action)
-            xact_info.respond_xpath(rwdts.XactRspCode.ACK)
+            try:
+                xact_info.respond_xpath(rwdts.XactRspCode.ACK)
+            except rift.tasklets.dts.ResponseError as e:
+                self._log.error(
+                    "Subscriber DTS prepare for project {}, action {} in class {} failed: {}".
+                    format(self.project, xact_info.query_action, self.__class__, e))
 
         acg_hdl = rift.tasklets.AppConfGroup.Handler(on_apply=on_apply)
         with self.dts.appconf_group_create(handler=acg_hdl) as acg:
diff --git a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py
index 061ade0..907831a 100755
--- a/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py
+++ b/rwlaunchpad/plugins/rwnsm/rift/tasklets/rwnsmtasklet/rwnsmtasklet.py
@@ -2856,7 +2856,9 @@
                         self._nsm.update_nsd(cfg)
 
             else:
-                self._log.error("No reg handle for {} for project {}".
+                # This can happen if we do the deregister
+                # during project delete before this is called
+                self._log.debug("No reg handle for {} for project {}".
                                 format(self.__class__, self._project.name))
 
             scratch.pop('nsds', None)
@@ -2905,9 +2907,10 @@
 
             xact_info.respond_xpath(rwdts.XactRspCode.ACK)
 
+        xpath = self._project.add_project(NsdDtsHandler.XPATH)
         self._log.debug(
             "Registering for NSD config using xpath: %s",
-            NsdDtsHandler.XPATH,
+            xpath,
             )
 
         acg_hdl = rift.tasklets.AppConfGroup.Handler(on_apply=on_apply)
@@ -2915,7 +2918,7 @@
             # Need a list in scratch to store NSDs to create/update later
             # acg._scratch['nsds'] = list()
             self._regh = acg.register(
-                xpath=self._project.add_project(NsdDtsHandler.XPATH),
+                xpath=xpath,
                 flags=rwdts.Flag.SUBSCRIBER | rwdts.Flag.DELTA_READY | rwdts.Flag.CACHE,
                 on_prepare=on_prepare)
 
@@ -2982,8 +2985,9 @@
         @asyncio.coroutine
         def on_prepare(dts, acg, xact, xact_info, ks_path, msg, scratch):
             """ on prepare callback """
+            xpath = ks_path.to_xpath(NsdYang.get_schema())
             self._log.debug("Got on prepare for VNFD (path: %s) (action: %s) (msg: %s)",
-                            ks_path.to_xpath(NsdYang.get_schema()), xact_info.query_action, msg)
+                            xpath, xact_info.query_action, msg)
 
             fref = ProtobufC.FieldReference.alloc()
             fref.goto_whole_message(msg.to_pbcm())
@@ -2998,7 +3002,13 @@
                 vnfds = scratch.setdefault('vnfds', [])
                 vnfds.append(msg.id)
 
-            xact_info.respond_xpath(rwdts.XactRspCode.ACK)
+            try:
+                xact_info.respond_xpath(rwdts.XactRspCode.ACK)
+            except rift.tasklets.dts.ResponseError as e:
+                self._log.error(
+                    "VnfdDtsHandler in project {} with path {} for action {} failed: {}".
+                    format(self._project, xpath, xact_info.query_action, e))
+
 
         xpath = self._project.add_project(VnfdDtsHandler.XPATH)
         self._log.debug(
@@ -3805,7 +3815,7 @@
         self._conf_url = "https://{ip}:{port}/api/config". \
                        format(ip=self._ip,
                               port=self._rport)
-        
+
         self._nsrs = {}
         self._nsds = {}
         self._vnfds = {}
diff --git a/rwlaunchpad/plugins/rwpkgmgr/test/utest_publisher_dts.py b/rwlaunchpad/plugins/rwpkgmgr/test/utest_publisher_dts.py
index 1606ad2..9a8b0e7 100755
--- a/rwlaunchpad/plugins/rwpkgmgr/test/utest_publisher_dts.py
+++ b/rwlaunchpad/plugins/rwpkgmgr/test/utest_publisher_dts.py
@@ -169,14 +169,16 @@
         # Here, we are assuming that there is no HTTP server at 10.1.2.3
         url = "http://10.1.2.3/common/unittests/plantuml.jar"
         url_downloader = downloader.PackageFileDownloader(url, "1", "/", "VNFD", proxy)
+        self.log.debug("Downloader url: {}".format(url_downloader))
 
         download_id = yield from self.job_handler.register_downloader(url_downloader)
+        self.log.debug("Download id: {}".format(download_id))
         assert download_id is not None
-       
+
         # Waiting for 10 secs to be sure all reconnect attempts have been exhausted
         yield from asyncio.sleep(10, loop=self.loop)
-        xpath = "/download-jobs/job[download-id='{}']".format(
-            download_id)
+        xpath = self.project.add_project("/download-jobs/job[download-id='{}']".
+                                         format(download_id))
         result = yield from self.read_xpath(xpath)
         self.log.debug("Test result before complete check - %s", result)
         assert result.status == "FAILED"
diff --git a/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py b/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py
index 50e7f26..96ccaf8 100755
--- a/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py
+++ b/rwlaunchpad/plugins/rwvnfm/rift/tasklets/rwvnfmtasklet/rwvnfmtasklet.py
@@ -2061,8 +2061,9 @@
         @asyncio.coroutine
         def on_prepare(dts, acg, xact, xact_info, ks_path, msg, scratch):
             """ on prepare callback """
+            xpath = ks_path.to_xpath(RwVnfmYang.get_schema())
             self._log.debug("Got on prepare for VNFD (path: %s) (action: %s) (msg: %s)",
-                            ks_path.to_xpath(RwVnfmYang.get_schema()),
+                            xpath,
                             xact_info.query_action, msg)
             fref = ProtobufC.FieldReference.alloc()
             fref.goto_whole_message(msg.to_pbcm())
@@ -2078,7 +2079,12 @@
                 # Delete a VNFD record
                 yield from self._vnfm.delete_vnfd(msg.id)
 
-            xact_info.respond_xpath(rwdts.XactRspCode.ACK)
+            try:
+                xact_info.respond_xpath(rwdts.XactRspCode.ACK)
+            except rift.tasklets.dts.ResponseError as e:
+                self._log.error(
+                    "VnfdDtsHandler in project {} with path {} for action {} failed: {}".
+                    format(self._vnfm._project, xpath, xact_info.query_action, e))
 
         xpath = self._vnfm._project.add_project(VnfdDtsHandler.XPATH)
         self._log.debug("Registering for VNFD config using xpath: {}".