Adds use of OSMPOL_SQL_DATABASE_URI config param to connect to DB 54/6654/4
authorBenjamin Diaz <bdiaz@whitestack.com>
Mon, 8 Oct 2018 19:34:17 +0000 (16:34 -0300)
committerBenjamin Diaz <bdiaz@whitestack.com>
Sun, 14 Oct 2018 21:38:20 +0000 (18:38 -0300)
The OSMPOL_SQL_DATABASE_URI was not being used by POL to connect
to the database. There was a hardcoded sqlite database name.
This change should now provide capability to the user to use any
SQL database engine supported by the peewee ORM (mysql/mariadb,
postgres, sqlite).

Signed-off-by: Benjamin Diaz <bdiaz@whitestack.com>
Change-Id: Iff406862fb3dfeb4453fb3213c94db6d62385d96

docker/Dockerfile
osm_policy_module/core/config.py
osm_policy_module/core/database.py

index ab5b411..5953489 100644 (file)
@@ -44,7 +44,7 @@ ENV OSMPOL_DATABASE_DRIVER mongo
 ENV OSMPOL_DATABASE_HOST mongo
 ENV OSMPOL_DATABASE_PORT 27017
 
-ENV OSMPOL_SQL_DATABASE_URI sqlite:///mon_sqlite.db
+ENV OSMPOL_SQL_DATABASE_URI sqlite:///policy_module.db
 
 ENV OSMPOL_LOG_LEVEL INFO
 ENV OSMPOL_KAFKA_LOG_LEVEL WARN
index 84a1f57..94dec98 100644 (file)
@@ -65,7 +65,7 @@ class Config(object):
         CfgParam('OSMPOL_DATABASE_DRIVER', "mongo", six.text_type),
         CfgParam('OSMPOL_DATABASE_HOST', "mongo", six.text_type),
         CfgParam('OSMPOL_DATABASE_PORT', 27017, int),
-        CfgParam('OSMPOL_SQL_DATABASE_URI', "sqlite:///mon_sqlite.db", six.text_type),
+        CfgParam('OSMPOL_SQL_DATABASE_URI', "sqlite:///policy_module.db", six.text_type),
         CfgParam('OSMPOL_LOG_LEVEL', "INFO", six.text_type),
         CfgParam('OSMPOL_KAFKA_LOG_LEVEL', "WARN", six.text_type),
     ]
index 8ad19f2..e522b8d 100644 (file)
@@ -25,14 +25,14 @@ import datetime
 import logging
 
 from peewee import CharField, IntegerField, ForeignKeyField, Model, TextField, AutoField, DateTimeField
-from playhouse.sqlite_ext import SqliteExtDatabase
+from playhouse.db_url import connect
 
 from osm_policy_module.core.config import Config
 
 log = logging.getLogger(__name__)
 cfg = Config.instance()
 
-db = SqliteExtDatabase('policy_module.db')
+db = connect(cfg.OSMPOL_SQL_DATABASE_URI)
 
 
 class BaseModel(Model):