mirror of https://github.com/nucypher/nucypher.git
Don't migrate configurations from v4->v6, but instead do v4->v5->v6 to ensure proper changes are enacted.
Migration from v4->v5 missed deprecation of "db_filepath" configuration parameter. Add tests for configuration migration.pull/3230/head
parent
5d5261a5a7
commit
0081ee1ce6
|
@ -2,7 +2,7 @@ from collections import OrderedDict
|
|||
|
||||
from .configuration_v1_to_v2 import configuration_v1_to_v2
|
||||
from .configuration_v3_to_v4 import configuration_v3_to_v4
|
||||
from .configuration_v4_to_v6 import configuration_v4_to_v6
|
||||
from .configuration_v4_to_v5 import configuration_v4_to_v5
|
||||
from .configuration_v5_to_v6 import configuration_v5_to_v6
|
||||
from .configuration_v6_to_v7 import configuration_v6_to_v7
|
||||
|
||||
|
@ -11,7 +11,7 @@ MIGRATIONS = OrderedDict(
|
|||
(1, 2): configuration_v1_to_v2,
|
||||
(2, 3): None, # (no-op)
|
||||
(3, 4): configuration_v3_to_v4,
|
||||
(4, 6): configuration_v4_to_v6,
|
||||
(4, 5): configuration_v4_to_v5,
|
||||
(5, 6): configuration_v5_to_v6,
|
||||
(6, 7): configuration_v6_to_v7,
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ from nucypher.config.migrations.common import perform_migration
|
|||
|
||||
|
||||
def __migration(config: Dict) -> Dict:
|
||||
del config["federated_only"] # deprecated
|
||||
# deprecated
|
||||
del config["federated_only"]
|
||||
del config["checksum_address"]
|
||||
del config["db_filepath"]
|
||||
return config
|
||||
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
from typing import Dict
|
||||
|
||||
from nucypher.blockchain.eth.networks import NetworksInventory
|
||||
from nucypher.config.migrations.common import perform_migration
|
||||
|
||||
|
||||
def __migration(config: Dict) -> Dict:
|
||||
eth_provider = config["eth_provider_uri"]
|
||||
eth_chain_id = NetworksInventory.get_ethereum_chain_id(config["domain"])
|
||||
polygon_provider = config["payment_provider"]
|
||||
polygon_chain_id = NetworksInventory.get_polygon_chain_id(config["payment_network"])
|
||||
if "condition_provider_uris" in config:
|
||||
return config
|
||||
config["condition_provider_uris"] = {
|
||||
eth_chain_id: [eth_provider],
|
||||
polygon_chain_id: [polygon_provider],
|
||||
}
|
||||
return config
|
||||
|
||||
|
||||
def configuration_v4_to_v6(filepath) -> None:
|
||||
perform_migration(
|
||||
old_version=4, new_version=6, migration=__migration, filepath=filepath
|
||||
)
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"federated_only": null,
|
||||
"checksum_address": null,
|
||||
"keystore_path": null,
|
||||
"domain": ":temporary-domain:",
|
||||
"learn_on_same_thread": false,
|
||||
"abort_on_learning_error": false,
|
||||
"start_learning_now": false,
|
||||
"save_metadata": false,
|
||||
"node_storage": {
|
||||
"storage_type": ":memory:"
|
||||
},
|
||||
"lonely": false,
|
||||
"eth_provider_uri": "tester://pyevm",
|
||||
"poa": null,
|
||||
"light": false,
|
||||
"signer_uri": "tester://pyevm",
|
||||
"gas_strategy": "fast",
|
||||
"max_gas_price": null,
|
||||
"operator_address": "0xd45B37d42C0A9e4c6072fcD5A94ee11697275012",
|
||||
"rest_host": "127.0.0.1",
|
||||
"rest_port": 51941,
|
||||
"db_filepath": "/root/.local/share/nucypher/ursula.db",
|
||||
"availability_check": false,
|
||||
"payment_method": "SubscriptionManager",
|
||||
"payment_provider": "tester://pyevm",
|
||||
"payment_network": ":temporary-domain:",
|
||||
"version": 4
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import tests
|
||||
from nucypher.config.characters import UrsulaConfiguration
|
||||
from nucypher.config.migrations import MIGRATIONS
|
||||
from nucypher.config.migrations.common import WrongConfigurationVersion
|
||||
|
||||
|
||||
def _copy_config_file(src_test_file_name, dst_filepath):
|
||||
src_filepath = (
|
||||
Path(tests.__file__).parent
|
||||
/ "integration"
|
||||
/ "config"
|
||||
/ "data"
|
||||
/ src_test_file_name
|
||||
)
|
||||
shutil.copy(src=src_filepath, dst=dst_filepath)
|
||||
|
||||
|
||||
def _do_migration(config_file: Path):
|
||||
for jump, migration in MIGRATIONS.items():
|
||||
if not migration:
|
||||
continue # no migration script
|
||||
try:
|
||||
migration(config_file)
|
||||
except WrongConfigurationVersion:
|
||||
continue
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def ursula_v4_config_filepath(tempfile_path):
|
||||
# v4 is the latest public release (from v6.1.0)
|
||||
_copy_config_file("ursula_v4.json", tempfile_path)
|
||||
|
||||
return tempfile_path
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("test_registry_source_manager")
|
||||
def test_migrate_v4_to_latest(ursula_v4_config_filepath):
|
||||
_do_migration(config_file=ursula_v4_config_filepath)
|
||||
|
||||
# file changed in place
|
||||
migrated_ursula_config_filepath = ursula_v4_config_filepath
|
||||
ursula_config = UrsulaConfiguration.from_configuration_file(
|
||||
migrated_ursula_config_filepath, dev_mode=True
|
||||
)
|
||||
|
||||
# successfully produce an ursula based on latest config
|
||||
_ = ursula_config.produce()
|
Loading…
Reference in New Issue