Merge "Add trove flavor custom constraint"

This commit is contained in:
Jenkins 2015-03-12 15:53:02 +00:00 committed by Gerrit Code Review
commit 55df1256e2
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 import exception
from heat.common.i18n import _ from heat.common.i18n import _
from heat.engine.clients import client_plugin from heat.engine.clients import client_plugin
from heat.engine import constraints
class TroveClientPlugin(client_plugin.ClientPlugin): class TroveClientPlugin(client_plugin.ClientPlugin):
@ -108,3 +109,11 @@ class TroveClientPlugin(client_plugin.ClientPlugin):
if flavor_id is None: if flavor_id is None:
raise exception.FlavorMissing(flavor_id=flavor) raise exception.FlavorMissing(flavor_id=flavor)
return flavor_id 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( FLAVOR: properties.Schema(
properties.Schema.STRING, properties.Schema.STRING,
_('Reference to a flavor for creating DB instance.'), _('Reference to a flavor for creating DB instance.'),
required=True required=True,
constraints=[
constraints.CustomConstraint('trove.flavor')
]
), ),
DATASTORE_TYPE: properties.Schema( DATASTORE_TYPE: properties.Schema(
properties.Schema.STRING, 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 keystone
from heat.engine.clients.os import neutron from heat.engine.clients.os import neutron
from heat.engine.clients.os import nova from heat.engine.clients.os import nova
from heat.engine.clients.os import trove
from heat.engine import environment from heat.engine import environment
from heat.engine import resources from heat.engine import resources
from heat.engine import scheduler from heat.engine import scheduler
@ -191,3 +192,7 @@ class HeatTestCase(testscenarios.WithScenarios,
def stub_PortConstraint_validate(self): def stub_PortConstraint_validate(self):
validate = self.patchobject(neutron.PortConstraint, 'validate') validate = self.patchobject(neutron.PortConstraint, 'validate')
validate.return_value = True 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.fc = self.m.CreateMockAnything()
self.nova = self.m.CreateMockAnything() self.nova = self.m.CreateMockAnything()
self.m.StubOutWithMock(trove.TroveClientPlugin, '_create') self.m.StubOutWithMock(trove.TroveClientPlugin, '_create')
self.stub_TroveFlavorConstraint_validate()
def _setup_test_clouddbinstance(self, name, t): def _setup_test_clouddbinstance(self, name, t):
stack_name = '%s_stack' % name stack_name = '%s_stack' % name

View File

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