def test_export_package(self): rw_vnfd_msg = RwVnfdYang.YangData_RwProject_Project_VnfdCatalog_Vnfd( id="new_id", name="new_name", description="new_description", meta="THIS FIELD IS NOT IN REGULAR VNFD") vnfd_msg = VnfdYang.YangData_RwProject_Project_VnfdCatalog_Vnfd() vnfd_msg.from_dict(rw_vnfd_msg.as_dict(), ignore_missing_keys=True) self.assertNotEqual(rw_vnfd_msg, vnfd_msg) json_desc_str = self._rw_vnfd_serializer.to_json_string(rw_vnfd_msg) with tempfile.TemporaryDirectory() as tmp_dir: vnfd_package = self.create_vnfd_package() pkg_id = str(uuid.uuid4()) exported_path = self._exporter.export_package( vnfd_package, tmp_dir, pkg_id, json_desc_str, self._vnfd_serializer) self.assertTrue(os.path.isfile(exported_path)) self.assertTrue(tarfile.is_tarfile(exported_path)) with open(exported_path, "rb") as archive_hdl: archive = rift.package.archive.TarPackageArchive( self._log, archive_hdl) package = archive.create_package() self.assertEqual(package.descriptor_msg, vnfd_msg)
def test_export_package(self): rw_vnfd_msg = RwVnfdYang.YangData_Vnfd_VnfdCatalog_Vnfd( id="new_id", name="new_name", description="new_description", meta="THIS FIELD IS NOT IN REGULAR VNFD" ) vnfd_msg = VnfdYang.YangData_Vnfd_VnfdCatalog_Vnfd() vnfd_msg.from_dict(rw_vnfd_msg.as_dict(), ignore_missing_keys=True) self.assertNotEqual(rw_vnfd_msg, vnfd_msg) json_desc_str = self._rw_vnfd_serializer.to_json_string(rw_vnfd_msg) with tempfile.TemporaryDirectory() as tmp_dir: vnfd_package = self.create_vnfd_package() pkg_id = str(uuid.uuid4()) exported_path = self._exporter.export_package( vnfd_package, tmp_dir, pkg_id, json_desc_str, self._vnfd_serializer ) self.assertTrue(os.path.isfile(exported_path)) self.assertTrue(tarfile.is_tarfile(exported_path)) with open(exported_path, "rb") as archive_hdl: archive = rift.package.archive.TarPackageArchive(self._log, archive_hdl) package = archive.create_package() self.assertEqual(package.descriptor_msg, vnfd_msg)
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))
def test_create_archive(self): rw_vnfd_msg = RwVnfdYang.YangData_RwProject_Project_VnfdCatalog_Vnfd( id="new_id", name="new_name", description="new_description") json_desc_str = self._rw_vnfd_serializer.to_json_string(rw_vnfd_msg) vnfd_package = self.create_vnfd_package() with io.BytesIO() as archive_hdl: archive = self._exporter.create_archive(archive_hdl, vnfd_package, json_desc_str, self._rw_vnfd_serializer) archive_hdl.seek(0) # Create a new read-only archive from the archive handle and a package from that archive archive = rift.package.archive.TarPackageArchive( self._log, archive_hdl) package = archive.create_package() # Ensure that the descriptor in the package has been overwritten self.assertEqual(package.descriptor_msg, rw_vnfd_msg)
def test_create_archive(self): rw_vnfd_msg = RwVnfdYang.YangData_Vnfd_VnfdCatalog_Vnfd( id="new_id", name="new_name", description="new_description" ) json_desc_str = self._rw_vnfd_serializer.to_json_string(rw_vnfd_msg) vnfd_package = self.create_vnfd_package() with io.BytesIO() as archive_hdl: archive = self._exporter.create_archive( archive_hdl, vnfd_package, json_desc_str, self._rw_vnfd_serializer ) archive_hdl.seek(0) # Create a new read-only archive from the archive handle and a package from that archive archive = rift.package.archive.TarPackageArchive(self._log, archive_hdl) package = archive.create_package() # Ensure that the descriptor in the package has been overwritten self.assertEqual(package.descriptor_msg, rw_vnfd_msg)
def create_vnfd_package(self): self.add_vnfd_yaml() archive = self.create_tar_package_archive() package = archive.create_package() return package