Basic test cases for policy types in engine

This commit is contained in:
tengqm 2015-03-14 10:03:33 +08:00
parent e9184b42aa
commit b4d4efbba0
3 changed files with 89 additions and 1 deletions

View File

@ -0,0 +1,66 @@
# 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.
from oslo_messaging.rpc import dispatcher as rpc
from senlin.common import exception
from senlin.engine import environment
from senlin.engine import service
from senlin.tests.common import base
from senlin.tests.common import utils
from senlin.tests import fakes
class PolicyTypeTest(base.SenlinTestCase):
def setUp(self):
super(PolicyTypeTest, self).setUp()
self.ctx = utils.dummy_context(tenant_id='policy_type_test_tenant')
self.eng = service.EngineService('host-a', 'topic-a')
self.eng.init_tgm()
environment.global_env().register_policy('TestPolicy',
fakes.TestPolicy)
def test_policy_type_list(self):
types = self.eng.policy_type_list(self.ctx)
self.assertIsInstance(types, list)
self.assertIn({'name': 'TestPolicy'}, types)
self.assertNotIn({'name': 'some-weird-stuff'}, types)
def test_policy_type_schema(self):
type_name = 'TestPolicy'
expected = {
'spec': {
'KEY1': {
'type': 'String',
'required': False,
'required': False,
'description': 'key1',
'default': 'default1',
},
'KEY2': {
'type': 'Integer',
'required': False,
'description': 'key2',
'default': 1,
},
}
}
schema = self.eng.policy_type_schema(self.ctx, type_name=type_name)
self.assertEqual(expected, schema)
def test_resource_schema_nonexist(self):
ex = self.assertRaises(rpc.ExpectedException,
self.eng.policy_type_schema,
self.ctx, type_name='Bogus')
self.assertEqual(exception.PolicyTypeNotFound, ex.exc_info[0])

View File

@ -82,7 +82,6 @@ class ProfileTypeTest(base.SenlinTestCase):
},
},
},
},
}

View File

@ -15,6 +15,7 @@ A module that contains various fake entities
'''
from senlin.common import schema
from senlin.policies import base as policy_base
from senlin.profiles import base as profile_base
@ -49,3 +50,25 @@ class TestProfile(profile_base.Profile):
def do_check(self, id):
return True
class TestPolicy(policy_base.Policy):
spec_schema = {
'KEY1': schema.String('key1', default='default1'),
'KEY2': schema.Integer('key2', default=1),
}
def __init__(self, type_name, name, **kwargs):
super(TestPolicy, self).__init__(type_name, name, **kwargs)
def attach(self, context, cluster, policy_data):
return
def detach(self, context, cluster, policy_data):
return
def pre_op(self, cluster_id, action, policy_data):
return policy_data
def post_op(self, cluster_id, action, policy_data):
return policy_data