Implement a fake SDL database backend
Implement a fake SDL database backend what can be used only for
local testing purposes, when SDL client does not need real DBAAS
database services. An SDL client can activate fake SDL database
backend usage when SDL instance is initiated with optional
'fake_db_backend' parameter:
sdl_instance = SyncStorage(fake_db_backend='dict')
Value 'dict' is only supported.
Change-Id: I2ee7474175d0923617e026c306ec684b117dab60
Signed-off-by: Timo Tietavainen <timo.tietavainen@nokia.com>
diff --git a/ricsdl-package/ricsdl/configuration.py b/ricsdl-package/ricsdl/configuration.py
index 91bcd98..892d607 100644
--- a/ricsdl-package/ricsdl/configuration.py
+++ b/ricsdl-package/ricsdl/configuration.py
@@ -21,16 +21,23 @@
"""The module provides implementation of Shared Data Layer (SDL) configurability."""
import os
+from enum import Enum
from collections import namedtuple
+class DbBackendType(Enum):
+ """Enumeration class of supported SDL database backend types."""
+ REDIS = 1
+ FAKE_DICT = 2
+
+
class _Configuration():
"""This class implements Shared Data Layer (SDL) configurability."""
Params = namedtuple('Params', ['db_host', 'db_port', 'db_sentinel_port',
- 'db_sentinel_master_name'])
+ 'db_sentinel_master_name', 'db_type'])
- def __init__(self):
- self.params = self._read_configuration()
+ def __init__(self, fake_db_backend):
+ self.params = self._read_configuration(fake_db_backend)
def __str__(self):
return str(
@@ -38,7 +45,8 @@
"DB host": self.params.db_host,
"DB port": self.params.db_port,
"DB master sentinel": self.params.db_sentinel_master_name,
- "DB sentinel port": self.params.db_sentinel_port
+ "DB sentinel port": self.params.db_sentinel_port,
+ "DB type": self.params.db_type.name,
}
)
@@ -47,8 +55,21 @@
return self.params
@classmethod
- def _read_configuration(cls):
+ def _read_configuration(cls, fake_db_backend):
+ backend_type = DbBackendType.REDIS
+ if fake_db_backend:
+ if fake_db_backend.lower() != 'dict':
+ msg = ("Configuration error: "
+ "SDL instance was initiated with wrong "
+ "'fake_db_backend' argument value: {}. "
+ "Value 'dict' is only supported.".
+ format(fake_db_backend))
+ raise ValueError(msg)
+
+ backend_type = DbBackendType.FAKE_DICT
+
return _Configuration.Params(db_host=os.getenv('DBAAS_SERVICE_HOST'),
db_port=os.getenv('DBAAS_SERVICE_PORT'),
db_sentinel_port=os.getenv('DBAAS_SERVICE_SENTINEL_PORT'),
- db_sentinel_master_name=os.getenv('DBAAS_MASTER_NAME'))
+ db_sentinel_master_name=os.getenv('DBAAS_MASTER_NAME'),
+ db_type=backend_type)