mirror of https://github.com/nucypher/nucypher.git
Some janitorial stuff
parent
0fb2cad64a
commit
f42de3ae11
|
@ -32,6 +32,7 @@ ursula_maker = partial(Ursula, rest_host='127.0.0.1',
|
|||
federated_only=True,
|
||||
domain=TEMPORARY_DOMAIN)
|
||||
|
||||
|
||||
def spin_up_federated_ursulas(quantity: int = FLEET_POPULATION):
|
||||
# Ports
|
||||
starting_port = DEMO_NODE_STARTING_PORT
|
||||
|
@ -39,7 +40,7 @@ def spin_up_federated_ursulas(quantity: int = FLEET_POPULATION):
|
|||
|
||||
ursulas = []
|
||||
|
||||
sage = ursula_maker(rest_port=ports[0], db_filepath=f"{Path(APP_DIR.user_cache_dir) / 'sage.db'}")
|
||||
sage = ursula_maker(rest_port=ports[0], db_filepath=str(Path(APP_DIR.user_cache_dir) / 'sage.db'))
|
||||
|
||||
ursulas.append(sage)
|
||||
for index, port in enumerate(ports[1:]):
|
||||
|
|
|
@ -342,6 +342,7 @@ class Character(Learner):
|
|||
# If we're federated only, we assume that all other nodes in our domain are as well.
|
||||
known_node_class.set_federated_mode(federated_only)
|
||||
|
||||
# TODO: Unused
|
||||
def store_metadata(self, filepath: str) -> str:
|
||||
"""
|
||||
Save this node to the disk.
|
||||
|
|
|
@ -201,7 +201,7 @@ class ForgetfulNodeStorage(NodeStorage):
|
|||
# Certificates
|
||||
self.__certificates = dict()
|
||||
self.__temporary_certificates = list()
|
||||
self._temp_certificates_dir = tempfile.mkdtemp(prefix='nucypher-temp-certs-', dir=parent_dir)
|
||||
self._temp_certificates_dir = tempfile.mkdtemp(prefix=self.__base_prefix, dir=parent_dir)
|
||||
|
||||
@property
|
||||
def source(self) -> str:
|
||||
|
@ -209,7 +209,7 @@ class ForgetfulNodeStorage(NodeStorage):
|
|||
return self._name
|
||||
|
||||
def all(self, federated_only: bool, certificates_only: bool = False) -> set:
|
||||
return set(self.__metadata.values() if not certificates_only else self.__certificates.values())
|
||||
return set(self.__certificates.values() if certificates_only else self.__metadata.values())
|
||||
|
||||
@validate_checksum_address
|
||||
def get(self,
|
||||
|
@ -449,11 +449,6 @@ class LocalFileBasedNodeStorage(NodeStorage):
|
|||
self.__write_metadata(filepath=filepath, node=node)
|
||||
return filepath
|
||||
|
||||
def save_node(self, node, force) -> Tuple[str, str]:
|
||||
certificate_filepath = self.store_node_certificate(certificate=node.certificate, force=force)
|
||||
metadata_filepath = self.store_node_metadata(node=node)
|
||||
return metadata_filepath, certificate_filepath
|
||||
|
||||
@validate_checksum_address
|
||||
def remove(self, checksum_address: str, metadata: bool = True, certificate: bool = True) -> None:
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ import time
|
|||
from collections import defaultdict, deque
|
||||
from contextlib import suppress
|
||||
from queue import Queue
|
||||
from typing import Iterable
|
||||
from typing import Iterable, List
|
||||
from typing import Set, Tuple, Union
|
||||
|
||||
import maya
|
||||
|
@ -344,7 +344,7 @@ class Learner:
|
|||
|
||||
return discovered
|
||||
|
||||
def read_nodes_from_storage(self) -> None:
|
||||
def read_nodes_from_storage(self) -> List:
|
||||
stored_nodes = self.node_storage.all(federated_only=self.federated_only) # TODO: #466
|
||||
|
||||
restored_from_disk = []
|
||||
|
|
|
@ -401,9 +401,9 @@ def federated_ursulas(ursula_federated_test_config):
|
|||
def lonely_ursula_maker(ursula_federated_test_config):
|
||||
class _PartialUrsulaMaker:
|
||||
_partial = partial(make_federated_ursulas,
|
||||
ursula_config=ursula_federated_test_config,
|
||||
know_each_other=False,
|
||||
)
|
||||
ursula_config=ursula_federated_test_config,
|
||||
know_each_other=False,
|
||||
)
|
||||
_made = []
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
|
|
|
@ -18,10 +18,9 @@ along with nucypher. If not, see <https://www.gnu.org/licenses/>.
|
|||
import pytest
|
||||
|
||||
from nucypher.characters.lawful import Ursula
|
||||
from nucypher.config.storages import (ForgetfulNodeStorage, NodeStorage,
|
||||
TemporaryFileBasedNodeStorage)
|
||||
from tests.constants import (
|
||||
MOCK_URSULA_DB_FILEPATH)
|
||||
from nucypher.config.storages import ForgetfulNodeStorage, NodeStorage, TemporaryFileBasedNodeStorage
|
||||
|
||||
from tests.constants import MOCK_URSULA_DB_FILEPATH
|
||||
from tests.utils.ursula import MOCK_URSULA_STARTING_PORT
|
||||
|
||||
|
||||
|
|
|
@ -21,35 +21,36 @@ from tests.utils.ursula import make_federated_ursulas
|
|||
|
||||
|
||||
def test_learner_learns_about_domains_separately(lonely_ursula_maker, caplog):
|
||||
_lonely_ursula_maker = partial(lonely_ursula_maker, know_each_other=True, quantity=3)
|
||||
_lonely_ursula_maker = partial(lonely_ursula_maker, know_each_other=True, quantity=3)
|
||||
|
||||
global_learners = _lonely_ursula_maker(domain="nucypher1.test_suite")
|
||||
first_domain_learners = _lonely_ursula_maker(domain="nucypher1.test_suite")
|
||||
second_domain_learners = _lonely_ursula_maker(domain="nucypher2.test_suite")
|
||||
global_learners = _lonely_ursula_maker(domain="nucypher1.test_suite")
|
||||
first_domain_learners = _lonely_ursula_maker(domain="nucypher1.test_suite")
|
||||
second_domain_learners = _lonely_ursula_maker(domain="nucypher2.test_suite")
|
||||
|
||||
big_learner = global_learners.pop()
|
||||
big_learner = global_learners.pop()
|
||||
|
||||
assert len(big_learner.known_nodes) == 2
|
||||
assert len(big_learner.known_nodes) == 2
|
||||
|
||||
# Learn about the fist domain.
|
||||
big_learner._current_teacher_node = first_domain_learners.pop()
|
||||
big_learner.learn_from_teacher_node()
|
||||
# Learn about the fist domain.
|
||||
big_learner._current_teacher_node = first_domain_learners.pop()
|
||||
big_learner.learn_from_teacher_node()
|
||||
|
||||
# Learn about the second domain.
|
||||
big_learner._current_teacher_node = second_domain_learners.pop()
|
||||
big_learner.learn_from_teacher_node()
|
||||
# Learn about the second domain.
|
||||
big_learner._current_teacher_node = second_domain_learners.pop()
|
||||
big_learner.learn_from_teacher_node()
|
||||
|
||||
# All domain 1 nodes
|
||||
assert len(big_learner.known_nodes) == 5
|
||||
# All domain 1 nodes
|
||||
assert len(big_learner.known_nodes) == 5
|
||||
|
||||
new_first_domain_learner = _lonely_ursula_maker(domain="nucypher1.test_suite").pop()
|
||||
_new_second_domain_learner = _lonely_ursula_maker(domain="nucypher2.test_suite")
|
||||
new_first_domain_learner = _lonely_ursula_maker(domain="nucypher1.test_suite").pop()
|
||||
_new_second_domain_learner = _lonely_ursula_maker(domain="nucypher2.test_suite")
|
||||
|
||||
new_first_domain_learner._current_teacher_node = big_learner
|
||||
new_first_domain_learner.learn_from_teacher_node()
|
||||
new_first_domain_learner._current_teacher_node = big_learner
|
||||
new_first_domain_learner.learn_from_teacher_node()
|
||||
|
||||
# This node, in the first domain, didn't learn about the second domain.
|
||||
assert not set(second_domain_learners).intersection(new_first_domain_learner.known_nodes)
|
||||
# This node, in the first domain, didn't learn about the second domain.
|
||||
assert not set(second_domain_learners).intersection(new_first_domain_learner.known_nodes)
|
||||
|
||||
# However, it learned about *all* of the nodes in its own domain.
|
||||
assert set(first_domain_learners).intersection(n.mature() for n in new_first_domain_learner.known_nodes) == first_domain_learners
|
||||
# However, it learned about *all* of the nodes in its own domain.
|
||||
assert set(first_domain_learners).intersection(
|
||||
n.mature() for n in new_first_domain_learner.known_nodes) == first_domain_learners
|
||||
|
|
Loading…
Reference in New Issue