Add profile constraint to senlin_plugin

Add profile constraint to senlin_plugin

blueprint senlin-resources
Change-Id: I6f8cd4bdd21027298a38d3364baebce26400d22c
This commit is contained in:
Ethan Lynn 2015-11-02 15:38:15 +08:00
parent fba9708f5b
commit 6e0a9f9998
3 changed files with 33 additions and 2 deletions

View File

@ -12,6 +12,7 @@
# under the License.
from heat.engine.clients import client_plugin
from heat.engine import constraints
from senlinclient import client
from senlinclient.common import exc
@ -33,3 +34,11 @@ class SenlinClientPlugin(client_plugin.ClientPlugin):
def is_not_found(self, ex):
return isinstance(ex, exc.HTTPNotFound)
class ProfileConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exc.HTTPNotFound,)
def validate_with_client(self, client, profile):
client.client('senlin').get_profile(profile)

View File

@ -11,17 +11,38 @@
# License for the specific language governing permissions and limitations
# under the License.
from testtools import testcase
import mock
from heat.engine.clients.os import senlin as senlin_plugin
from heat.tests import common
from heat.tests import utils
from senlinclient.common import exc
class SenlinClientPluginTests(common.HeatTestCase):
@testcase.skip('skipped until bug #1519185 is fixed!')
def test_cluster_get(self):
context = utils.dummy_context()
plugin = context.clients.client_plugin('senlin')
client = plugin.client()
self.assertIsNotNone(client.clusters)
class ProfileConstraintTest(common.HeatTestCase):
def setUp(self):
super(ProfileConstraintTest, self).setUp()
self.senlin_client = mock.MagicMock()
self.ctx = utils.dummy_context()
self.mock_get_profile = mock.Mock()
self.ctx.clients.client(
'senlin').get_profile = self.mock_get_profile
self.constraint = senlin_plugin.ProfileConstraint()
def test_validate_true(self):
self.mock_get_profile.return_value = None
self.assertTrue(self.constraint.validate("PROFILE_ID", self.ctx))
def test_validate_false(self):
self.mock_get_profile.side_effect = exc.HTTPNotFound
self.assertFalse(self.constraint.validate("PROFILE_ID", self.ctx))

View File

@ -114,6 +114,7 @@ heat.constraints =
cron_expression = heat.engine.constraint.common_constraints:CRONExpressionConstraint
monasca.notification = heat.engine.clients.os.monasca:MonascaNotificationConstraint
sahara.plugin = heat.engine.clients.os.sahara:PluginConstraint
senlin.profile = heat.engine.clients.os.senlin:ProfileConstraint
heat.stack_lifecycle_plugins =