From: Timo Tietavainen Date: Sat, 7 Dec 2019 18:09:31 +0000 (+0200) Subject: Take Hiredis into use in Redis backend X-Git-Tag: 1.0.2~1 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=cede9a3eacc358aeec806c71208540743889e303;p=ric-plt%2Fsdlpy.git Take Hiredis into use in Redis backend Add dependency to Hiredis package to take it into use in ricsdl Redis backend, because Hiredis provides better performance for Redis server response handling than pure build-in implementation of Redis client in python. Add new unit tests for configuration reading from environment variables. Signed-off-by: Timo Tietavainen Change-Id: I43227df9df4f3a84a2646d0aaa71552d0105c9d5 --- diff --git a/docs/release-notes.rst b/docs/release-notes.rst index 8576334..92a49a6 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -33,6 +33,11 @@ This document provides the release notes of the ricsdl library. Version history --------------- +[1.0.2] - 2019-12-18 + +* Take Hiredis package into use in Redis database backend. +* Add unit tests for configuration handling. + [1.0.1] - 2019-12-06 * Version bump. diff --git a/ricsdl-package/ricsdl/__init__.py b/ricsdl-package/ricsdl/__init__.py index d11eb4b..91eff80 100644 --- a/ricsdl-package/ricsdl/__init__.py +++ b/ricsdl-package/ricsdl/__init__.py @@ -31,7 +31,7 @@ from .exceptions import ( ) -__version__ = '1.0.1' +__version__ = '1.0.2' __all__ = [ diff --git a/ricsdl-package/setup.py b/ricsdl-package/setup.py index 5c0cedb..c04e8de 100644 --- a/ricsdl-package/setup.py +++ b/ricsdl-package/setup.py @@ -58,7 +58,8 @@ setup( keywords="RIC SDL", install_requires=[ 'setuptools', - 'redis' + 'redis', + 'hiredis' ], long_description=_long_descr(), long_description_content_type="text/markdown", diff --git a/ricsdl-package/tests/test_configuration.py b/ricsdl-package/tests/test_configuration.py new file mode 100644 index 0000000..7b17221 --- /dev/null +++ b/ricsdl-package/tests/test_configuration.py @@ -0,0 +1,71 @@ +# Copyright (c) 2019 AT&T Intellectual Property. +# Copyright (c) 2018-2019 Nokia. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This source code is part of the near-RT RIC (RAN Intelligent Controller) +# platform project (RICP). +# + + +import pytest +from ricsdl.configuration import _Configuration + + +@pytest.fixture() +def config_fixture(request, monkeypatch): + monkeypatch.setenv('DBAAS_SERVICE_HOST', '10.20.30.40') + monkeypatch.setenv('DBAAS_SERVICE_PORT', '10000') + monkeypatch.setenv('DBAAS_SERVICE_SENTINEL_PORT', '11000') + monkeypatch.setenv('DBAAS_MASTER_NAME', 'my-master') + request.cls.config = _Configuration() + request.cls.config._read_configuration() + + +@pytest.fixture +def config_missing_fixture(request, monkeypatch): + monkeypatch.delenv('DBAAS_SERVICE_HOST', raising=False) + monkeypatch.delenv('DBAAS_SERVICE_PORT', raising=False) + monkeypatch.delenv('DBAAS_SERVICE_SENTINEL_PORT', raising=False) + monkeypatch.delenv('DBAAS_MASTER_NAME', raising=False) + request.cls.config = _Configuration() + request.cls.config._read_configuration() + + +class TestConfiguration: + def test_get_params_function_returns_read_configuration(self, config_fixture): + expected_config = _Configuration.Params(db_host='10.20.30.40', db_port='10000', + db_sentinel_port='11000', + db_sentinel_master_name='my-master') + assert expected_config == self.config.get_params() + + def test_get_params_function_can_return_empty_configuration(self, config_missing_fixture): + expected_config = _Configuration.Params(db_host=None, db_port=None, + db_sentinel_port=None, + db_sentinel_master_name=None) + assert expected_config == self.config.get_params() + + def test_configuration_object_string_representation(self, config_fixture): + expected_config_info = {'DB host': '10.20.30.40', + 'DB port': '10000', + 'DB master sentinel': 'my-master', + 'DB sentinel port': '11000'} + assert str(self.config) == str(expected_config_info) + + def test_configuration_object_string_representation_if_no_config(self, config_missing_fixture): + expected_config_info = {'DB host': None, + 'DB port': None, + 'DB master sentinel': None, + 'DB sentinel port': None} + assert str(self.config) == str(expected_config_info)