getting tarantool into testing mode

This commit is contained in:
Jürgen Eckel 2022-02-28 10:31:08 +01:00
parent bd373d0419
commit 22ab57bba4
11 changed files with 100 additions and 49 deletions

View File

@ -26,6 +26,15 @@ env:
matrix: matrix:
fast_finish: true fast_finish: true
include: include:
- python: 3.9
env:
- PLANETMINT_DATABASE_BACKEND=tarantool
- PLANETMINT_DATABASE_SSL=
- python: 3.9
env:
- PLANETMINT_DATABASE_BACKEND=tarantool
- PLANETMINT_DATABASE_SSL=
- PLANETMINT_CI_ABCI=enable
- python: 3.9 - python: 3.9
env: env:
- PLANETMINT_DATABASE_BACKEND=localmongodb - PLANETMINT_DATABASE_BACKEND=localmongodb
@ -35,6 +44,7 @@ matrix:
- PLANETMINT_DATABASE_BACKEND=localmongodb - PLANETMINT_DATABASE_BACKEND=localmongodb
- PLANETMINT_DATABASE_SSL= - PLANETMINT_DATABASE_SSL=
- PLANETMINT_CI_ABCI=enable - PLANETMINT_CI_ABCI=enable
- python: 3.9 - python: 3.9
env: env:
- PLANETMINT_ACCEPTANCE_TEST=enable - PLANETMINT_ACCEPTANCE_TEST=enable

View File

@ -34,7 +34,7 @@ RUN mkdir -p /data/db /data/configdb \
# Planetmint enviroment variables # Planetmint enviroment variables
ENV PLANETMINT_DATABASE_PORT 27017 ENV PLANETMINT_DATABASE_PORT 27017
ENV PLANETMINT_DATABASE_BACKEND localmongodb ENV PLANETMINT_DATABASE_BACKEND tarantool
ENV PLANETMINT_SERVER_BIND 0.0.0.0:9984 ENV PLANETMINT_SERVER_BIND 0.0.0.0:9984
ENV PLANETMINT_WSSERVER_HOST 0.0.0.0 ENV PLANETMINT_WSSERVER_HOST 0.0.0.0
ENV PLANETMINT_WSSERVER_SCHEME ws ENV PLANETMINT_WSSERVER_SCHEME ws

View File

@ -14,6 +14,15 @@ services:
- "27017:27017" - "27017:27017"
command: mongod command: mongod
restart: always restart: always
tarantool:
image: tarantool/tarantool:2.3.1
ports:
- "5200:5200"
- "3301:3301"
command: tarantool
restart: always
planetmint: planetmint:
depends_on: depends_on:
- mongodb - mongodb
@ -31,9 +40,9 @@ services:
- ./pytest.ini:/usr/src/app/pytest.ini - ./pytest.ini:/usr/src/app/pytest.ini
- ./tox.ini:/usr/src/app/tox.ini - ./tox.ini:/usr/src/app/tox.ini
environment: environment:
PLANETMINT_DATABASE_BACKEND: localmongodb PLANETMINT_DATABASE_BACKEND: tarantool
PLANETMINT_DATABASE_HOST: mongodb PLANETMINT_DATABASE_HOST: tarantool
PLANETMINT_DATABASE_PORT: 27017 PLANETMINT_DATABASE_PORT: 3301
PLANETMINT_SERVER_BIND: 0.0.0.0:9984 PLANETMINT_SERVER_BIND: 0.0.0.0:9984
PLANETMINT_WSSERVER_HOST: 0.0.0.0 PLANETMINT_WSSERVER_HOST: 0.0.0.0
PLANETMINT_WSSERVER_ADVERTISED_HOST: planetmint PLANETMINT_WSSERVER_ADVERTISED_HOST: planetmint
@ -43,6 +52,7 @@ services:
- "9984:9984" - "9984:9984"
- "9985:9985" - "9985:9985"
- "26658" - "26658"
- "2222:2222"
healthcheck: healthcheck:
test: ["CMD", "bash", "-c", "curl http://planetmint:9984 && curl http://tendermint:26657/abci_query"] test: ["CMD", "bash", "-c", "curl http://planetmint:9984 && curl http://tendermint:26657/abci_query"]
interval: 3s interval: 3s
@ -50,6 +60,7 @@ services:
retries: 3 retries: 3
command: '.ci/entrypoint.sh' command: '.ci/entrypoint.sh'
restart: always restart: always
tendermint: tendermint:
image: tendermint/tendermint:v0.31.5 image: tendermint/tendermint:v0.31.5
# volumes: # volumes:
@ -60,6 +71,7 @@ services:
- "26657:26657" - "26657:26657"
command: sh -c "tendermint init && tendermint node --consensus.create_empty_blocks=false --proxy_app=tcp://planetmint:26658" command: sh -c "tendermint init && tendermint node --consensus.create_empty_blocks=false --proxy_app=tcp://planetmint:26658"
restart: always restart: always
bdb: bdb:
image: busybox image: busybox
depends_on: depends_on:
@ -93,7 +105,7 @@ services:
context: . context: .
dockerfile: Dockerfile-dev dockerfile: Dockerfile-dev
args: args:
backend: localmongodb backend: tarantool
volumes: volumes:
- .:/usr/src/app/ - .:/usr/src/app/
command: make -C docs/root html command: make -C docs/root html

