Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if local tracker store is the correct one #3697

Merged
merged 3 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Fixed
-----
- slack notifications from bots correctly render text
- fixed usage of ``--log-file`` argument for ``rasa run`` and ``rasa shell``

- check if correct tracker store is configured in local mode

[1.0.6] - 2019-06-03
^^^^^^^^^^^^^^^^^^^^
Expand Down
32 changes: 29 additions & 3 deletions rasa/cli/x.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import functools
import importlib.util
import logging
import signal
Expand All @@ -22,6 +21,7 @@
DEFAULT_LOG_LEVEL_RASA_X,
)
import rasa.utils.io as io_utils
from rasa.utils.endpoints import EndpointConfig

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -97,17 +97,43 @@ def _prepare_credentials_for_rasa_x(


def _overwrite_endpoints_for_local_x(endpoints, rasa_x_token, rasa_x_url):
from rasa.utils.endpoints import EndpointConfig
import questionary

endpoints.model = EndpointConfig(
"{}/projects/default/models/tags/production".format(rasa_x_url),
token=rasa_x_token,
wait_time_between_pulls=2,
)
if not endpoints.tracker_store:

overwrite_existing_tracker_store = False
if endpoints.tracker_store and not _is_correct_tracker_store(
endpoints.tracker_store
):
print_error(
"Rasa X currently only supports a SQLite tracker store with path '{}' "
"when running locally. You can deploy Rasa X with Docker "
"(https://rasa.com/docs/rasa-x/deploy/) if you want to use "
"other tracker store configurations.".format(DEFAULT_TRACKER_DB)
)
overwrite_existing_tracker_store = questionary.confirm(
"Do you want to continue with the default SQLite tracker store?"
).ask()

if not overwrite_existing_tracker_store:
exit(0)

if not endpoints.tracker_store or overwrite_existing_tracker_store:
endpoints.tracker_store = EndpointConfig(type="sql", db=DEFAULT_TRACKER_DB)


def _is_correct_tracker_store(tracker_endpoint: EndpointConfig) -> bool:
return (
tracker_endpoint.type == "sql"
and tracker_endpoint.kwargs.get("dialect", "").lower() == "sqlite"
and tracker_endpoint.kwargs.get("db") == DEFAULT_TRACKER_DB
)


def start_rasa_for_local_rasa_x(args: argparse.Namespace, rasa_x_token: Text):
"""Starts the Rasa X API with Rasa as a background process."""

Expand Down
23 changes: 23 additions & 0 deletions tests/cli/test_rasa_x.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest

import rasa.utils.io as io_utils
from rasa.cli import x
from rasa.utils.endpoints import EndpointConfig


def test_x_help(run):
Expand Down Expand Up @@ -49,3 +52,23 @@ def test_prepare_credentials_if_already_valid(tmpdir_factory):
actual = io_utils.read_yaml_file(credentials_path)

assert actual == credentials


def test_if_endpoint_config_is_valid_in_local_mode():
config = EndpointConfig(type="sql", dialect="sqlite", db=x.DEFAULT_TRACKER_DB)

assert x._is_correct_tracker_store(config)


@pytest.mark.parametrize(
"kwargs",
[
{"type": "mongo", "url": "mongodb://localhost:27017"},
{"type": "sql", "dialect": "postgresql"},
{"type": "sql", "dialect": "sqlite", "db": "some.db"},
],
)
def test_if_endpoint_config_is_invalid_in_local_mode(kwargs):
config = EndpointConfig(**kwargs)

assert not x._is_correct_tracker_store(config)