Fixes congress integration

Fixes several bugs that were introduced during
recent dsl refactoring

Change-Id: Ida55ff4102e20a059e5f43311ea351264afbb5b4
Closes-Bug: #1613337
This commit is contained in:
Stan Lagun 2016-08-16 18:43:15 -07:00 committed by zhurong
parent 58d92abb16
commit 50a7aa4e0b
3 changed files with 21 additions and 17 deletions

View File

@ -225,7 +225,7 @@ class TaskExecutor(object):
if obj is not None: if obj is not None:
try: try:
self._validate_model(obj.object, pkg_loader) self._validate_model(obj.object, pkg_loader, executor)
except Exception as e: except Exception as e:
return self.exception_result(e, obj, '<validate>') return self.exception_result(e, obj, '<validate>')
@ -298,9 +298,10 @@ class TaskExecutor(object):
} }
} }
def _validate_model(self, obj, pkg_loader): def _validate_model(self, obj, pkg_loader, executor):
if CONF.engine.enable_model_policy_enforcer: if CONF.engine.enable_model_policy_enforcer:
if obj is not None: if obj is not None:
with helpers.with_object_store(executor.object_store):
self._model_policy_enforcer.modify(obj, pkg_loader) self._model_policy_enforcer.modify(obj, pkg_loader)
self._model_policy_enforcer.validate(obj.to_dictionary(), self._model_policy_enforcer.validate(obj.to_dictionary(),
pkg_loader) pkg_loader)

View File

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import semantic_version
import six import six
from murano.dsl import helpers from murano.dsl import helpers
@ -119,14 +118,13 @@ class CongressRulesManager(object):
obj_rule.obj_id, obj_rule.obj_id,
"services")) "services"))
self._rules.extend( self._rules.extend(
self._create_propety_rules(obj_rule.obj_id, obj)) self._create_property_rules(obj_rule.obj_id, obj))
cls = obj['?']['type'] cls = obj['?']['type']
if 'classVersion' in obj['?']: if 'classVersion' in obj['?']:
version_spec = helpers.parse_version_spec( version_spec = obj['?']['classVersion']
semantic_version.Version(obj['?']['classVersion']))
else: else:
version_spec = semantic_version.Spec('*') version_spec = '*'
types = self._get_parent_types( types = self._get_parent_types(
cls, self._package_loader, version_spec) cls, self._package_loader, version_spec)
self._rules.extend(self._create_parent_type_rules(obj['?']['id'], self._rules.extend(self._create_parent_type_rules(obj['?']['id'],
@ -145,7 +143,7 @@ class CongressRulesManager(object):
def _create_object_rule(self, app, owner_id): def _create_object_rule(self, app, owner_id):
return ObjectRule(app['?']['id'], owner_id, app['?']['type']) return ObjectRule(app['?']['id'], owner_id, app['?']['type'])
def _create_propety_rules(self, obj_id, obj, prefix=""): def _create_property_rules(self, obj_id, obj, prefix=""):
rules = [] rules = []
# Skip when inside properties of other object. # Skip when inside properties of other object.
@ -161,7 +159,7 @@ class CongressRulesManager(object):
if value is not None: if value is not None:
value = self._to_dict(value) value = self._to_dict(value)
if isinstance(value, dict): if isinstance(value, dict):
rules.extend(self._create_propety_rules( rules.extend(self._create_property_rules(
obj_id, value, prefix + key + ".")) obj_id, value, prefix + key + "."))
elif isinstance(value, list) or isinstance(obj, tuple): elif isinstance(value, list) or isinstance(obj, tuple):
for v in value: for v in value:
@ -191,6 +189,9 @@ class CongressRulesManager(object):
@staticmethod @staticmethod
def _get_parent_types(type_name, package_loader, version_spec): def _get_parent_types(type_name, package_loader, version_spec):
type_name, version_spec, _ = helpers.parse_type_string(
type_name, version_spec, None)
version_spec = helpers.parse_version_spec(version_spec)
result = {type_name} result = {type_name}
if package_loader: if package_loader:
pkg = package_loader.load_class_package(type_name, version_spec) pkg = package_loader.load_class_package(type_name, version_spec)
@ -211,7 +212,7 @@ class ObjectRule(object):
def __init__(self, obj_id, owner_id, type_name): def __init__(self, obj_id, owner_id, type_name):
self.obj_id = obj_id self.obj_id = obj_id
self.owner_id = owner_id self.owner_id = owner_id
self.type_name = type_name self.type_name = helpers.parse_type_string(type_name, None, None)[0]
def __str__(self): def __str__(self):
return 'murano:objects+("{0}", "{1}", "{2}")'.format(self.obj_id, return 'murano:objects+("{0}", "{1}", "{2}")'.format(self.obj_id,

View File

@ -52,7 +52,7 @@ class TestModelPolicyEnforcer(base.MuranoTestCase):
executor._model_policy_enforcer = mock.Mock() executor._model_policy_enforcer = mock.Mock()
CONF.engine.enable_model_policy_enforcer = False CONF.engine.enable_model_policy_enforcer = False
executor._validate_model(self.obj, self.package_loader) executor._validate_model(self.obj, self.package_loader, None)
self.assertFalse(executor._model_policy_enforcer.validate.called) self.assertFalse(executor._model_policy_enforcer.validate.called)
@ -61,7 +61,8 @@ class TestModelPolicyEnforcer(base.MuranoTestCase):
executor._model_policy_enforcer = mock.Mock() executor._model_policy_enforcer = mock.Mock()
CONF.engine.enable_model_policy_enforcer = True CONF.engine.enable_model_policy_enforcer = True
executor._validate_model(self.obj, self.package_loader) dsl_executor = mock.Mock()
executor._validate_model(self.obj, self.package_loader, dsl_executor)
executor._model_policy_enforcer \ executor._model_policy_enforcer \
.validate.assert_called_once_with(self.model_dict, .validate.assert_called_once_with(self.model_dict,
@ -121,13 +122,14 @@ class TestModelPolicyEnforcer(base.MuranoTestCase):
executor._model_policy_enforcer = mock.Mock() executor._model_policy_enforcer = mock.Mock()
CONF.engine.enable_model_policy_enforcer = True CONF.engine.enable_model_policy_enforcer = True
dsl_executor = mock.Mock()
executor._validate_model(None, self.package_loader) executor._validate_model(None, self.package_loader, dsl_executor)
self.assertFalse(executor._model_policy_enforcer.modify.called) self.assertFalse(executor._model_policy_enforcer.modify.called)
self.assertFalse(executor._model_policy_enforcer.validate.called) self.assertFalse(executor._model_policy_enforcer.validate.called)
executor._validate_model(self.obj, self.package_loader) executor._validate_model(self.obj, self.package_loader, dsl_executor)
self.assertTrue(executor._model_policy_enforcer.modify.called) self.assertTrue(executor._model_policy_enforcer.modify.called)
self.assertTrue(executor._model_policy_enforcer.validate.called) self.assertTrue(executor._model_policy_enforcer.validate.called)