예제 #1
0
    def upload_images(self, package, package_checksums):
        image_file_map = rift.package.image.get_package_image_files(package)
        if not image_file_map:
            return

        name_hdl_map = {name: package.open(image_file_map[name]) for name in image_file_map}
        try:
            for image_name, image_hdl in name_hdl_map.items():
                image_file = image_file_map[image_name]
                if image_file in package_checksums:
                    image_checksum = package_checksums[image_file]
                else:
                    self.log.warning("checksum not provided for image %s.  Calculating checksum",
                                     image_file)
                    image_checksum = rift.package.checksums.checksum(
                            package.open(image_file_map[image_name])
                            )
                try:
                    set_image_property = {}
                    self.uploader.upload_image(image_name, image_checksum, image_hdl, set_image_property)
                    self.uploader.upload_image_to_cloud_accounts(image_name, image_checksum, self.project.name)

                except image.ImageUploadError as e:
                    raise MessageException(OnboardImageUploadError(str(e))) from e

        finally:
            _ = [image_hdl.close() for image_hdl in name_hdl_map.values()]
예제 #2
0
    def upload_images(self, package):
        image_file_map = rift.package.image.get_package_image_files(package)
        name_hdl_map = {name: package.open(image_file_map[name]) for name in image_file_map}
        try:
            self.uploader.upload_images(name_hdl_map)

        except image.ImageUploadError as e:
            raise MessageException(UpdateImageUploadError()) from e

        finally:
            for hdl in name_hdl_map.values():
                hdl.close()
예제 #3
0
    def test_create_vnfd_package_from_file(self):
        vnfd_file_name = "asdf_vnfd.yaml"
        hdl = io.BytesIO(vnfd_yaml)
        hdl.name = vnfd_file_name

        package = rift.package.package.DescriptorPackage.from_descriptor_file_hdl(
            self._log, hdl)
        self.assertTrue(isinstance(package, rift.package.package.VnfdPackage))

        with package.open(vnfd_file_name) as vnfd_hdl:
            vnfd_data = vnfd_hdl.read()
            self.assertEquals(yaml.load(vnfd_data), yaml.load(vnfd_yaml))
예제 #4
0
    def test_create_vnfd_package_from_file(self):
        vnfd_file_name = "asdf_vnfd.yaml"
        hdl = io.BytesIO(vnfd_yaml)
        hdl.name = vnfd_file_name

        package = rift.package.package.DescriptorPackage.from_descriptor_file_hdl(
                self._log, hdl
                )
        self.assertTrue(isinstance(package, rift.package.package.VnfdPackage))

        with package.open(vnfd_file_name) as vnfd_hdl:
            vnfd_data = vnfd_hdl.read()
            self.assertEquals(yaml.load(vnfd_data), yaml.load(vnfd_yaml))
예제 #5
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
예제 #6
0
    def test_round_trip_vnfd_package_from_archive(self):
        package = self.create_vnfd_package()
        hdl = io.BytesIO()
        self.create_vnfd_package_archive(package, hdl)

        archive = rift.package.archive.TarPackageArchive(self._log, hdl)
        def md5(file_hdl):
            return rift.package.checksums.checksum(file_hdl)

        # Create the package from the archive and validate file checksums and modes
        new_package = archive.create_package()

        self.assertEqual(package.files, new_package.files)
        self.assertEqual(type(package), type(new_package))

        for filename in package.files:
            pkg_file = package.open(filename)
            new_pkg_file = new_package.open(filename)
            self.assertEqual(md5(pkg_file), md5(new_pkg_file))
예제 #7
0
    def test_round_trip_vnfd_package_from_archive(self):
        package = self.create_vnfd_package()
        hdl = io.BytesIO()
        self.create_vnfd_package_archive(package, hdl)

        archive = rift.package.archive.TarPackageArchive(self._log, hdl)

        def md5(file_hdl):
            return rift.package.checksums.checksum(file_hdl)

        # Create the package from the archive and validate file checksums and modes
        new_package = archive.create_package()

        self.assertEqual(package.files, new_package.files)
        self.assertEqual(type(package), type(new_package))

        for filename in package.files:
            pkg_file = package.open(filename)
            new_pkg_file = new_package.open(filename)
            self.assertEqual(md5(pkg_file), md5(new_pkg_file))