def test_delete_package(self):
        with tempfile.TemporaryDirectory() as root_dir:
            store = self.create_store(root_dir)
            package = self.create_and_store_package(store)

            store.get_package(package.descriptor_id)
            store.delete_package(package)

            with self.assertRaises(rift.package.store.PackageStoreError):
                store.get_package(package.descriptor_id)
    def test_delete_package(self):
        with tempfile.TemporaryDirectory() as root_dir:
            store = self.create_store(root_dir)
            package = self.create_and_store_package(store)

            store.get_package(package.descriptor_id)
            store.delete_package(package.descriptor_id)

            with self.assertRaises(rift.package.store.PackageStoreError):
                store.get_package(package.descriptor_id)
 def test_store_package(self):
     with tempfile.TemporaryDirectory() as root_dir:
         store = self.create_store(root_dir)
         package = self.create_and_store_package(store)
         new_package = store.get_package(package.descriptor_id)
         self.assertEquals(new_package.files, package.files)
         self.assertEquals(type(new_package), type(package))
 def test_store_package(self):
     with tempfile.TemporaryDirectory() as root_dir:
         store = self.create_store(root_dir)
         package = self.create_and_store_package(store)
         new_package = store.get_package(package.descriptor_id)
         self.assertEquals(new_package.files, package.files)
         self.assertEquals(type(new_package), type(package))
Example #5
0
    def update_package(self, package):
        store = self.get_package_store(package)

        try:
            store.update_package(package)
        except rift.package.store.PackageNotFoundError as e:
            raise MessageException(UpdatePackageNotFoundError(package.descriptor_id)) from e

        stored_package = store.get_package(package.descriptor_id)

        return stored_package
Example #6
0
    def store_package(self, package):
        store = self.get_package_store(package)

        try:
            store.store_package(package)
        except rift.package.store.PackageExistsError as e:
            store.update_package(package)

        stored_package = store.get_package(package.descriptor_id)

        return stored_package
Example #7
0
    def package_file_add(self, new_file, package_type, package_id, package_path, package_file_type, project_name):
        # Get the schema from thr package path
        # the first part will always be the vnfd/nsd name
        mode = 0o664

        # for files other than README, create the package path from the asset type, e.g. icons/icon1.png
        # for README files, strip off any leading '/' 
        file_name = package_path
        package_path = package_file_type + "/" + package_path \
            if package_file_type != "readme" else package_path.strip('/')
        
        components = package_path.split("/")
        if len(components) > 2:
            schema = components[1]
            mode = self.SCHEMA_TO_PERMS.get(schema, mode)

        # Fetch the package object
        package_type = package_type.lower()
        store = self._get_store(package_type, project_name)
        package = store.get_package(package_id)

        # Construct abs path of the destination obj
        path = store._get_package_dir(package_id)
        dest_file = os.path.join(path, package.prefix, package_path)

        # Insert (by copy) the file in the package location. For icons, 
        # insert also in UI location for UI to pickup
        try:
            self.log.debug("Inserting file {} in the destination {} - {} ".format(dest_file, package_path, dest_file))
            package.insert_file(new_file, dest_file, package_path, mode=mode)

            if package_file_type == 'icons': 
                icon_extract = icon.PackageIconExtractor(self.log) 
                icon_extract.extract_icons(package)

            if package_file_type == 'images':                                
                image_hdl = package.open(package_path)
                image_checksum = checksums.checksum(image_hdl)
                
                try:
                    self.uploader.upload_image(file_name, image_checksum, image_hdl, {})
                    self.uploader.upload_image_to_cloud_accounts(file_name, image_checksum, project_name)
                finally:
                    _ = image_hdl.close()
        except rift.package.package.PackageAppendError as e:
            self.log.exception(e)
            return False

        self.log.debug("File insertion complete at {}".format(dest_file))
        return True
Example #8
0
    def update_package(self, package):
        store = self.get_package_store(package)

        try:
            store.update_package(package)
        except rift.package.store.PackageNotFoundError as e:
            # If the package doesn't exist, then it is possible the descriptor was onboarded
            # out of band.  In that case, just store the package as is
            self.log.warning("Package not found, storing new package instead.")
            store.store_package(package)

        stored_package = store.get_package(package.descriptor_id)

        return stored_package
Example #9
0
    def store_package(self, package):
        store = self.get_package_store(package)

        try:
            store.store_package(package)
        except rift.package.store.PackageExistsError as e:
            #TODO: The package store needs to stay in sync with configured
            #descriptors (descriptor delete -> stored package deletion).  Until
            #that happens, we should just update the stored package.
            #raise MessageException(OnboardDescriptorExistsError(package.descriptor_id)) from e
            store.update_package(package)

        stored_package = store.get_package(package.descriptor_id)

        return stored_package
Example #10
0
    def package_file_delete(self, package_type, package_id, package_path, package_file_type, project_name):
        package_type = package_type.lower()
        store = self._get_store(package_type, project_name)
        package = store.get_package(package_id)

        # for files other than README, create the relative package path from the asset type
        package_path_rel = package_file_type + "/" + package_path \
            if package_file_type != "readme" else package_path

        # package_path has to be relative, so strip off the starting slash if
        # provided incorrectly.
        if package_path_rel[0] == "/":
            package_path_rel = package_path_rel[1:]

        # Construct abs path of the destination obj
        path = store._get_package_dir(package_id)
        dest_file = os.path.join(path, package.prefix, package_path_rel)

        try:
            package.delete_file(dest_file, package_path_rel)

            if package_file_type == 'icons': 
                ui_icon_path = os.path.join(
                        icon.PackageIconExtractor.DEFAULT_INSTALL_DIR, 
                        package_type, 
                        package_id)
                if os.path.exists(ui_icon_path): 
                    icon_file = os.path.join(ui_icon_path, package_path)
                    self.log.debug("Deleting UI icon file path {}".format(icon_file))
                    os.remove(icon_file)

        except rift.package.package.PackageAppendError as e:
            self.log.exception(e)
            return False

        return True