BUG 402 : Raising Exception if the charm directory is not found
[osm/SO.git] / rwcm / plugins / rwconman / rift / tasklets / rwconmantasklet / jujuconf.py
index 0b7ecae..b003df8 100644 (file)
@@ -190,8 +190,11 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
                                 charm)
             self._log.debug("jujuCA: Charm dir is {}".format(path))
             if not os.path.isdir(path):
-                self._log.error("jujuCA: Did not find the charm directory at {}".format(path))
+                msg = "jujuCA: Did not find the charm directory at {}".format(path)
+                self._log.error(msg)
                 path = None
+                # Return from here instead of forwarding the config request to juju_api
+                raise Exception(msg)
         except Exception as e:
             self.log.exception(e)
             return False
@@ -199,12 +202,13 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
         if vnf_unique_name not in self._tasks:
             self._tasks[vnf_unique_name] = {}
 
-        self._tasks[vnf_unique_name]['deploy'] = self.loop.create_task(
-            self.api.deploy_application(charm, vnf_unique_name, path=path))
-
         self._log.debug("jujuCA: Deploying service %s",
                         vnf_unique_name)
-
+        yield from self.api.deploy_application(
+            charm,
+            vnf_unique_name,
+            path=path,
+        )
         return True
 
     @asyncio.coroutine
@@ -239,19 +243,18 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
             vnfr = agent_vnfr.vnfr
             service = vnfr['vnf_juju_name']
 
-            self._log.debug ("jujuCA: Terminating VNFr %s, %s",
-                             agent_vnfr.name, service)
-            self._tasks[service]['destroy'] = self.loop.create_task(
-                    self.api.remove_application(service)
-                )
+            self._log.debug("jujuCA: Terminating VNFr {}, {}".format(
+                agent_vnfr.name,
+                service,
+            ))
+            yield from self.api.remove_application(service)
 
             del self._juju_vnfs[agent_vnfr.id]
-            self._log.debug ("jujuCA: current vnfrs={}".
-                             format(self._juju_vnfs))
+            self._log.debug("jujuCA: current vnfrs={}".
+                            format(self._juju_vnfs))
             if service in self._tasks:
                 tasks = []
                 for action in self._tasks[service].keys():
-                    #if self.check_task_status(service, action):
                     tasks.append(action)
                 del tasks
         except KeyError as e:
@@ -270,35 +273,6 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
         """
         return True
 
-    def check_task_status(self, service, action):
-        #self.log.debug("jujuCA: check task status for %s, %s" % (service, action))
-        try:
-            task = self._tasks[service][action]
-            if task.done():
-                self.log.debug("jujuCA: Task for %s, %s done" % (service, action))
-                e = task.exception()
-                if e:
-                    self.log.error("jujuCA: Error in task for {} and {} : {}".
-                                   format(service, action, e))
-                    raise Exception(e)
-                r= task.result()
-                if r:
-                    self.log.debug("jujuCA: Task for {} and {}, returned {}".
-                                   format(service, action,r))
-                return True
-            else:
-                self.log.debug("jujuCA: task {}, {} not done".
-                               format(service, action))
-                return False
-        except KeyError as e:
-            self.log.error("jujuCA: KeyError for task for {} and {}: {}".
-                           format(service, action, e))
-        except Exception as e:
-            self.log.error("jujuCA: Error for task for {} and {}: {}".
-                           format(service, action, e))
-            raise
-        return True
-
     @asyncio.coroutine
     def _vnf_config_primitive(self, nsr_id, vnfr_id, primitive,
                               vnf_config=None, wait=False):
@@ -732,12 +706,13 @@ class JujuConfigPlugin(riftcm_config_plugin.RiftCMConfigPluginBase):
 
         rc = 'configuring'
 
-        if not self.check_task_status(service, 'deploy'):
-            return rc
-
         try:
-            resp = yield from self.api.get_service_status(application=service)
-            self._log.debug("jujuCA: Get service %s status? %s", service, resp)
+            # Get the status of the application
+            resp = yield from self.api.get_application_status(service)
+
+            # No status means the application is still pending deployment
+            if resp is None:
+                return rc
 
             if resp == 'error':
                 return 'error'