Skip to content

Commit

Permalink
Merge branch 'hotfix/v0.2.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-napoleone committed Oct 1, 2018
2 parents c45d782 + 4d62628 commit d9d28f6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tmn"
version = "0.2.4"
version = "0.2.5"
description = "Quickstart your masternode"
readme = "README.md"
license = "GPL-3.0+"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _clean(tmn):


def test_version(runner, tmn):
version = '0.2.4'
version = '0.2.5'
result = runner.invoke(tmn.main, ['--version'])
assert result.output[-6:-1] == version
assert package.__version__ == version
Expand Down Expand Up @@ -184,7 +184,7 @@ def test_command_start_ignore(runner, tmn):
])
result = runner.invoke(tmn.main, ['start', '--name', 'test'])
lines = result.output.splitlines()
assert '! warning: masternode test is already configured' in lines
assert '! warning: masternode test1 is already configured' in lines
_clean(tmn)


Expand Down
2 changes: 1 addition & 1 deletion tmn/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

__version__ = '0.2.4'
__version__ = '0.2.5'

handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('[%(levelname)s] %(message)s'))
Expand Down
45 changes: 17 additions & 28 deletions tmn/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, name: str = None, net: str = None,
self.net = net
self.pkey = pkey or ''
self.id = None
self.force_recreate = False
if not docker_url:
self.client = docker.from_env()
else:
Expand All @@ -38,47 +39,47 @@ def __init__(self, name: str = None, net: str = None,
except Exception as e:
logger.error(e)
display.error_docker()
sys.exit()
sys.exit('\n')
if resources.user.read('name'):
self._load()
elif start:
self._write()
else:
display.error_start_not_initialized()
sys.exit()
sys.exit('\n')
self._compose()

def _new_id(self) -> str:
return uuid.uuid4().hex[:6]

def _load(self) -> None:
if self.name or self.net or self.pkey:
display.warning_ignoring_start_options(self.name)
display.warning_ignoring_start_options(resources.user.read('name'))
self.id = resources.user.read('id')
self.name = resources.user.read('name')
self.net = resources.user.read('net')
#######################################################################
# this is a dirty fix for retro compatiblity #
# can be removed in some future version #
# old `tmn` don't write the `id` option to disk #
# old `tmn` don't write the `id` or `net` option to disk #
# screw with `tmn update` #
# this will ensure it's present #
# will ask to recreate as this is a breaking change #
#######################################################################
if not self.id:
self.id = self._new_id()
resources.user.write('id', self.id)
if not self.id or not self.net:
self.force_recreate = True
self.net = 'devnet'
#######################################################################

def _write(self) -> None:
if not self.name:
display.error_start_option_required('--name')
sys.exit()
sys.exit('\n')
elif not self.net:
display.error_start_option_required('--net')
sys.exit()
sys.exit('\n')
elif not self.pkey:
display.error_start_option_required('--pkey')
sys.exit()
sys.exit('\n')
self._validate()
self.id = self._new_id()
resources.user.write('id', self.id)
Expand All @@ -94,10 +95,11 @@ def _compose(self) -> None:
name='{}_chaindata'.format(self.name),
client=self.client
)
tag = 'testnet' if self.net == 'testnet' else 'latest'
self.services['metrics'] = Service(
name='{}_metrics'.format(self.name),
hostname='{}_{}'.format(self.name, self.id),
image='tomochain/telegraf:testnet',
image='tomochain/telegraf:{}'.format(tag),
network=self.networks['tmn'].name,
volumes={
'/var/run/docker.sock': {
Expand All @@ -111,7 +113,7 @@ def _compose(self) -> None:
)
self.services['tomochain'] = Service(
name='{}_tomochain'.format(self.name),
image='tomochain/node:testnet',
image='tomochain/node:{}'.format(tag),
network=self.networks['tmn'].name,
environment={
'IDENTITY': '{}_{}'.format(self.name, self.id),
Expand All @@ -125,19 +127,6 @@ def _compose(self) -> None:
ports={'30303/udp': 30303, '30303/tcp': 30303},
client=self.client
)
#######################################################################
# this is a dirty fix for retro compatiblity #
# can be removed in some future version #
# old `tmn` don't write the `net` option to disk #
# when comming from an old version, net is not defined #
# it screw with the update command #
#######################################################################
if not self.net:
if self.services['tomochain'].image.split(':')[1] == 'testnet':
self.net = 'testnet'
else:
self.net = 'devnet'
#######################################################################
for container, variables in environments[self.net].items():
for variable, value in variables.items():
self.services[container].add_environment(
Expand All @@ -150,11 +139,11 @@ def _validate(self) -> None:
if len(self.name) < 5 or len(self.name) > 30:
display.error_validation_option('--name', '5 to 30 characters '
'slug')
sys.exit()
sys.exit('\n')
if len(self.pkey) != 64:
display.error_validation_option('--pkey', '64 characters hex '
'string')
sys.exit()
sys.exit('\n')

def remove(self) -> None:
resources.user.delete('id')
Expand Down
15 changes: 15 additions & 0 deletions tmn/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,18 @@ def error_validation_option(option: str, format: str) -> None:
'<hy>{}</hy> is not valid\n'.format(option)
+ ' it should be a {}'.format(format)
)


def error_breaking_change() -> None:
"Custom error when breaking changes need to recreate the node"
error(
'latest update introduced some non-retrocompatible changes\n'
' '
'please recreate your node by deleting it\n'
' '
'<hy>tmn remove --confirm</hy>\n'
' '
'and creating it back with the same options as the old one\n'
' '
'<hy>tmn start --name ... --net ... --pkey ...</hy>'
)
17 changes: 16 additions & 1 deletion tmn/tmn.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def start(name: str, net: str, pkey: str) -> None:
"Start the containers needed to run a masternode"
configuration = Configuration(name=name, net=net, pkey=pkey, start=True,
docker_url=docker_url)
if configuration.force_recreate:
display.error_breaking_change()
sys.exit('\n')
display.title_start_masternode(configuration.name)
# volumes
display.subtitle_create_volumes()
Expand Down Expand Up @@ -85,6 +88,9 @@ def start(name: str, net: str, pkey: str) -> None:
def stop() -> None:
"Stop the masternode containers"
configuration = Configuration(docker_url=docker_url)
if configuration.force_recreate:
display.error_breaking_change()
sys.exit('\n')
display.title_stop_masternode(configuration.name)
for _, service in configuration.services.items():
display.step_stop_container(service.name)
Expand All @@ -99,6 +105,9 @@ def stop() -> None:
def status() -> None:
"Show the status of the masternode containers"
configuration = Configuration(docker_url=docker_url)
if configuration.force_recreate:
display.error_breaking_change()
sys.exit('\n')
display.title_status_masternode(configuration.name)
for _, service in configuration.services.items():
status = service.status()
Expand Down Expand Up @@ -131,6 +140,9 @@ def status() -> None:
def inspect() -> None:
"Show details about the tomochain masternode"
configuration = Configuration(docker_url=docker_url)
if configuration.force_recreate:
display.error_breaking_change()
sys.exit('\n')
display.title_inspect_masternode(configuration.name)
identity = configuration.services['tomochain'].execute(
'echo $IDENTITY'
Expand All @@ -153,6 +165,9 @@ def inspect() -> None:
def update() -> None:
"Update the tomochain masternode with the lastest images"
configuration = Configuration(docker_url=docker_url)
if configuration.force_recreate:
display.error_breaking_change()
sys.exit('\n')
display.title_update_masternode(configuration.name)
display.subtitle_remove_containers()
# containers
Expand Down Expand Up @@ -197,7 +212,7 @@ def remove(confirm: bool) -> None:
configuration = Configuration(docker_url=docker_url)
if not confirm:
display.warning_remove_masternode(configuration.name)
sys.exit()
sys.exit('\n')
display.title_remove_masternode(configuration.name)
display.subtitle_remove_containers()
# containers
Expand Down

0 comments on commit d9d28f6

Please sign in to comment.