From 3ea972229a2a40f6be5e0d2d3c35a4e29504bbbf Mon Sep 17 00:00:00 2001 From: Shailendra Paliwal Date: Tue, 26 Sep 2023 12:18:03 +0200 Subject: [PATCH] ATO-1520-35x (#12851) * add username to Redis Lock and Tracker Stores * reformat * add changelog --- .github/workflows/continous-integration.yml | 4 +++ changelog/12851.improvement.md | 1 + data/test_endpoints/example_endpoints.yml | 14 +++++++++ docs/docs/lock-stores.mdx | 2 ++ docs/docs/tracker-stores.mdx | 2 ++ rasa/core/lock_store.py | 4 +++ rasa/core/tracker_store.py | 2 ++ tests/core/test_lock_store.py | 33 ++++++++++++++++----- tests/core/test_tracker_stores.py | 2 ++ 9 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 changelog/12851.improvement.md diff --git a/.github/workflows/continous-integration.yml b/.github/workflows/continous-integration.yml index c83e779c8510..474130fcdd01 100644 --- a/.github/workflows/continous-integration.yml +++ b/.github/workflows/continous-integration.yml @@ -215,6 +215,7 @@ jobs: name: Run Tests if: github.ref_type != 'tag' runs-on: ${{ matrix.os }} + timeout-minutes: 60 needs: [changes] strategy: fail-fast: false @@ -363,6 +364,7 @@ jobs: name: Run Flaky Tests if: github.ref_type != 'tag' runs-on: ${{ matrix.os }} + timeout-minutes: 60 needs: [changes] strategy: fail-fast: false @@ -554,6 +556,7 @@ jobs: name: Run Non-Sequential Integration Tests if: github.ref_type != 'tag' runs-on: ubuntu-22.04 + timeout-minutes: 60 needs: [changes] env: REDIS_HOST: localhost @@ -690,6 +693,7 @@ jobs: name: Run Sequential Integration Tests if: github.ref_type != 'tag' runs-on: ubuntu-20.04 + timeout-minutes: 60 needs: [changes] env: POSTGRES_HOST: localhost diff --git a/changelog/12851.improvement.md b/changelog/12851.improvement.md new file mode 100644 index 000000000000..0fea8ac19d52 --- /dev/null +++ b/changelog/12851.improvement.md @@ -0,0 +1 @@ +Added `username` to the connection parameters for `RedisLockStore` and `RedisTrackerStore` \ No newline at end of file diff --git a/data/test_endpoints/example_endpoints.yml b/data/test_endpoints/example_endpoints.yml index fccc4f9c4594..2e07554cee98 100644 --- a/data/test_endpoints/example_endpoints.yml +++ b/data/test_endpoints/example_endpoints.yml @@ -13,6 +13,7 @@ tracker_store: url: localhost port: 6379 db: 0 + username: username password: password key_prefix: conversation record_exp: 30000 @@ -20,6 +21,19 @@ tracker_store: ssl_keyfile: "keyfile.key" ssl_certfile: "certfile.crt" ssl_ca_certs: "my-bundle.ca-bundle" +# example of redis external lock store config +lock_store: + type: redis + url: localhost + port: 6379 + db: 0 + username: username + password: password + key_prefix: lock + use_ssl: True + ssl_keyfile: "keyfile.key" + ssl_certfile: "certfile.crt" + ssl_ca_certs: "my-bundle.ca-bundle" # example of mongoDB external tracker store config #tracker_store: #type: mongod diff --git a/docs/docs/lock-stores.mdx b/docs/docs/lock-stores.mdx index 5889d953eac8..8f0a1b66a285 100644 --- a/docs/docs/lock-stores.mdx +++ b/docs/docs/lock-stores.mdx @@ -156,6 +156,8 @@ The `ConcurrentRedisLockStore` recreates the `TicketLock` from the persisted `Ti - `key_prefix` (default: `None`): The prefix to prepend to lock store keys. Must be alphanumeric + - `username` (default: `None`): Username used for authentication + - `password` (default: `None`): Password used for authentication (`None` equals no authentication) diff --git a/docs/docs/tracker-stores.mdx b/docs/docs/tracker-stores.mdx index f3ac71f4a2d1..f0485583c451 100644 --- a/docs/docs/tracker-stores.mdx +++ b/docs/docs/tracker-stores.mdx @@ -219,6 +219,8 @@ To set up Rasa with Redis the following steps are required: * `key_prefix` (default: `None`): The prefix to prepend to tracker store keys. Must be alphanumeric +* `username` (default: `None`): Username used for authentication + * `password` (default: `None`): Password used for authentication (`None` equals no authentication) diff --git a/rasa/core/lock_store.py b/rasa/core/lock_store.py index b7d495b3f1f5..e8baff134a2e 100644 --- a/rasa/core/lock_store.py +++ b/rasa/core/lock_store.py @@ -200,6 +200,7 @@ def __init__( host: Text = "localhost", port: int = 6379, db: int = 1, + username: Optional[Text] = None, password: Optional[Text] = None, use_ssl: bool = False, ssl_certfile: Optional[Text] = None, @@ -215,6 +216,8 @@ def __init__( port: The port of the redis server. db: The name of the database within Redis which should be used by Rasa Open Source. + username: The username which should be used for authentication with the + Redis database. password: The password which should be used for authentication with the Redis database. use_ssl: `True` if SSL should be used for the connection to Redis. @@ -232,6 +235,7 @@ def __init__( host=host, port=int(port), db=int(db), + username=username, password=password, ssl=use_ssl, ssl_certfile=ssl_certfile, diff --git a/rasa/core/tracker_store.py b/rasa/core/tracker_store.py index 35c1f1d5f7db..82870d1bfe3e 100644 --- a/rasa/core/tracker_store.py +++ b/rasa/core/tracker_store.py @@ -456,6 +456,7 @@ def __init__( host: Text = "localhost", port: int = 6379, db: int = 0, + username: Optional[Text] = None, password: Optional[Text] = None, event_broker: Optional[EventBroker] = None, record_exp: Optional[float] = None, @@ -473,6 +474,7 @@ def __init__( host=host, port=port, db=db, + username=username, password=password, ssl=use_ssl, ssl_keyfile=ssl_keyfile, diff --git a/tests/core/test_lock_store.py b/tests/core/test_lock_store.py index bba472696197..d90cd26a61b5 100644 --- a/tests/core/test_lock_store.py +++ b/tests/core/test_lock_store.py @@ -1,31 +1,30 @@ import asyncio import logging import sys +import time from pathlib import Path +from typing import Text +from unittest.mock import Mock, patch import numpy as np import pytest -import time - +import rasa.core.lock_store from _pytest.logging import LogCaptureFixture from _pytest.monkeypatch import MonkeyPatch -from unittest.mock import patch, Mock - from rasa.core.agent import Agent from rasa.core.channels import UserMessage from rasa.core.constants import DEFAULT_LOCK_LIFETIME -from rasa.shared.constants import INTENT_MESSAGE_PREFIX from rasa.core.lock import TicketLock -import rasa.core.lock_store from rasa.core.lock_store import ( + DEFAULT_REDIS_LOCK_STORE_KEY_PREFIX, InMemoryLockStore, LockError, LockStore, RedisLockStore, - DEFAULT_REDIS_LOCK_STORE_KEY_PREFIX, ) +from rasa.shared.constants import INTENT_MESSAGE_PREFIX from rasa.shared.exceptions import ConnectionException -from rasa.utils.endpoints import EndpointConfig +from rasa.utils.endpoints import EndpointConfig, read_endpoint_config class FakeRedisLockStore(RedisLockStore): @@ -384,3 +383,21 @@ async def test_redis_lock_store_with_valid_prefix(monkeypatch: MonkeyPatch): with pytest.raises(LockError): async with lock_store.lock("some sender"): pass + + +def test_create_lock_store_from_endpoint_config(endpoints_path: Text): + store = read_endpoint_config(endpoints_path, endpoint_type="lock_store") + tracker_store = RedisLockStore( + host="localhost", + port=6379, + db=0, + username="username", + password="password", + use_ssl=True, + ssl_keyfile="keyfile.key", + ssl_certfile="certfile.crt", + ssl_ca_certs="my-bundle.ca-bundle", + key_prefix="lock", + ) + + assert isinstance(tracker_store, type(LockStore.create(store))) diff --git a/tests/core/test_tracker_stores.py b/tests/core/test_tracker_stores.py index 6408200c044c..ea5bf5ef62dd 100644 --- a/tests/core/test_tracker_stores.py +++ b/tests/core/test_tracker_stores.py @@ -144,6 +144,7 @@ def test_tracker_store_endpoint_config_loading(endpoints_path: Text): "url": "localhost", "port": 6379, "db": 0, + "username": "username", "password": "password", "timeout": 30000, "use_ssl": True, @@ -163,6 +164,7 @@ def test_create_tracker_store_from_endpoint_config( host="localhost", port=6379, db=0, + username="username", password="password", record_exp=3000, use_ssl=True,