Skip to content

Commit

Permalink
Troubleshooting unit test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
NeonDaniel committed Oct 19, 2023
1 parent f55ca93 commit 0f21a20
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions chat_server/server_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os
from typing import Optional

from config import Configuration
from chat_server.server_utils.sftp_utils import init_sftp_connector
from utils.logging_utils import LOG
from utils.database_utils import DatabaseController

server_config_path = os.environ.get(
"CHATSERVER_CONFIG", "~/.local/share/neon/credentials.json"
Expand All @@ -40,17 +42,20 @@
)


def _init_db_controller(db_config: dict):
def _init_db_controller(db_config: dict) -> Optional[DatabaseController]:
from chat_server.server_utils.db_utils import DbUtils
from utils.database_utils import DatabaseController

# Determine configured database dialect
dialect = db_config.pop("dialect", "mongo")

# Create a database connection
db_controller = DatabaseController(config_data=db_config)
db_controller.attach_connector(dialect=dialect)
db_controller.connect()
try:
# Create a database connection
db_controller = DatabaseController(config_data=db_config)
db_controller.attach_connector(dialect=dialect)
db_controller.connect()
except Exception as e:
LOG.exception(f"DatabaseController init failed: {e}")
return None

# Initialize convenience class
DbUtils.init(db_controller)
Expand All @@ -68,14 +73,15 @@ def _init_db_controller(db_config: dict):
# ovos-config has built-in mechanisms for loading configuration files based
# on envvars, so the configuration structure is simplified
from ovos_config.config import Configuration
app_config = Configuration().get("CHAT_SERVER")
app_config = Configuration().get("CHAT_SERVER") or dict()
env_spec = os.environ.get("KLAT_ENV")
if env_spec and app_config.get(env_spec):
LOG.warning("Legacy configuration handling KLAT_ENV envvar")
app_config = app_config.get(env_spec)
db_controller = _init_db_controller(app_config.get("connection_properties",
Configuration().get(
"DATABASE_CONFIG")))
"DATABASE_CONFIG",
{})))

LOG.info(f"App config: {app_config}")

Expand Down

0 comments on commit 0f21a20

Please sign in to comment.