mirror of https://github.com/nucypher/nucypher.git
Include dbatabase filepath as a configuration option; Stop spraying databases during tests.
parent
a63a99c3d9
commit
d311c397a1
|
@ -397,6 +397,7 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
certificate=None,
|
||||
certificate_filepath: str = None,
|
||||
db_name=None,
|
||||
db_filepath: str = None,
|
||||
is_me=True,
|
||||
interface_signature=None,
|
||||
|
||||
|
@ -455,6 +456,7 @@ class Ursula(Character, VerifiableNode, Miner):
|
|||
|
||||
rest_routes = ProxyRESTRoutes(
|
||||
db_name=db_name,
|
||||
db_path=db_filepath,
|
||||
network_middleware=self.network_middleware,
|
||||
federated_only=self.federated_only,
|
||||
treasure_map_tracker=self.treasure_maps,
|
||||
|
|
|
@ -2,9 +2,11 @@ import os
|
|||
from glob import glob
|
||||
from os.path import abspath
|
||||
|
||||
from constant_sorrow import constants
|
||||
from cryptography.hazmat.primitives.asymmetric import ec
|
||||
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve
|
||||
|
||||
from nucypher.blockchain.eth.agents import MinerAgent
|
||||
from nucypher.config.constants import DEFAULT_CONFIG_FILE_LOCATION
|
||||
from nucypher.config.node import NodeConfiguration
|
||||
|
||||
|
@ -27,22 +29,23 @@ class UrsulaConfiguration(NodeConfiguration):
|
|||
|
||||
# Ursula
|
||||
db_name: str = None,
|
||||
db_filepath: str = None,
|
||||
interface_signature=None,
|
||||
crypto_power=None,
|
||||
|
||||
# Blockchain
|
||||
miner_agent=None,
|
||||
miner_agent: MinerAgent = None,
|
||||
checksum_address: str = None,
|
||||
registry_filepath: str = None,
|
||||
|
||||
*args, **kwargs
|
||||
) -> None:
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
# REST
|
||||
self.rest_host = rest_host
|
||||
self.rest_port = rest_port
|
||||
self.db_name = db_name or "ursula.{port}.db".format(port=self.rest_port)
|
||||
self.db_filepath = db_filepath or constants.UNINITIALIZED_CONFIGURATION
|
||||
|
||||
#
|
||||
# TLS
|
||||
|
@ -52,14 +55,10 @@ class UrsulaConfiguration(NodeConfiguration):
|
|||
self.certificate: bytes = certificate
|
||||
|
||||
# if certificate_filepath is None:
|
||||
# certificate_filepath = os.path.join(self.known_certificates_dir, 'ursula.pem')
|
||||
# certificate_filepath = certificate_filepath or os.path.join(self.known_certificates_dir, 'ursula.pem')
|
||||
self.certificate_filepath = certificate_filepath
|
||||
|
||||
# Ursula
|
||||
if db_name is None:
|
||||
db_name = "ursula.{port}.db".format(port=self.rest_port)
|
||||
self.db_name = db_name
|
||||
|
||||
self.interface_signature = interface_signature
|
||||
self.crypto_power = crypto_power
|
||||
|
||||
|
@ -68,7 +67,9 @@ class UrsulaConfiguration(NodeConfiguration):
|
|||
#
|
||||
self.miner_agent = miner_agent
|
||||
self.checksum_address = checksum_address
|
||||
self.registry_filepath = registry_filepath
|
||||
self.registry_filepath = registry_filepath or constants.UNINITIALIZED_CONFIGURATION
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def from_configuration_file(cls, filepath=None, **overrides) -> 'UrsulaConfiguration':
|
||||
|
@ -80,6 +81,7 @@ class UrsulaConfiguration(NodeConfiguration):
|
|||
|
||||
def generate_runtime_filepaths(self):
|
||||
super().generate_runtime_filepaths()
|
||||
self.db_filepath = os.path.join(self.config_root, self.db_name)
|
||||
self.registry_filepath = os.path.join(self.config_root, 'contract_registry.json')
|
||||
|
||||
@property
|
||||
|
@ -90,6 +92,8 @@ class UrsulaConfiguration(NodeConfiguration):
|
|||
# REST
|
||||
rest_host=self.rest_host,
|
||||
rest_port=self.rest_port,
|
||||
db_name=self.db_name,
|
||||
db_filepath=self.db_filepath,
|
||||
|
||||
# TLS
|
||||
tls_curve=self.tls_curve,
|
||||
|
@ -98,7 +102,6 @@ class UrsulaConfiguration(NodeConfiguration):
|
|||
# certificate_filepath=self.certificate_filepath, # TODO
|
||||
|
||||
# Ursula
|
||||
db_name=self.db_name,
|
||||
interface_signature=self.interface_signature,
|
||||
crypto_power=self.crypto_power,
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ from nucypher.config.constants import DEFAULT_CONFIG_ROOT, DEFAULT_CONFIG_FILE_L
|
|||
|
||||
class NodeConfiguration:
|
||||
|
||||
TEMP_CONFIGURATION_DIR_PREFIX = "nucypher-tmp-config-"
|
||||
|
||||
class ConfigurationError(RuntimeError):
|
||||
pass
|
||||
|
||||
|
@ -20,6 +22,7 @@ class NodeConfiguration:
|
|||
temp: bool = True,
|
||||
auto_initialize: bool = False,
|
||||
config_root: str = None,
|
||||
|
||||
config_file_location: str = DEFAULT_CONFIG_FILE_LOCATION,
|
||||
keyring_dir: str = None,
|
||||
|
||||
|
@ -121,7 +124,7 @@ class NodeConfiguration:
|
|||
#
|
||||
|
||||
if self.temp:
|
||||
self.__temp_dir = TemporaryDirectory("nucypher-tmp-config-")
|
||||
self.__temp_dir = TemporaryDirectory(prefix=self.TEMP_CONFIGURATION_DIR_PREFIX)
|
||||
self.config_root = self.__temp_dir.name
|
||||
self.generate_runtime_filepaths()
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ class ProxyRESTRoutes:
|
|||
|
||||
def __init__(self,
|
||||
db_name,
|
||||
db_path,
|
||||
network_middleware,
|
||||
federated_only,
|
||||
treasure_map_tracker,
|
||||
|
@ -90,16 +91,15 @@ class ProxyRESTRoutes:
|
|||
]
|
||||
|
||||
self.rest_app = App(routes=routes)
|
||||
|
||||
if not db_name:
|
||||
raise TypeError("In order to start a datastore, you need to supply a db_name.")
|
||||
self.db_name = db_name
|
||||
self.db_path = db_path
|
||||
|
||||
from nucypher.keystore import keystore
|
||||
from nucypher.keystore.db import Base
|
||||
from sqlalchemy.engine import create_engine
|
||||
|
||||
self.log.info("Starting datastore {}".format(db_name))
|
||||
engine = create_engine('sqlite:///{}'.format(db_name))
|
||||
self.log.info("Starting datastore {}".format(self.db_path))
|
||||
engine = create_engine('sqlite:///{}'.format(self.db_path))
|
||||
Base.metadata.create_all(engine)
|
||||
self.datastore = keystore.KeyStore(engine)
|
||||
self.db_engine = engine
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import shutil
|
||||
|
||||
import pytest_twisted
|
||||
import requests
|
||||
|
@ -22,8 +23,7 @@ def test_alice_enacts_policies_in_policy_group_via_rest(enacted_federated_policy
|
|||
|
||||
@pytest_twisted.inlineCallbacks
|
||||
def test_federated_nodes_connect_via_tls_and_verify(ursula_federated_test_config):
|
||||
node = make_federated_ursulas(ursula_config=ursula_federated_test_config,
|
||||
quantity=1).pop()
|
||||
node = make_federated_ursulas(ursula_config=ursula_federated_test_config, quantity=1).pop()
|
||||
node_deployer = node.get_deployer()
|
||||
|
||||
node_deployer.addServices()
|
||||
|
@ -45,6 +45,5 @@ def test_federated_nodes_connect_via_tls_and_verify(ursula_federated_test_config
|
|||
yield threads.deferToThread(check_node_with_cert, node, "test-cert")
|
||||
finally:
|
||||
os.remove("test-cert")
|
||||
|
||||
#
|
||||
# def test_node_metadata_contains_proper_cert():
|
||||
|
|
Loading…
Reference in New Issue