validate static configuration
Check for validity of configuration with static yaml schema Change-Id: I2241076d11d25730d08decee4a5fc049133984fc
This commit is contained in:
parent
a1d829009d
commit
ea33464513
@ -145,3 +145,4 @@ python-zaqarclient==1.2.0
|
|||||||
tooz==1.58.0
|
tooz==1.58.0
|
||||||
zake==0.1.6
|
zake==0.1.6
|
||||||
psutil==5.4.3
|
psutil==5.4.3
|
||||||
|
jsonschema==2.6.0
|
||||||
|
@ -53,4 +53,5 @@ futures>=3.0.0;python_version=='2.7' or python_version=='2.6' # BSD
|
|||||||
pytz>=2013.6 # MIT
|
pytz>=2013.6 # MIT
|
||||||
tenacity>=4.9.0
|
tenacity>=4.9.0
|
||||||
tooz>=1.58.0 # Apache-2.0
|
tooz>=1.58.0 # Apache-2.0
|
||||||
psutil>=5.4.3 # BSD
|
psutil>=5.4.3 # BSD
|
||||||
|
jsonschema>=2.6.0 # MIT
|
||||||
|
@ -45,6 +45,75 @@ OPTS = [
|
|||||||
help='static data sources configuration directory')]
|
help='static data sources configuration directory')]
|
||||||
|
|
||||||
|
|
||||||
|
STATIC_SCHEMA = {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["definitions"],
|
||||||
|
"properties": {
|
||||||
|
"metadata": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["name"],
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"definitions": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["entities", "relationships"],
|
||||||
|
"properties": {
|
||||||
|
"entities": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["static_id"],
|
||||||
|
"properties": {
|
||||||
|
"static_id": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"relationships": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"required": ["source", "target",
|
||||||
|
"relationship_type"],
|
||||||
|
"properties": {
|
||||||
|
"source": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"target": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
"relationship_type": {
|
||||||
|
"type": "string",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class StaticFields(object):
|
class StaticFields(object):
|
||||||
"""yaml fields for static definitions"""
|
"""yaml fields for static definitions"""
|
||||||
METADATA = 'metadata'
|
METADATA = 'metadata'
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
from jsonschema import validate
|
||||||
from six.moves import reduce
|
from six.moves import reduce
|
||||||
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
@ -21,6 +22,7 @@ from vitrage.common.constants import DatasourceProperties as DSProps
|
|||||||
from vitrage.common.constants import GraphAction
|
from vitrage.common.constants import GraphAction
|
||||||
from vitrage.datasources.driver_base import DriverBase
|
from vitrage.datasources.driver_base import DriverBase
|
||||||
from vitrage.datasources.static import STATIC_DATASOURCE
|
from vitrage.datasources.static import STATIC_DATASOURCE
|
||||||
|
from vitrage.datasources.static import STATIC_SCHEMA
|
||||||
from vitrage.datasources.static import StaticFields
|
from vitrage.datasources.static import StaticFields
|
||||||
from vitrage.utils import file as file_utils
|
from vitrage.utils import file as file_utils
|
||||||
|
|
||||||
@ -39,10 +41,15 @@ class StaticDriver(DriverBase):
|
|||||||
self.entities_cache = []
|
self.entities_cache = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _is_valid_config(config):
|
def _is_valid_config(config, path):
|
||||||
"""check for validity of configuration"""
|
"""check for validity of configuration"""
|
||||||
# TODO(yujunz) check with yaml schema or reuse template validation
|
try:
|
||||||
return StaticFields.DEFINITIONS in config
|
validate(config, STATIC_SCHEMA)
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
msg = "Invalid config file: %s" % path
|
||||||
|
LOG.exception(msg)
|
||||||
|
return False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_event_types():
|
def get_event_types():
|
||||||
@ -103,9 +110,7 @@ class StaticDriver(DriverBase):
|
|||||||
def _get_entities_from_file(cls, path):
|
def _get_entities_from_file(cls, path):
|
||||||
config = file_utils.load_yaml_file(path)
|
config = file_utils.load_yaml_file(path)
|
||||||
|
|
||||||
if not cls._is_valid_config(config):
|
if not cls._is_valid_config(config, path):
|
||||||
LOG.warning("Skipped invalid config (possible obsoleted): {}"
|
|
||||||
.format(path))
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
definitions = config[StaticFields.DEFINITIONS]
|
definitions = config[StaticFields.DEFINITIONS]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user