View File

@ -6,6 +6,7 @@
import copy import copy
import logging import logging
import os import os
#import planetmint.debug
from planetmint.log import DEFAULT_LOGGING_CONFIG as log_config from planetmint.log import DEFAULT_LOGGING_CONFIG as log_config
from planetmint.lib import Planetmint # noqa from planetmint.lib import Planetmint # noqa
@ -23,45 +24,57 @@ from planetmint.core import App # noqa
# I tried to configure # I tried to configure
_database_keys_map = { # TODO Check if it is working after removing 'name' field _database_keys_map = { # TODO Check if it is working after removing 'name' field
'tarantool_db': ('host', 'port'), 'tarantool': ('host', 'port'),
'localmongodb': ('host', 'port', 'name'),
} }
_base_database_tarantool_local_db = { # TODO Rewrite this configs for tarantool usage _base_database_localmongodb = {
'host': 'localhost', 'host': 'localhost',
'port': 27017,
'name': 'planetmint',
'replicaset': None,
'login': None,
'password': None,
}
_database_localmongodb = {
'backend': 'localmongodb',
'connection_timeout': 5000,
'max_tries': 3,
'ssl': False,
'ca_cert': None,
'certfile': None,
'keyfile': None,
'keyfile_passphrase': None,
'crlfile': None,
}
_database_localmongodb.update(_base_database_localmongodb)
_base_database_tarantool_local_db = { # TODO Rewrite this configs for tarantool usage
'host': 'tarantool',
'port': 3301, 'port': 3301,
'username': None, 'username': 'guest',
'password': None, 'password': None,
"connect_now": True, "connect_now": True,
"encoding": "utf-8" "encoding": "utf-8"
} }
init_config = {
"init_file": "init_db.txt",
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
}
drop_config = {
"drop_file": "drop_db.txt", # planetmint/backend/tarantool/init_db.txt
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
}
_database_tarantool = { _database_tarantool = {
'backend': 'tarantool_db', 'backend': 'tarantool',
'connection_timeout': 5000, 'connection_timeout': 5000,
'max_tries': 3, 'max_tries': 3,
"reconnect_delay": 0.5, "reconnect_delay": 0.5,
"ctl_config": { #"host": "admin:pass@127.0.0.1:3301",
"login": "admin", #"service": "tarantoolctl connect",
"host": "admin:pass@127.0.0.1:3301",
"service": "tarantoolctl connect",
"init_config": init_config,
"drop_config": drop_config
}
} }
_database_tarantool.update(_base_database_tarantool_local_db) _database_tarantool.update(_base_database_tarantool_local_db)
_database_map = { _database_map = {
'tarantool_db': _database_tarantool 'tarantool': _database_tarantool,
'localmongodb': _database_localmongodb,
} }
config = { config = {
'server': { 'server': {
# Note: this section supports all the Gunicorn settings: # Note: this section supports all the Gunicorn settings:
@ -85,7 +98,7 @@ config = {
'version': 'v0.31.5', # look for __tm_supported_versions__ 'version': 'v0.31.5', # look for __tm_supported_versions__
}, },
# TODO Maybe remove hardcode configs for tarantool (review) # TODO Maybe remove hardcode configs for tarantool (review)
'database': _database_map['tarantool_db'], 'database': _database_map['tarantool'],
'log': { 'log': {
'file': log_config['handlers']['file']['filename'], 'file': log_config['handlers']['file']['filename'],
'error_file': log_config['handlers']['errors']['filename'], 'error_file': log_config['handlers']['errors']['filename'],

View File

@ -9,19 +9,30 @@ from itertools import repeat
import tarantool import tarantool
import planetmint import planetmint
import os
from planetmint.backend.exceptions import ConnectionError from planetmint.backend.exceptions import ConnectionError
from planetmint.backend.utils import get_planetmint_config_value, get_planetmint_config_value_or_key_error from planetmint.backend.utils import get_planetmint_config_value, get_planetmint_config_value_or_key_error
from planetmint.common.exceptions import ConfigurationError from planetmint.common.exceptions import ConfigurationError
BACKENDS = { # This is path to MongoDBClass BACKENDS = { # This is path to MongoDBClass
'tarantool_db': 'planetmint.backend.connection_tarantool.TarantoolDB', 'tarantool': 'planetmint.backend.connection_tarantool.TarantoolDB',
} }
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class TarantoolDB: class TarantoolDB:
init_config = {
"init_file": "init_db.txt",
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
}
drop_config = {
"drop_file": "drop_db.txt", # planetmint/backend/tarantool/init_db.txt
"relative_path": os.path.dirname(os.path.abspath(__file__)) + "/backend/tarantool/"
}
def __init__(self, host: str, port: int, user: str, password: str, reset_database: bool = False): def __init__(self, host: str, port: int, user: str, password: str, reset_database: bool = False):
self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password) self.db_connect = tarantool.connect(host=host, port=port, user=user, password=password)
if reset_database: if reset_database:
@ -40,23 +51,25 @@ class TarantoolDB:
def drop_database(self): def drop_database(self):
from planetmint.backend.tarantool.utils import run from planetmint.backend.tarantool.utils import run
config = get_planetmint_config_value_or_key_error("ctl_config") # config = get_planetmint_config_value_or_key_error("ctl_config")
drop_config = config["drop_config"] # drop_config = config["drop_config"]
f_path = "%s%s" % (drop_config["relative_path"], drop_config["drop_file"]) f_path = "%s%s" % (self.drop_config["relative_path"], self.drop_config["drop_file"])
commands = self.__read_commands(file_path=f_path) commands = self.__read_commands(file_path=f_path)
run(commands=commands, config=config) run(commands=commands, config=config)
def init_database(self): def init_database(self):
from planetmint.backend.tarantool.utils import run from planetmint.backend.tarantool.utils import run
config = get_planetmint_config_value_or_key_error("ctl_config") # config = get_planetmint_config_value_or_key_error("ctl_config")
init_config = config["init_config"] # init_config = config["init_config"]
f_path = "%s%s" % (init_config["relative_path"], init_config["init_file"]) f_path = "%s%s" % (self.init_config["relative_path"], self.init_config["init_file"])
commands = self.__read_commands(file_path=f_path) commands = self.__read_commands(file_path=f_path)
run(commands=commands, config=config) run(commands=commands, config=config)
def connect(host: str = None, port: int = None, username: str = "admin", password: str = "pass",
def connect(host: str = None, port: int = None, username: str = None, password: str = None,
backend: str = None, reset_database: bool = False, name=None, max_tries=None, backend: str = None, reset_database: bool = False, name=None, max_tries=None,
connection_timeout=None, replicaset=None, ssl=None, login: str = "admin", ctl_config=None, connection_timeout=None, replicaset=None, ssl=None, login: str = None, ctl_config=None,
ca_cert=None, certfile=None, keyfile=None, keyfile_passphrase=None, reconnect_delay=None, ca_cert=None, certfile=None, keyfile=None, keyfile_passphrase=None, reconnect_delay=None,
crlfile=None, connect_now=True, encoding=None): crlfile=None, connect_now=True, encoding=None):
backend = backend or get_planetmint_config_value_or_key_error('backend') # TODO Rewrite Configs backend = backend or get_planetmint_config_value_or_key_error('backend') # TODO Rewrite Configs
@ -73,6 +86,9 @@ def connect(host: str = None, port: int = None, username: str = "admin", passwor
'Planetmint currently supports {}'.format(backend, BACKENDS.keys())) 'Planetmint currently supports {}'.format(backend, BACKENDS.keys()))
except (ImportError, AttributeError) as exc: except (ImportError, AttributeError) as exc:
raise ConfigurationError('Error loading backend `{}`'.format(backend)) from exc raise ConfigurationError('Error loading backend `{}`'.format(backend)) from exc
print(host)
print(port)
print(username)
logger.debug('Connection: {}'.format(Class)) logger.debug('Connection: {}'.format(Class))
return Class(host=host, port=port, user=username, password=password, reset_database=reset_database) return Class(host=host, port=port, user=username, password=password, reset_database=reset_database)

View File

@ -5,7 +5,7 @@
"""Query implementation for MongoDB""" """Query implementation for MongoDB"""
from pymongo import DESCENDING #from pymongo import DESCENDING
from secrets import token_hex from secrets import token_hex
from operator import itemgetter from operator import itemgetter

View File

@ -318,12 +318,11 @@ def create_parser():
help='Prepare the config file.') help='Prepare the config file.')
config_parser.add_argument('backend', config_parser.add_argument('backend',
choices=['tarantool_db'], choices=['tarantool', 'localmongodb'],
default='tarantool_db', default='tarantool',
const='tarantool_db', const='tarantool',
nargs='?', nargs='?',
help='The backend to use. It can only be ' help='The backend to use. Tarantool is default.')
'"tarantool_db", currently.')
# parser for managing elections # parser for managing elections
election_parser = subparsers.add_parser('election', election_parser = subparsers.add_parser('election',

View File

@ -91,9 +91,10 @@ install_requires = [
'pyyaml==5.4.1', 'pyyaml==5.4.1',
'requests==2.25.1', 'requests==2.25.1',
'setproctitle==1.2.2', 'setproctitle==1.2.2',
'ptvsd'
] ]
if sys.version_info < (3, 6): if sys.version_info < (3, 9):
install_requires.append('pysha3~=1.0.2') install_requires.append('pysha3~=1.0.2')
setup( setup(

View File

@ -181,7 +181,7 @@ def test_run_configure_when_config_does_exist(monkeypatch,
@pytest.mark.skip @pytest.mark.skip
@pytest.mark.parametrize('backend', ( @pytest.mark.parametrize('backend', (
'localmongodb', 'tarantool',
)) ))
def test_run_configure_with_backend(backend, monkeypatch, mock_write_config): def test_run_configure_with_backend(backend, monkeypatch, mock_write_config):
import planetmint import planetmint

View File

@ -48,7 +48,7 @@ def pytest_addoption(parser):
parser.addoption( parser.addoption(
'--database-backend', '--database-backend',
action='store', action='store',
default=os.environ.get('PLANETMINT_DATABASE_BACKEND', 'tarantool_db'), default=os.environ.get('PLANETMINT_DATABASE_BACKEND', 'tarantool'),
help='Defines the backend to use (available: {})'.format(backends), help='Defines the backend to use (available: {})'.format(backends),
) )
@ -97,7 +97,7 @@ def _configure_planetmint(request):
test_db_name = '{}_{}'.format(TEST_DB_NAME, xdist_suffix) test_db_name = '{}_{}'.format(TEST_DB_NAME, xdist_suffix)
# backend = request.config.getoption('--database-backend') # backend = request.config.getoption('--database-backend')
backend = "tarantool_db" backend = "tarantool"
config = { config = {
'database': planetmint._database_map[backend], 'database': planetmint._database_map[backend],

View File

@ -185,7 +185,7 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
config_utils.autoconfigure() config_utils.autoconfigure()
database_mongodb = { database_mongodb = {
'backend': 'localmongodb', 'backend': 'tarantool',
'host': DATABASE_HOST, 'host': DATABASE_HOST,
'port': DATABASE_PORT, 'port': DATABASE_PORT,
'name': DATABASE_NAME, 'name': DATABASE_NAME,