068831ccd8
With this change MuranoPackage becomes first-class DSL citizen. Packages have version, runtime_version (that is specified in Format attribute of the manifest file) and a list of classes. Previously engine used to have package loader which had most of "load" functionality and class loader that mostly acted as an adapter from package loader to interface that DSL used to get classes. Now class loader is gone and is replaced with package loader at the DSL level. Package loader is responsible for loading packages by either package or class name (as it was before) plus semantic_version spec (for example ">=1.2,<2.0"). Package loader can now keep track of several versions of the same package. Also packages now have requirements with version specs. All class names that are encountered in application code are looked up within requirements only. As a consequence packages that use other packages without referencing them explicitly will become broken. An exception from this rule is core library which is referenced automatically. Partially implements: blueprint murano-versioning Change-Id: I8789ba45b6210e71bf4977a766f82b66d2a2d270
112 lines
3.7 KiB
Python
112 lines
3.7 KiB
Python
# Copyright (c) 2014 Mirantis, Inc.
|
|
#
|
|
# 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.
|
|
|
|
import mock
|
|
|
|
from murano.dsl import murano_method
|
|
from murano.dsl import serializer
|
|
from murano.services import actions
|
|
from murano.tests.unit import base
|
|
|
|
|
|
class TestActionsSerializer(base.MuranoTestCase):
|
|
def setUp(self):
|
|
super(TestActionsSerializer, self).setUp()
|
|
|
|
def _get_mocked_obj(self):
|
|
method1 = mock.Mock()
|
|
method1.usage = murano_method.MethodUsages.Action
|
|
method1.name = 'method1'
|
|
method2 = mock.Mock()
|
|
method2.usage = murano_method.MethodUsages.Runtime
|
|
method2.name = 'method2'
|
|
method3 = mock.Mock()
|
|
method3.usage = murano_method.MethodUsages.Action
|
|
method3.name = 'method3'
|
|
|
|
obj2_type = mock.Mock()
|
|
obj2_type.declared_parents = []
|
|
obj2_type.methods = {'method3': method3}
|
|
obj2_type.type.find_methods = lambda p: filter(p, [method3])
|
|
|
|
obj = mock.Mock()
|
|
obj.object_id = 'id1'
|
|
obj.type.declared_parents = [obj2_type]
|
|
obj.type.methods = {'method1': method1, 'method2': method2}
|
|
obj.type.find_methods = lambda p: filter(
|
|
p, [method1, method2, method3])
|
|
|
|
return obj
|
|
|
|
def test_object_actions_serialization(self):
|
|
obj = self._get_mocked_obj()
|
|
|
|
obj_actions = serializer._serialize_available_action(obj, {})
|
|
|
|
expected_result = {'name': 'method1', 'enabled': True}
|
|
self.assertIn('id1_method1', obj_actions)
|
|
self.assertEqual(expected_result, obj_actions['id1_method1'])
|
|
|
|
def test_that_only_actions_are_serialized(self):
|
|
obj = self._get_mocked_obj()
|
|
obj_actions = serializer._serialize_available_action(obj, {})
|
|
self.assertNotIn('id1_method2', obj_actions)
|
|
|
|
def test_parent_actions_are_serialized(self):
|
|
obj = self._get_mocked_obj()
|
|
|
|
obj_actions = serializer._serialize_available_action(obj, {})
|
|
|
|
expected_result = {'name': 'method3', 'enabled': True}
|
|
self.assertIn('id1_method3', obj_actions)
|
|
self.assertEqual(expected_result, obj_actions['id1_method3'])
|
|
|
|
|
|
class TestActionFinder(base.MuranoTestCase):
|
|
def setUp(self):
|
|
super(TestActionFinder, self).setUp()
|
|
|
|
def test_simple_root_level_search(self):
|
|
model = {
|
|
'?': {
|
|
'id': 'id1',
|
|
'_actions': {
|
|
'ad_deploy': {
|
|
'enabled': True,
|
|
'name': 'deploy'
|
|
}
|
|
}
|
|
}
|
|
}
|
|
action = actions.ActionServices.find_action(model, 'ad_deploy')
|
|
self.assertEqual('deploy', action[1]['name'])
|
|
|
|
def test_recursive_action_search(self):
|
|
model = {
|
|
'?': {
|
|
'id': 'id1',
|
|
'_actions': {'ad_deploy': {'enabled': True, 'name': 'deploy'}}
|
|
},
|
|
'property': {
|
|
'?': {
|
|
'id': 'id2',
|
|
'_actions': {
|
|
'ad_scale': {'enabled': True, 'name': 'scale'}
|
|
}
|
|
},
|
|
}
|
|
}
|
|
action = actions.ActionServices.find_action(model, 'ad_scale')
|
|
self.assertEqual('scale', action[1]['name'])
|