Add trove flavor custom constraint

Change-Id: I08f866434beef9074dc554eb8693dd5ac421df6e
changes/67/163567/2
Tetiana Lashchova 2015-03-11 21:06:17 +02:00
parent f2a1edd3b9
commit 6064eea7c8
5 changed files with 20 additions and 1 deletions

View File

@ -17,6 +17,7 @@ from troveclient.openstack.common.apiclient import exceptions
from heat.common import exception
from heat.common.i18n import _
from heat.engine.clients import client_plugin
from heat.engine import constraints
class TroveClientPlugin(client_plugin.ClientPlugin):
@ -108,3 +109,11 @@ class TroveClientPlugin(client_plugin.ClientPlugin):
if flavor_id is None:
raise exception.FlavorMissing(flavor_id=flavor)
return flavor_id
class FlavorConstraint(constraints.BaseCustomConstraint):
expected_exceptions = (exception.FlavorMissing,)
def validate_with_client(self, client, flavor):
client.client_plugin('trove').get_flavor_id(flavor)

View File

@ -92,7 +92,10 @@ class OSDBInstance(resource.Resource):
FLAVOR: properties.Schema(
properties.Schema.STRING,
_('Reference to a flavor for creating DB instance.'),
required=True
required=True,
constraints=[
constraints.CustomConstraint('trove.flavor')
]
),
DATASTORE_TYPE: properties.Schema(
properties.Schema.STRING,

View File

@ -31,6 +31,7 @@ from heat.engine.clients.os import glance
from heat.engine.clients.os import keystone
from heat.engine.clients.os import neutron
from heat.engine.clients.os import nova
from heat.engine.clients.os import trove
from heat.engine import environment
from heat.engine import resources
from heat.engine import scheduler
@ -191,3 +192,7 @@ class HeatTestCase(testscenarios.WithScenarios,
def stub_PortConstraint_validate(self):
validate = self.patchobject(neutron.PortConstraint, 'validate')
validate.return_value = True
def stub_TroveFlavorConstraint_validate(self):
validate = self.patchobject(trove.FlavorConstraint, 'validate')
validate.return_value = True

View File

@ -102,6 +102,7 @@ class OSDBInstanceTest(common.HeatTestCase):
self.fc = self.m.CreateMockAnything()
self.nova = self.m.CreateMockAnything()
self.m.StubOutWithMock(trove.TroveClientPlugin, '_create')
self.stub_TroveFlavorConstraint_validate()
def _setup_test_clouddbinstance(self, name, t):
stack_name = '%s_stack' % name

View File

@ -71,6 +71,7 @@ heat.constraints =
cinder.snapshot = heat.engine.clients.os.cinder:VolumeSnapshotConstraint
cinder.vtype = heat.engine.clients.os.cinder:VolumeTypeConstraint
sahara.image = heat.engine.clients.os.sahara:ImageConstraint
trove.flavor = heat.engine.clients.os.trove:FlavorConstraint
heat.stack_lifecycle_plugins =