[15746] Pkgmgr subscriber should not create a folder if the uploader has already...
[osm/SO.git] / rwlaunchpad / plugins / rwpkgmgr / rift / tasklets / rwpkgmgr / subscriber / download_status.py
index 8fd041e..b7bed38 100644 (file)
@@ -57,9 +57,9 @@ class VnfdStatusSubscriber(DownloadStatusSubscriber):
         self.log.debug(log_msg)
         if action == RwDts.QueryAction.UPDATE:
             actionCreate(self, msg)
-
-        elif action == RwDts.QueryAction.DELETE:
-            actionDelete(self, msg)
+        else:
+            self.log.debug("VnfdStatusSubscriber: No action for {}".format(repr(action)))
+            pass
 
     def get_xpath(self): 
         return self.subscriber.get_xpath() 
@@ -79,9 +79,9 @@ class NsdStatusSubscriber(DownloadStatusSubscriber):
         self.log.debug(log_msg)
         if action == RwDts.QueryAction.UPDATE:
             actionCreate(self, msg)
-
-        elif action == RwDts.QueryAction.DELETE:
-            actionDelete(self, msg)
+        else:
+            self.log.debug("NsdStatusSubscriber: No action for {}".format(repr(action)))
+            pass
 
     def get_xpath(self): 
         return self.subscriber.get_xpath() 
@@ -92,25 +92,24 @@ def actionCreate(descriptor, msg):
     Serialize the Vnfd/Nsd object to yaml and store yaml file in the created folder.
     '''
 
-    download_dir = os.path.join(descriptor.DOWNLOAD_DIR, msg.id, msg.name)
-
-    if not os.path.exists(download_dir):
-        os.makedirs(download_dir)
-        descriptor.log.debug("Created directory {}".format(download_dir))
-
-        model = RwYang.Model.create_libncx()
-        for module in descriptor.MODULE_DESC: model.load_module(module)
-
-        yaml_path = "{base}/{name}_{type}.yaml".format(base=download_dir, name=msg.name, type=descriptor.DESC_TYPE) 
-        with open(yaml_path,"w") as fh:
-            fh.write(msg.to_yaml(model))
-
-def actionDelete(descriptor, msg): 
-    ''' Delete folder structure created above.
-    '''
-
+    desc_name = msg.name if msg.name else ""
     download_dir = os.path.join(descriptor.DOWNLOAD_DIR, msg.id)
-    if os.path.exists(download_dir):
-        descriptor.log.debug("Removing directory {}".format(download_dir))
-        shutil.rmtree(download_dir)
+
+    # If a download dir is present with contents, then we know it has been created in the 
+    # upload path. 
+    if os.path.exists(download_dir) and os.listdir(download_dir):
+        descriptor.log.debug("Skpping folder creation, {} already present".format(download_dir))
+        return
+    else: 
+        download_dir = os.path.join(download_dir, desc_name) 
+        if not os.path.exists(download_dir):
+            os.makedirs(download_dir)
+            descriptor.log.debug("Created directory {}".format(download_dir))
+
+            model = RwYang.Model.create_libncx()
+            for module in descriptor.MODULE_DESC: model.load_module(module)
+
+            yaml_path = "{base}/{name}_{type}.yaml".format(base=download_dir, name=msg.name, type=descriptor.DESC_TYPE) 
+            with open(yaml_path,"w") as fh:
+                fh.write(msg.to_yaml(model))