All characters destroy thier own config files, considering force

pull/861/head
Kieran Prasch 2019-03-18 14:33:43 -07:00
parent b691339f50
commit e110632bb1
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
8 changed files with 22 additions and 15 deletions

View File

@ -77,7 +77,7 @@ class IPCStdoutEmitter(StdoutEmitter):
transport_serializer = json.dumps
def _emit(self, response: dict = None, message: str = None) -> None:
def _emit(self, response: dict = None, message: str = None, *args, **kwargs) -> None:
"""
Write data to stdout. For machine consumption only.
"""

View File

@ -184,7 +184,7 @@ def alice(click_config,
if dev:
message = "'nucypher ursula destroy' cannot be used in --dev mode"
raise click.BadOptionUsage(option_name='--dev', message=message)
return actions.destroy_configuration(character_config=alice_config)
return actions.destroy_configuration(character_config=alice_config, force=force)
else:
raise click.BadArgumentUsage(f"No such argument {action}")

View File

@ -149,7 +149,7 @@ ETH ........ {str(eth_balance)}
elif action == "destroy":
"""Delete all configuration files from the disk"""
return actions.destroy_configuration(character_config=felix_config)
return actions.destroy_configuration(character_config=felix_config, force=force)
elif action == 'run': # Start web services
FELIX.start(host=host, port=port, web_services=not dry_run, distribution=True, crash_on_error=click_config.debug)

View File

@ -312,7 +312,7 @@ def ursula(click_config,
if dev:
message = "'nucypher ursula destroy' cannot be used in --dev mode"
raise click.BadOptionUsage(option_name='--dev', message=message)
return actions.destroy_configuration(character_config=ursula_config)
return actions.destroy_configuration(character_config=ursula_config, force=force)
elif action == 'stake':

View File

@ -90,14 +90,14 @@ def nucypher_cli(click_config,
# Only used for testing outputs;
# Redirects outputs to in-memory python containers.
if mock_networking:
click_config.emitter(message="WARNING: Mock networking is enabled")
click_config.emit(message="WARNING: Mock networking is enabled")
click_config.middleware = MockRestMiddleware()
else:
click_config.middleware = RestMiddleware()
# Global Warnings
if click_config.verbose:
click_config.emitter("Verbose mode is enabled", color='blue')
click_config.emit("Verbose mode is enabled", color='blue')
@click.command()

View File

@ -93,9 +93,9 @@ class UrsulaConfiguration(NodeConfiguration):
curve=self.tls_curve,
**generation_kwargs)
def destroy(self):
super().destroy()
def destroy(self) -> None:
os.remove(self.db_filepath)
super().destroy()
class AliceConfiguration(NodeConfiguration):

View File

@ -399,7 +399,7 @@ class NodeConfiguration(ABC):
overrides = {k: v for k, v in overrides.items() if v is not None}
# Instantiate from merged params
node_configuration = cls(**{**payload, **overrides})
node_configuration = cls(config_file_location=filepath, **{**payload, **overrides})
return node_configuration

View File

@ -76,6 +76,7 @@ def test_coexisting_configurations(click_runner,
result = click_runner.invoke(nucypher_cli, felix_init_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert os.path.isfile(felix_file_location)
assert len(os.listdir(public_keys_dir)) == 3
# Use a custom local filepath to init an persistent Alice
@ -88,6 +89,7 @@ def test_coexisting_configurations(click_runner,
result = click_runner.invoke(nucypher_cli, alice_init_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert os.path.isfile(alice_file_location)
assert len(os.listdir(public_keys_dir)) == 5
# Use the same local filepath to init an persistent Ursula
@ -124,33 +126,38 @@ def test_coexisting_configurations(click_runner,
# Destroy
#
another_ursula_destruction_args = ('ursula',
'destroy',
'--force',
another_ursula_destruction_args = ('ursula', 'destroy', '--force',
'--config-file', another_ursula_configuration_file_location)
result = click_runner.invoke(nucypher_cli, another_ursula_destruction_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert len(os.listdir(public_keys_dir)) == 8
assert not os.path.isfile(another_ursula_configuration_file_location)
ursula_destruction_args = ('ursula', 'destroy', '--config-file', ursula_file_location)
result = click_runner.invoke(nucypher_cli, ursula_destruction_args, catch_exceptions=False, env=envvars)
result = click_runner.invoke(nucypher_cli, ursula_destruction_args, input='Y', catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert 'y/N' in result.output
assert len(os.listdir(public_keys_dir)) == 5
assert not os.path.isfile(ursula_file_location)
felix_destruction_args = ('alice', 'destroy', '--force', '--config-file', alice_file_location)
result = click_runner.invoke(nucypher_cli, felix_destruction_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert len(os.listdir(public_keys_dir)) == 3
assert not os.path.isfile(alice_file_location)
felix_destruction_args = ('felix', 'destroy', '--force', '--config-file', felix_file_location)
result = click_runner.invoke(nucypher_cli, felix_destruction_args, catch_exceptions=False, env=envvars)
assert result.exit_code == 0
assert len(os.listdir(public_keys_dir)) == 0
assert not os.path.isfile(felix_file_location)
def test_nucypher_removal(click_runner, custom_filepath):
# Remove nucypher completely
destruction_args = ('remove', '--force', '--config-root', custom_filepath)
result = click_runner.invoke(nucypher_cli, destruction_args, catch_exceptions=False, env=envvars)
result = click_runner.invoke(nucypher_cli, destruction_args, catch_exceptions=False)
assert result.exit_code == 0
assert not os.path.isdir(custom_filepath)
# Everything is gone