Fix bug 1721: charms can include reference to .charm files 92/11292/1
authorDavid Garcia <david.garcia@canonical.com>
Tue, 26 Oct 2021 15:17:50 +0000 (17:17 +0200)
committerDavid Garcia <david.garcia@canonical.com>
Tue, 26 Oct 2021 15:17:50 +0000 (17:17 +0200)
Change-Id: I7bb1c468c528e390b4368e7bdb172f47066c8d48
Signed-off-by: David Garcia <david.garcia@canonical.com>
osmclient/common/package_tool.py

index 50307e7..436053c 100644 (file)
@@ -91,7 +91,9 @@ class PackageTool(object):
                 "detailed": detailed,
             }
         elif package_type == "vnf":
-            template = env.get_template("vnfd.yaml.j2" if not old else "vnfd_old.yaml.j2")
+            template = env.get_template(
+                "vnfd.yaml.j2" if not old else "vnfd_old.yaml.j2"
+            )
             content = {
                 "name": package_name,
                 "vendor": vendor,
@@ -153,7 +155,9 @@ class PackageTool(object):
                 f for f in glob.glob(base_directory + "/*.yaml", recursive=recursive)
             ]
         self._logger.info("Base directory: {}".format(base_directory))
-        self._logger.info("{} Descriptors found to validate".format(len(descriptors_paths)))
+        self._logger.info(
+            "{} Descriptors found to validate".format(len(descriptors_paths))
+        )
         for desc_path in descriptors_paths:
             with open(desc_path) as descriptor_file:
                 descriptor_data = descriptor_file.read()
@@ -538,6 +542,8 @@ class PackageTool(object):
                 else:
                     if not os.path.isdir(
                         "{}/charms/{}".format(package_folder, charmName)
+                    ) and not os.path.isfile(
+                        "{}/charms/{}".format(package_folder, charmName)
                     ):
                         raise ClientException(
                             "The charm: {} referenced in the descriptor file "
@@ -719,9 +725,12 @@ class PackageTool(object):
                             self._logger.debug(
                                 "Copying tree: {} -> {}".format(s_charm, d_temp)
                             )
-                            shutil.copytree(
-                                s_charm, d_temp, symlinks=True, ignore=ignore
-                            )
+                            if os.path.isdir(s_charm):
+                                shutil.copytree(
+                                    s_charm, d_temp, symlinks=True, ignore=ignore
+                                )
+                            else:
+                                shutil.copy2(s_charm, d_temp)
                             self._logger.debug("DONE")
                     else:
                         self._logger.debug("Copying tree: {} -> {}".format(s, d))