summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-08-06 13:42:34 -0300
committerTomás Touceda <chiiph@leap.se>2013-08-06 13:42:34 -0300
commit6b3c65f158fcb63695568b3215f3f86503af8cb8 (patch)
tree38235dec90078ce444fd2268c1abf3f84be70959
parent695aee535cbfb3f956c52d8de6d61e217fb5bc44 (diff)
parente169ed03967fc8552c9300467bd99013ad7391df (diff)
Merge remote-tracking branch 'ivan/feature/check-if-schema-exists' into develop
-rw-r--r--changes/check-if-schema-exists1
-rw-r--r--src/leap/common/config/baseconfig.py15
2 files changed, 14 insertions, 2 deletions
diff --git a/changes/check-if-schema-exists b/changes/check-if-schema-exists
new file mode 100644
index 0000000..1459112
--- /dev/null
+++ b/changes/check-if-schema-exists
@@ -0,0 +1 @@
+ o Check if schema exists before load a config. Related to #3310.
diff --git a/src/leap/common/config/baseconfig.py b/src/leap/common/config/baseconfig.py
index 699d734..7bf08dd 100644
--- a/src/leap/common/config/baseconfig.py
+++ b/src/leap/common/config/baseconfig.py
@@ -26,7 +26,7 @@ import os
from abc import ABCMeta, abstractmethod
-from leap.common.check import leap_assert
+from leap.common.check import leap_assert, leap_check
from leap.common.files import mkdir_p
from leap.common.config.pluggableconfig import PluggableConfig
from leap.common.config.prefixers import get_platform_prefixer
@@ -34,6 +34,12 @@ from leap.common.config.prefixers import get_platform_prefixer
logger = logging.getLogger(__name__)
+class NonExistingSchema(Exception):
+ """
+ Raised if the schema needed to verify the config is None.
+ """
+
+
class BaseConfig:
"""
Abstract base class for any JSON based configuration.
@@ -112,6 +118,7 @@ class BaseConfig:
def load(self, path="", data=None, mtime=None, relative=True):
"""
Loads the configuration from disk.
+ It may raise NonExistingSchema exception.
:param path: if relative=True, this is a relative path
to configuration. The absolute path
@@ -131,8 +138,12 @@ class BaseConfig:
else:
config_path = path
+ schema = self._get_spec()
+ leap_check(schema is not None,
+ "There is no schema to use.", NonExistingSchema)
+
self._config_checker = PluggableConfig(format="json")
- self._config_checker.options = copy.deepcopy(self._get_spec())
+ self._config_checker.options = copy.deepcopy(schema)
try:
if data is None: