artifacts = []
directories = []
for f in listdir(origin):
- if isfile(join(origin, f)) and f.endswith('.tar.gz'):
+ self._logger.debug(f"Element: {join(origin,f)}")
+ if isfile(join(origin, f)) and f.endswith(".tar.gz"):
artifacts.append(f)
elif isdir(join(origin, f)) and f != destination.split('/')[-1] and not f.startswith('.'):
directories.append(f) # TODO: Document that nested directories are not supported
else:
self._logger.debug(f"Ignoring {f}")
- for artifact in artifacts:
- self.register_artifact_in_repository(
- join(origin, artifact), destination, source="artifact"
+ self._logger.debug(f"Artifacts: {artifacts}")
+ for package in artifacts:
+ self.register_package_in_repository(
+ join(origin, package), origin, destination, kind="artifact"
)
- for artifact in directories:
- self.register_artifact_in_repository(
- join(origin, artifact), destination, source="directory"
+ self._logger.debug(f"Directories: {directories}")
+ for package in directories:
+ self.register_package_in_repository(
+ join(origin, package), origin, destination, kind="directory"
)
self._logger.info("\nFinal Results: ")
self._logger.info(
descriptor_file = glob.glob("{}/*.y*ml".format(folder))[0]
return folder, descriptor_file
- def validate_artifact(self, path, source):
+ def validate_artifact(self, path, origin, kind):
"""
Validation of artifact.
:param path: file path
- :param source: flag to select the correct file type (directory or artifact)
+ :param origin: folder where the package is located
+ :param kind: flag to select the correct file type (directory or artifact)
:return: status details, status, fields, package_type
"""
- self._logger.debug(f"Validating {path} {source}")
+ self._logger.debug(f"Validating {path} {kind}")
package_type = ""
folder = ""
try:
- if source == "directory":
+ if kind == "directory":
descriptor_file = glob.glob("{}/*.y*ml".format(path))[0]
else:
folder, descriptor_file = self.zip_extraction(path)
+ folder = join(origin, folder)
+ self._logger.debug(f"Kind is an artifact (tar.gz). Folder: {folder}. Descriptor_file: {descriptor_file}")
self._logger.debug("Opening descriptor file: {}".format(descriptor_file))
if folder:
rmtree(folder, ignore_errors=True)
- def register_artifact_in_repository(self, path, destination, source):
+ def register_package_in_repository(self, path, origin, destination, kind):
"""
Registration of one artifact in a repository
- param path:
- param destination: path for index creation
- param source:
+ :param path: absolute path of the VNF/NS package
+ :param origin: folder where the package is located
+ :param destination: path for index creation
+ :param kind: artifact (tar.gz) or directory
"""
self._logger.debug("")
pt = PackageTool()
compressed = False
try:
fields = {}
- _, valid, fields, package_type = self.validate_artifact(path, source)
+ _, valid, fields, package_type = self.validate_artifact(path, origin, kind)
if not valid:
raise Exception(
"{} {} Not well configured.".format(package_type.upper(), str(path))
)
else:
- if source == "directory":
+ if kind == "directory":
path = pt.build(path)
self._logger.debug(f"Directory path {path}")
compressed = True
except Exception as e:
self._logger.exception(
- "Error registering artifact in Repository: {}".format(e)
+ "Error registering package in Repository: {}".format(e)
)
raise ClientException(e)
finally:
- if source == "directory" and compressed:
+ if kind == "directory" and compressed:
remove(path)
def indexation(self, destination, path, package_type, fields):