From d061f060904e364a750afbc6c67e9716f84fb55c Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 10:22:51 +0200 Subject: [PATCH 01/17] first initial setup of the working change --- CHANGELOG.rst | 1 + rasa/cli/x.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 98e00a72a990..dd9baed27524 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -40,6 +40,7 @@ Changed trackers are still loaded from pickle but will be dumped as json in any subsequent save operations. - Event brokers are now also passed to custom tracker stores (using the ``event_broker`` parameter) +- Updated Rasa X model pull interval to be used and give a warning message if the user has a custom url in the ``endpoints.yml`` file. Removed ------- diff --git a/rasa/cli/x.py b/rasa/cli/x.py index eb4b8376b68b..998ac21c3097 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -111,11 +111,27 @@ def _overwrite_endpoints_for_local_x( from rasa.utils.endpoints import EndpointConfig import questionary - endpoints.model = EndpointConfig( + # Checking if endpoint.yml has existing url and wait time values set, if so give warning we are overwriting + # the endpoint.yml file. + custom_wait_time_pulls = endpoints.model.kwargs['wait_time_between_pulls'] + custom_url = endpoints.model.url + + if custom_url is not None: + cli_utils.print_warning("Modifying the endpoints.yml file for Rasa X with our defaults") + + if custom_wait_time_pulls: + endpoints.model = EndpointConfig( + "{}/projects/default/models/tags/production".format(rasa_x_url), + token=rasa_x_token, + wait_time_between_pulls=custom_wait_time_pulls, + ) + else: + endpoints.model = EndpointConfig( "{}/projects/default/models/tags/production".format(rasa_x_url), token=rasa_x_token, wait_time_between_pulls=2, - ) + ) + overwrite_existing_event_broker = False if endpoints.event_broker and not _is_correct_event_broker(endpoints.event_broker): From 31b953bfed4a63310341817c47ac65e70bb21305 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 10:41:19 +0200 Subject: [PATCH 02/17] first initial commit of proposed changes --- rasa/cli/x.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 998ac21c3097..f9b2bfd29063 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -113,25 +113,26 @@ def _overwrite_endpoints_for_local_x( # Checking if endpoint.yml has existing url and wait time values set, if so give warning we are overwriting # the endpoint.yml file. - custom_wait_time_pulls = endpoints.model.kwargs['wait_time_between_pulls'] + custom_wait_time_pulls = endpoints.model.kwargs["wait_time_between_pulls"] custom_url = endpoints.model.url if custom_url is not None: - cli_utils.print_warning("Modifying the endpoints.yml file for Rasa X with our defaults") - + cli_utils.print_warning( + "Modifying the endpoints.yml file for Rasa X with our defaults" + ) + if custom_wait_time_pulls: endpoints.model = EndpointConfig( - "{}/projects/default/models/tags/production".format(rasa_x_url), - token=rasa_x_token, - wait_time_between_pulls=custom_wait_time_pulls, + "{}/projects/default/models/tags/production".format(rasa_x_url), + token=rasa_x_token, + wait_time_between_pulls=custom_wait_time_pulls, ) else: endpoints.model = EndpointConfig( - "{}/projects/default/models/tags/production".format(rasa_x_url), - token=rasa_x_token, - wait_time_between_pulls=2, + "{}/projects/default/models/tags/production".format(rasa_x_url), + token=rasa_x_token, + wait_time_between_pulls=2, ) - overwrite_existing_event_broker = False if endpoints.event_broker and not _is_correct_event_broker(endpoints.event_broker): From 41e73d488910a710f625b62095e97e5e4f85841a Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 15:46:12 +0200 Subject: [PATCH 03/17] fixing the logging message based on review --- rasa/cli/x.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index f9b2bfd29063..ffc357ba05b7 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -117,8 +117,11 @@ def _overwrite_endpoints_for_local_x( custom_url = endpoints.model.url if custom_url is not None: - cli_utils.print_warning( - "Modifying the endpoints.yml file for Rasa X with our defaults" + logger.info( + "Ignoring url '{0}' from 'endpoints.yml' and using " + "{1}/projects/default/models/tag/production instead".format( + custom_url,rasa_x_url + ) ) if custom_wait_time_pulls: From 6b3123a2bb8a21a50856bf99b83ce7363ae1176b Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 15:48:03 +0200 Subject: [PATCH 04/17] fixing logging feedback and if condition --- rasa/cli/x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index ffc357ba05b7..2ea8a209cb6c 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -116,7 +116,7 @@ def _overwrite_endpoints_for_local_x( custom_wait_time_pulls = endpoints.model.kwargs["wait_time_between_pulls"] custom_url = endpoints.model.url - if custom_url is not None: + if custom_url is not None and custom_url != model_pull_url: logger.info( "Ignoring url '{0}' from 'endpoints.yml' and using " "{1}/projects/default/models/tag/production instead".format( From 522f15c017d0e13a604649ee9e73ed3d96fb3bca Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 15:55:21 +0200 Subject: [PATCH 05/17] fixing kwargs to prevent key error --- rasa/cli/x.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 2ea8a209cb6c..e268c0cb26be 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -113,10 +113,11 @@ def _overwrite_endpoints_for_local_x( # Checking if endpoint.yml has existing url and wait time values set, if so give warning we are overwriting # the endpoint.yml file. - custom_wait_time_pulls = endpoints.model.kwargs["wait_time_between_pulls"] + custom_wait_time_pulls = endpoints.model.kwargs.get("wait_time_between_pulls") custom_url = endpoints.model.url - if custom_url is not None and custom_url != model_pull_url: + + if custom_url is not None and custom_url != custom_url: logger.info( "Ignoring url '{0}' from 'endpoints.yml' and using " "{1}/projects/default/models/tag/production instead".format( From 808f99d51de873ede38a92f833b716672eefa361 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 16:01:08 +0200 Subject: [PATCH 06/17] fixed a typo in conditional statement and de-duplicated some code --- rasa/cli/x.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index e268c0cb26be..26d90d575ade 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -117,7 +117,7 @@ def _overwrite_endpoints_for_local_x( custom_url = endpoints.model.url - if custom_url is not None and custom_url != custom_url: + if custom_url is not None and custom_url != rasa_x_url: logger.info( "Ignoring url '{0}' from 'endpoints.yml' and using " "{1}/projects/default/models/tag/production instead".format( @@ -125,18 +125,11 @@ def _overwrite_endpoints_for_local_x( ) ) - if custom_wait_time_pulls: - endpoints.model = EndpointConfig( - "{}/projects/default/models/tags/production".format(rasa_x_url), - token=rasa_x_token, - wait_time_between_pulls=custom_wait_time_pulls, - ) - else: - endpoints.model = EndpointConfig( - "{}/projects/default/models/tags/production".format(rasa_x_url), - token=rasa_x_token, - wait_time_between_pulls=2, - ) + endpoints.model = EndpointConfig( + "{}/projects/default/models/tags/production".format(rasa_x_url), + token=rasa_x_token, + wait_time_between_pulls=custom_wait_time_pulls, + ) overwrite_existing_event_broker = False if endpoints.event_broker and not _is_correct_event_broker(endpoints.event_broker): From 235597b5c916fa31c12ebcf993bb0cea38f72f6b Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 16:01:53 +0200 Subject: [PATCH 07/17] added or condition to endpoints setup --- rasa/cli/x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 26d90d575ade..0915fb458b86 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -128,7 +128,7 @@ def _overwrite_endpoints_for_local_x( endpoints.model = EndpointConfig( "{}/projects/default/models/tags/production".format(rasa_x_url), token=rasa_x_token, - wait_time_between_pulls=custom_wait_time_pulls, + wait_time_between_pulls=custom_wait_time_pulls or 2, ) overwrite_existing_event_broker = False From 06d060974da722b95fc964fd3adfb121b5017553 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 18 Oct 2019 16:05:24 +0200 Subject: [PATCH 08/17] updated the changelog --- CHANGELOG.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b87508252c7a..9b5bf466c0bd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -41,7 +41,9 @@ Changed trackers are still loaded from pickle but will be dumped as json in any subsequent save operations. - Event brokers are now also passed to custom tracker stores (using the ``event_broker`` parameter) -- Updated Rasa X model pull interval to be used and give a warning message if the user has a custom url in the ``endpoints.yml`` file. +- Give a info message now if we will be updating the ``endpoints.yml`` file when using Rasa X if custom_url is set. +- If a ``wait_time_between_pulls`` is configured for the model server in ``endpoints.yml``, + this will be used instead of the default one when running Rasa X - Updated the ``/status`` api route to use the actual model file location instead of the ``tmp`` location. From e674b898ff9428c13c5712d3aabd604c2be1dd8c Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Tue, 22 Oct 2019 09:23:34 +0200 Subject: [PATCH 09/17] updating PR based on feedback --- CHANGELOG.rst | 2 +- rasa/cli/x.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9b5bf466c0bd..6ab68fd2f36e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -41,7 +41,7 @@ Changed trackers are still loaded from pickle but will be dumped as json in any subsequent save operations. - Event brokers are now also passed to custom tracker stores (using the ``event_broker`` parameter) -- Give a info message now if we will be updating the ``endpoints.yml`` file when using Rasa X if custom_url is set. +- Print info message when running Rasa X and and custom model server url was specified in ``endpoints.yml`` - If a ``wait_time_between_pulls`` is configured for the model server in ``endpoints.yml``, this will be used instead of the default one when running Rasa X - Updated the ``/status`` api route to use the actual model file location instead of the ``tmp`` location. diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 0915fb458b86..701f57cce702 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -117,16 +117,14 @@ def _overwrite_endpoints_for_local_x( custom_url = endpoints.model.url - if custom_url is not None and custom_url != rasa_x_url: + if custom_url and custom_url != rasa_x_url: logger.info( - "Ignoring url '{0}' from 'endpoints.yml' and using " - "{1}/projects/default/models/tag/production instead".format( - custom_url,rasa_x_url - ) + f"Ignoring url '{custom_url}' from 'endpoints.yml' and using " + f"{rasa_x_url}/projects/default/models/tag/production instead" ) endpoints.model = EndpointConfig( - "{}/projects/default/models/tags/production".format(rasa_x_url), + f"{rasa_x_url}/projects/default/models/tags/production", token=rasa_x_token, wait_time_between_pulls=custom_wait_time_pulls or 2, ) From 4c75164e4cfdb0ec56e357404cc919c40ba00540 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Tue, 22 Oct 2019 10:27:21 +0200 Subject: [PATCH 10/17] fixing linting error --- rasa/cli/x.py | 1 - 1 file changed, 1 deletion(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 701f57cce702..ca6e6d4d4e6d 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -116,7 +116,6 @@ def _overwrite_endpoints_for_local_x( custom_wait_time_pulls = endpoints.model.kwargs.get("wait_time_between_pulls") custom_url = endpoints.model.url - if custom_url and custom_url != rasa_x_url: logger.info( f"Ignoring url '{custom_url}' from 'endpoints.yml' and using " From b6c2a50cd90d40aba333d364b252bfd2739c7a55 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Tue, 29 Oct 2019 08:45:06 -0400 Subject: [PATCH 11/17] updating based on feedback --- CHANGELOG.rst | 6 +++--- rasa/cli/x.py | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index aae22fcfe471..176e43c5468b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,9 @@ Added Changed ------- +- Print info message when running Rasa X and and custom model server url was specified in ``endpoints.yml`` +- If a ``wait_time_between_pulls`` is configured for the model server in ``endpoints.yml``, + this will be used instead of the default one when running Rasa X Removed ------- @@ -80,9 +83,6 @@ Changed trackers are still loaded from pickle but will be dumped as json in any subsequent save operations. - Event brokers are now also passed to custom tracker stores (using the ``event_broker`` parameter) -- Print info message when running Rasa X and and custom model server url was specified in ``endpoints.yml`` -- If a ``wait_time_between_pulls`` is configured for the model server in ``endpoints.yml``, - this will be used instead of the default one when running Rasa X - Don't run the Rasa Docker image as ``root``. - Use multi-stage builds to reduce the size of the Rasa Docker image. - Updated the ``/status`` api route to use the actual model file location instead of the ``tmp`` location. diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 265d4ab9f7c3..732f0038664a 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -116,15 +116,16 @@ def _overwrite_endpoints_for_local_x( # the endpoint.yml file. custom_wait_time_pulls = endpoints.model.kwargs.get("wait_time_between_pulls") custom_url = endpoints.model.url + default_rasax_model_server_url = f"{rasa_x_url}/projects/default/models/tag/production" - if custom_url and custom_url != rasa_x_url: + if custom_url != default_rasax_model_server_url: logger.info( f"Ignoring url '{custom_url}' from 'endpoints.yml' and using " - f"{rasa_x_url}/projects/default/models/tag/production instead" + f"{default_rasax_model_server_url} instead" ) endpoints.model = EndpointConfig( - f"{rasa_x_url}/projects/default/models/tags/production", + f"{default_rasax_model_server_url}", token=rasa_x_token, wait_time_between_pulls=custom_wait_time_pulls or 2, ) From dcb942633eb4271af977b310c46e9f85d664de17 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Tue, 29 Oct 2019 09:05:13 -0400 Subject: [PATCH 12/17] forgot check to verify custom_url isn't empty --- rasa/cli/x.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 732f0038664a..b3494caaa35a 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -118,7 +118,7 @@ def _overwrite_endpoints_for_local_x( custom_url = endpoints.model.url default_rasax_model_server_url = f"{rasa_x_url}/projects/default/models/tag/production" - if custom_url != default_rasax_model_server_url: + if custom_url is not None and != default_rasax_model_server_url: logger.info( f"Ignoring url '{custom_url}' from 'endpoints.yml' and using " f"{default_rasax_model_server_url} instead" From 0d9fd830719715313dc71d2204aac5ddd2a44401 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Wed, 30 Oct 2019 06:56:20 -0400 Subject: [PATCH 13/17] fixing 2 review issues --- rasa/cli/x.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index b3494caaa35a..2f8510ae7e91 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -118,10 +118,10 @@ def _overwrite_endpoints_for_local_x( custom_url = endpoints.model.url default_rasax_model_server_url = f"{rasa_x_url}/projects/default/models/tag/production" - if custom_url is not None and != default_rasax_model_server_url: + if custom_url is not None and custom_url != default_rasax_model_server_url: logger.info( f"Ignoring url '{custom_url}' from 'endpoints.yml' and using " - f"{default_rasax_model_server_url} instead" + f"'{default_rasax_model_server_url}' instead" ) endpoints.model = EndpointConfig( From 86857263cdf76ef6c5d97b93989eb61d68a662fe Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Wed, 30 Oct 2019 06:57:04 -0400 Subject: [PATCH 14/17] updating with black --- rasa/cli/x.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 2f8510ae7e91..487b6c5acc4b 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -116,7 +116,9 @@ def _overwrite_endpoints_for_local_x( # the endpoint.yml file. custom_wait_time_pulls = endpoints.model.kwargs.get("wait_time_between_pulls") custom_url = endpoints.model.url - default_rasax_model_server_url = f"{rasa_x_url}/projects/default/models/tag/production" + default_rasax_model_server_url = ( + f"{rasa_x_url}/projects/default/models/tag/production" + ) if custom_url is not None and custom_url != default_rasax_model_server_url: logger.info( From b56a67b0819ba0957dbf3aee11a6986c5b205254 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 15 Nov 2019 09:33:44 -0500 Subject: [PATCH 15/17] updating first test to check for url --- rasa/cli/x.py | 2 ++ tests/cli/test_rasa_x.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index 487b6c5acc4b..1c7c56818958 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -150,6 +150,8 @@ def _overwrite_endpoints_for_local_x( if not endpoints.tracker_store or overwrite_existing_event_broker: endpoints.event_broker = EndpointConfig(type="sql", db=DEFAULT_EVENTS_DB) + return endpoints + def _is_correct_event_broker(event_broker: EndpointConfig) -> bool: return all( diff --git a/tests/cli/test_rasa_x.py b/tests/cli/test_rasa_x.py index 6b6da6cbfa1c..d254bebfbd0e 100644 --- a/tests/cli/test_rasa_x.py +++ b/tests/cli/test_rasa_x.py @@ -9,6 +9,7 @@ import rasa.utils.io as io_utils from rasa.cli import x from rasa.utils.endpoints import EndpointConfig +from rasa.core.utils import AvailableEndpoints def test_x_help(run: Callable[..., RunResult]): @@ -79,6 +80,14 @@ def test_if_endpoint_config_is_invalid_in_local_mode(kwargs: Dict): config = EndpointConfig(**kwargs) assert not x._is_correct_event_broker(config) +def test_wait_time_between_pulls_custom(): + #endpoint_config = EndpointConfig(url="http://localhost:5002/api/projects/default/models/tag/production", wait_time_between_pulls=3) + endpoint_config = EndpointConfig(url="http://testserver:5002/models/default@latest", wait_time_between_pulls=5) + endpoints = AvailableEndpoints(model=endpoint_config) + + updated_endpoints = x._overwrite_endpoints_for_local_x(endpoints, "test", "http://localhost") + updated_config = updated_endpoints.model + assert updated_config.url == 'http://localhost/projects/default/models/tag/production' async def test_pull_runtime_config_from_server(): config_url = "http://example.com/api/config?token=token" @@ -99,6 +108,7 @@ async def test_pull_runtime_config_from_server(): endpoints_path, credentials_path = await x._pull_runtime_config_from_server( config_url, 1, 0 ) + with open(endpoints_path) as f: assert f.read() == endpoint_config From 54a372a355bc4867a8b8265b8c60cfe06f923d1f Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 15 Nov 2019 10:13:59 -0500 Subject: [PATCH 16/17] cleaning up some code based on review --- rasa/cli/x.py | 6 +++--- tests/cli/test_rasa_x.py | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/rasa/cli/x.py b/rasa/cli/x.py index bac01c3af8f0..8da99c7234eb 100644 --- a/rasa/cli/x.py +++ b/rasa/cli/x.py @@ -120,14 +120,14 @@ def _overwrite_endpoints_for_local_x( f"{rasa_x_url}/projects/default/models/tag/production" ) - if custom_url is not None and custom_url != default_rasax_model_server_url: + if custom_url != default_rasax_model_server_url: logger.info( f"Ignoring url '{custom_url}' from 'endpoints.yml' and using " - f"'{default_rasax_model_server_url}' instead" + f"'{default_rasax_model_server_url}' instead." ) endpoints.model = EndpointConfig( - f"{default_rasax_model_server_url}", + default_rasax_model_server_url, token=rasa_x_token, wait_time_between_pulls=custom_wait_time_pulls or 2, ) diff --git a/tests/cli/test_rasa_x.py b/tests/cli/test_rasa_x.py index 30c32c48db15..d1544f9f3751 100644 --- a/tests/cli/test_rasa_x.py +++ b/tests/cli/test_rasa_x.py @@ -127,7 +127,6 @@ async def test_pull_runtime_config_from_server(): config_url, 1, 0 ) - with open(endpoints_path) as f: assert f.read() == endpoint_config with open(credentials_path) as f: From 0fc1032632a3e1796c4b7e23a500f8ca83bd5995 Mon Sep 17 00:00:00 2001 From: Brian Hopkins Date: Fri, 15 Nov 2019 10:17:20 -0500 Subject: [PATCH 17/17] fixed some formatting for tests --- tests/cli/test_rasa_x.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/tests/cli/test_rasa_x.py b/tests/cli/test_rasa_x.py index d1544f9f3751..03e1f01b7ae7 100644 --- a/tests/cli/test_rasa_x.py +++ b/tests/cli/test_rasa_x.py @@ -16,7 +16,6 @@ from tests.conftest import assert_log_emitted - def test_x_help(run: Callable[..., RunResult]): output = run("x", "--help") @@ -85,26 +84,40 @@ def test_if_endpoint_config_is_invalid_in_local_mode(kwargs: Dict): config = EndpointConfig(**kwargs) assert not x._is_correct_event_broker(config) + def test_overwrite_for_local_x(caplog: LogCaptureFixture): test_wait_time = 5 default_wait_time = 2 - endpoint_config_missing_wait = EndpointConfig(url="http://testserver:5002/models/default@latest") - endpoint_config_custom = EndpointConfig(url="http://testserver:5002/models/default@latest", wait_time_between_pulls=test_wait_time) + endpoint_config_missing_wait = EndpointConfig( + url="http://testserver:5002/models/default@latest" + ) + endpoint_config_custom = EndpointConfig( + url="http://testserver:5002/models/default@latest", + wait_time_between_pulls=test_wait_time, + ) endpoints_custom = AvailableEndpoints(model=endpoint_config_custom) endpoints_missing_wait = AvailableEndpoints(model=endpoint_config_missing_wait) # Check that we get INFO message about overwriting the endpoints configuration log_message = "Ignoring url 'http://testserver:5002/models/default@latest' from 'endpoints.yml' and using 'http://localhost/projects/default/models/tag/production' instead" - with assert_log_emitted(caplog, 'rasa.cli.x', logging.INFO, log_message): + with assert_log_emitted(caplog, "rasa.cli.x", logging.INFO, log_message): x._overwrite_endpoints_for_local_x(endpoints_custom, "test", "http://localhost") # Checking for url to be changed in config and wait time value to be honored - assert endpoints_custom.model.url == 'http://localhost/projects/default/models/tag/production' - assert endpoints_custom.model.kwargs['wait_time_between_pulls'] == test_wait_time + assert ( + endpoints_custom.model.url + == "http://localhost/projects/default/models/tag/production" + ) + assert endpoints_custom.model.kwargs["wait_time_between_pulls"] == test_wait_time # Check for wait time to be set to 3 since it isn't specified - x._overwrite_endpoints_for_local_x(endpoints_missing_wait, "test", "http://localhost") - assert endpoints_missing_wait.model.kwargs['wait_time_between_pulls'] == default_wait_time + x._overwrite_endpoints_for_local_x( + endpoints_missing_wait, "test", "http://localhost" + ) + assert ( + endpoints_missing_wait.model.kwargs["wait_time_between_pulls"] + == default_wait_time + ) async def test_pull_runtime_config_from_server(): @@ -126,7 +139,7 @@ async def test_pull_runtime_config_from_server(): endpoints_path, credentials_path = await x._pull_runtime_config_from_server( config_url, 1, 0 ) - + with open(endpoints_path) as f: assert f.read() == endpoint_config with open(credentials_path) as f: