Commit edb7fc11 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed the migration package tests.

parent bdbbb001
Pipeline #48004 passed with stages
in 16 minutes and 51 seconds
......@@ -299,6 +299,8 @@ class Package(Document):
Assuming that the tarfile contains multiple extracted uploads. The first directory
hierarchy level is interpreted as upload_id.
"""
logger = utils.get_logger(__name__)
tf = tarfile.TarFile.open(source_tar_path, copybufsize=1024 * 1024) # type: ignore
if offset is not None:
tf.offset = offset # type: ignore
......@@ -308,10 +310,12 @@ class Package(Document):
class PackageFile():
def __init__(self, upload_id: str):
upload_directory = files.DirectoryObject(
config.fs.migration_packages, upload_id, create=True, prefix=True)
self.package = Package(upload_id=upload_id, package_id=utils.create_uuid())
self.package.package_path = files.PathObject(
config.fs.migration_packages, self.package.package_id + '.zip',
prefix=True, create_prefix=True).os_path
self.package.package_path = upload_directory.join_file(
self.package.package_id + '.zip').os_path
self.package.upload_path = os.path.join(source_tar_path, upload_id)
self.package_file = zipfile.ZipFile(
......@@ -388,7 +392,7 @@ class Package(Document):
current_package.close(True)
current_upload = upload
print('new upload %s' % current_upload)
logger.info('new upload', source_upload_id=current_upload)
current_directory = None
current_package = PackageFile(current_upload)
......
......@@ -96,7 +96,10 @@ def source_package(mongo, migration):
def assert_packages(restriction: int = 0, upload_id: str = None):
packages = Package.objects(upload_id=upload_id)
if upload_id is None:
packages = Package.objects()
else:
packages = Package.objects(upload_id=upload_id)
for package in packages:
assert os.path.exists(package.package_path)
assert package.size > 0
......@@ -118,11 +121,12 @@ def test_package(
monkeypatch.setattr('nomad.migration.max_package_size', 3)
upload = os.path.join('tests/data/migration/packaging%s' % variant, upload)
migration.package_index(upload, restriction=restriction)
assert assert_packages() == n_packages
migration.package_index(upload)
assert assert_packages(restriction=restriction) == n_packages
def test_tar_package(mongo, raw_files, monkeypatch):
Package.objects().delete() # the mongo fixture drops the db, but we still get old results, probably mongoengine caching
monkeypatch.setattr('nomad.migration.max_package_size', 3)
example_tar_file = 'tests/data/migration/example.tar.gz'
assert os.path.isfile(example_tar_file)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment