Skip to content

Commit

Permalink
Archive: add missing migration of transport entry points (#5604)
Browse files Browse the repository at this point in the history
In the migration from version `0.11` to `0.12` the existing entry points
from `aiida-core` were updated to include the `core.` prefix, however,
the entry points of transports were forgotten. Since the incorrect
migration was already released with `v2.0` of `aiida-core`, a separate
migration has to be added to perform the transport entry point migrations.
  • Loading branch information
janssenhenning authored Aug 4, 2022
1 parent f157d27 commit 3e4c883
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion aiida/storage/sqlite_zip/migrations/legacy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .v09_to_v10 import migrate_v9_to_v10
from .v10_to_v11 import migrate_v10_to_v11
from .v11_to_v12 import migrate_v11_to_v12
from .v12_to_v13 import migrate_v12_to_v13

# version from -> version to, function which modifies metadata, data in-place
LEGACY_MIGRATE_FUNCTIONS: Dict[str, Tuple[str, Callable[[dict, dict], None]]] = {
Expand All @@ -33,5 +34,6 @@
'0.9': ('0.10', migrate_v9_to_v10),
'0.10': ('0.11', migrate_v10_to_v11),
'0.11': ('0.12', migrate_v11_to_v12),
'0.12': ('0.13', migrate_v12_to_v13),
}
FINAL_LEGACY_VERSION = '0.12'
FINAL_LEGACY_VERSION = '0.13'
41 changes: 41 additions & 0 deletions aiida/storage/sqlite_zip/migrations/legacy/v12_to_v13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (c), The AiiDA team. All rights reserved. #
# This file is part of the AiiDA code. #
# #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
"""Migration from v0.12 to v0.13, used by ``verdi archive migrate`` command.
This migration is necessary after the v0.11 to v0.12 migration did not add the core prefix
to transport entry points.
"""
from ..utils import update_metadata, verify_metadata_version # pylint: disable=no-name-in-module

MAPPING_TRANSPORTS = {
'local': 'core.local',
'ssh': 'core.ssh',
}


def migrate_v12_to_v13(metadata: dict, data: dict) -> None:
"""Migration of export files from v0.12 to v0.13."""
# pylint: disable=too-many-branches
old_version = '0.12'
new_version = '0.13'

verify_metadata_version(metadata, old_version)
update_metadata(metadata, new_version)

# Migrate transport entry point names
for values in data.get('export_data', {}).get('Computer', {}).values():

if 'transport_type' in values:
try:
new_transport_type = MAPPING_TRANSPORTS[values['transport_type']]
except KeyError:
pass
else:
values['transport_type'] = new_transport_type
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/tools/archive/migration/test_v012_to_v013.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
###########################################################################
# Copyright (c), The AiiDA team. All rights reserved. #
# This file is part of the AiiDA code. #
# #
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core #
# For further information on the license, see the LICENSE.txt file #
# For further information please visit http://www.aiida.net #
###########################################################################
"""Test archive file migration from export version 0.12 to 0.13"""
from aiida.storage.sqlite_zip.migrations.legacy.v12_to_v13 import migrate_v12_to_v13


def test_migrate_v12_to_v13(core_archive, migrate_from_func):
"""Test the data migration of transport entry point strings
e.g. from local to core.local.
"""

# Migrate v0.12 to v0.13
_, data = migrate_from_func('export_0.12_simple.aiida', '0.12', '0.13', migrate_v12_to_v13, core_archive)

for values in data.get('export_data', {}).get('Computer', {}).values():
if 'transport_type' in values:
assert values['transport_type'] in [
'core.local',
'core.ssh',
], (f"encountered illegal transport entry point string `{values['transport_type']}`")

0 comments on commit 3e4c883

Please sign in to comment.