From 6064eea7c8785e64e9d80b8c90bc6e0772c46a94 Mon Sep 17 00:00:00 2001 From: Tetiana Lashchova Date: Wed, 11 Mar 2015 21:06:17 +0200 Subject: [PATCH] Add trove flavor custom constraint Change-Id: I08f866434beef9074dc554eb8693dd5ac421df6e --- heat/engine/clients/os/trove.py | 9 +++++++++ heat/engine/resources/openstack/trove/os_database.py | 5 ++++- heat/tests/common.py | 5 +++++ heat/tests/test_os_database.py | 1 + setup.cfg | 1 + 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/heat/engine/clients/os/trove.py b/heat/engine/clients/os/trove.py index debc1f220..2d654df7a 100644 --- a/heat/engine/clients/os/trove.py +++ b/heat/engine/clients/os/trove.py @@ -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) diff --git a/heat/engine/resources/openstack/trove/os_database.py b/heat/engine/resources/openstack/trove/os_database.py index a5a8278a4..ea1b33050 100644 --- a/heat/engine/resources/openstack/trove/os_database.py +++ b/heat/engine/resources/openstack/trove/os_database.py @@ -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, diff --git a/heat/tests/common.py b/heat/tests/common.py index 30efd437e..f27a4baf9 100644 --- a/heat/tests/common.py +++ b/heat/tests/common.py @@ -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 diff --git a/heat/tests/test_os_database.py b/heat/tests/test_os_database.py index 0c686152e..a6152477d 100644 --- a/heat/tests/test_os_database.py +++ b/heat/tests/test_os_database.py @@ -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 diff --git a/setup.cfg b/setup.cfg index 46b5091af..921e36d29 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 =