CORD-2293 add mechanism for synchronizer to load wrappers
Change-Id: I6f4e3ffa2032873718695977adc5c5d7e26272af
(cherry picked from commit 26eea288a017d27e2757e336df19b6628a8316f7)
diff --git a/lib/xos-config/xosconfig/config.py b/lib/xos-config/xosconfig/config.py
index ff221a9..ba8e75d 100644
--- a/lib/xos-config/xosconfig/config.py
+++ b/lib/xos-config/xosconfig/config.py
@@ -136,7 +136,11 @@
try:
Config.validate_config_format(config_file, config_schema)
except Exception, e:
- raise Exception('[XOS-Config] The config format is wrong: %s' % e.msg)
+ try:
+ error_msg = e.msg
+ except AttributeError:
+ error_msg = str(e)
+ raise Exception('[XOS-Config] The config format is wrong: %s' % error_msg)
with open(config_file, 'r') as stream:
return yaml.safe_load(stream)
diff --git a/lib/xos-config/xosconfig/synchronizer-config-schema.yaml b/lib/xos-config/xosconfig/synchronizer-config-schema.yaml
index 252ccee..276268d 100644
--- a/lib/xos-config/xosconfig/synchronizer-config-schema.yaml
+++ b/lib/xos-config/xosconfig/synchronizer-config-schema.yaml
@@ -21,6 +21,10 @@
type: str
logging:
type: any
+ wrappers:
+ type: seq
+ sequence:
+ - type: str
blueprints:
type: seq
sequence:
diff --git a/xos/synchronizers/new_base/modelaccessor.py b/xos/synchronizers/new_base/modelaccessor.py
index 0500f88..48026e4 100644
--- a/xos/synchronizers/new_base/modelaccessor.py
+++ b/xos/synchronizers/new_base/modelaccessor.py
@@ -25,6 +25,7 @@
"""
import functools
+import importlib
import os
import signal
from xosconfig import Config
@@ -256,4 +257,9 @@
else:
raise Exception("Unknown accessor kind %s" % accessor_kind)
+ # now import any wrappers that the synchronizer needs to add to the ORM
+ if Config.get("wrappers"):
+ for wrapper_name in Config.get("wrappers"):
+ importlib.import_module(wrapper_name)
+
config_accessor()