summaryrefslogtreecommitdiffstats
path: root/compass-tasks/db/config_validation
diff options
context:
space:
mode:
authorHarry Huang <huangxiangyu5@huawei.com>2017-11-17 14:53:44 +0800
committerHarry Huang <huangxiangyu5@huawei.com>2017-12-21 16:36:30 +0800
commit8646b8d62cf4ca7b6bccae537a0c9e72ba45eab3 (patch)
tree73a9a983e0dd1423e9df928a78a5023a09d5a7f9 /compass-tasks/db/config_validation
parent6234176ae292a75dcda5520324cb7857d6105988 (diff)
Merge compass-tasks-osa and compass-tasks-k8s
JIRA: COMPASS-568 rename compass-tasks to compass-tasks-base. add both osa and k8s support in compass-tasks Change-Id: I438f5b17e509d4cb751ced0ffe640ec70899882f Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'compass-tasks/db/config_validation')
-rw-r--r--compass-tasks/db/config_validation/__init__.py0
-rw-r--r--compass-tasks/db/config_validation/default_validator.py131
-rw-r--r--compass-tasks/db/config_validation/extension/__init__.py0
-rw-r--r--compass-tasks/db/config_validation/extension/openstack.py18
4 files changed, 0 insertions, 149 deletions
diff --git a/compass-tasks/db/config_validation/__init__.py b/compass-tasks/db/config_validation/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/compass-tasks/db/config_validation/__init__.py
+++ /dev/null
diff --git a/compass-tasks/db/config_validation/default_validator.py b/compass-tasks/db/config_validation/default_validator.py
deleted file mode 100644
index 224447f..0000000
--- a/compass-tasks/db/config_validation/default_validator.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright 2014 Huawei Technologies Co. Ltd
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Default config validation function."""
-
-from sqlalchemy import or_
-
-from compass.db.models import OSConfigField
-from compass.db.models import OSConfigMetadata
-from compass.db import validator
-
-MAPPER = {
- "os_id": {
- "metaTable": OSConfigMetadata,
- "metaFieldTable": OSConfigField
- }
- # "adapter_id": {
- # "metaTable": AdapterConfigMetadata,
- # "metaFieldTable": AdapterConfigField
- # }
-}
-
-
-def validate_config(session, config, id_name, id_value, patch=True):
- """Validates config.
-
- Validates the given config value according to the config
- metadata of the asscoiated os_id or adapter_id. Returns
- a tuple (status, message).
- """
- if id_name not in MAPPER.keys():
- return (False, "Invalid id type %s" % id_name)
-
- meta_table = MAPPER[id_name]['metaTable']
- metafield_table = MAPPER[id_name]['metaFieldTable']
- with session.begin(subtransactions=True):
- name_col = name_col = getattr(meta_table, 'name')
- id_col = getattr(meta_table, id_name)
-
- return _validate_config_helper(session, config,
- name_col, id_col, id_value,
- meta_table, metafield_table,
- patch)
-
-
-def _validate_config_helper(session, config,
- name_col, id_col, id_value,
- meta_table, metafield_table, patch=True):
-
- with session.begin(subtransactions=True):
- for elem in config:
-
- obj = session.query(meta_table).filter(name_col == elem)\
- .filter(or_(id_col is None,
- id_col == id_value)).first()
-
- if not obj and "_type" not in config[elem]:
- return (False, "Invalid metadata '%s'!" % elem)
-
- if "_type" in config[elem]:
- # Metadata is a variable
- metadata_name = config[elem]['_type']
- obj = session.query(meta_table).filter_by(name=metadata_name)\
- .first()
-
- if not obj:
- err_msg = ("Invalid metatdata '%s' or missing '_type'"
- "to indicate this is a variable metatdata."
- % elem)
- return (False, err_msg)
-
- # TODO(Grace): validate metadata here
- del config[elem]['_type']
-
- fields = obj.fields
-
- if not fields:
- is_valid, message = _validate_config_helper(session,
- config[elem],
- name_col, id_col,
- id_value,
- meta_table,
- metafield_table,
- patch)
- if not is_valid:
- return (False, message)
-
- else:
- field_config = config[elem]
- for key in field_config:
- field = session.query(metafield_table)\
- .filter_by(field=key).first()
- if not field:
- # The field is not in schema
- return (False, "Invalid field '%s'!" % key)
-
- value = field_config[key]
- if field.is_required and value is None:
- # The value of this field is required
- # and cannot be none
- err = "The value of field '%s' cannot be null!" % key
- return (False, err)
-
- if field.validator:
- func = getattr(validator, field.validator)
- if not func or not func(value):
- err_msg = ("The value of the field '%s' is "
- "invalid format or None!" % key)
- return (False, err_msg)
-
- # This is a PUT request. We need to check presence of all
- # required fields.
- if not patch:
- for field in fields:
- name = field.field
- if field.is_required and name not in field_config:
- return (False,
- "Missing required field '%s'" % name)
-
- return (True, None)
diff --git a/compass-tasks/db/config_validation/extension/__init__.py b/compass-tasks/db/config_validation/extension/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/compass-tasks/db/config_validation/extension/__init__.py
+++ /dev/null
diff --git a/compass-tasks/db/config_validation/extension/openstack.py b/compass-tasks/db/config_validation/extension/openstack.py
deleted file mode 100644
index 6b3af69..0000000
--- a/compass-tasks/db/config_validation/extension/openstack.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright 2014 Huawei Technologies Co. Ltd
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-def validate_cluster_config():
- # TODO(xiaodong): Add openstack specific validation here.
- pass