Merge "Add Baymodel contraint to OS::Magnum::Bay"
This commit is contained in:
commit
cc38a1bbbc
@ -11,10 +11,12 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from magnumclient.openstack.common.apiclient import exceptions
|
from magnumclient.openstack.common.apiclient import exceptions as mc_exc
|
||||||
from magnumclient.v1 import client as magnum_client
|
from magnumclient.v1 import client as magnum_client
|
||||||
|
|
||||||
|
from heat.common import exception
|
||||||
from heat.engine.clients import client_plugin
|
from heat.engine.clients import client_plugin
|
||||||
|
from heat.engine import constraints
|
||||||
|
|
||||||
|
|
||||||
class MagnumClientPlugin(client_plugin.ClientPlugin):
|
class MagnumClientPlugin(client_plugin.ClientPlugin):
|
||||||
@ -34,10 +36,25 @@ class MagnumClientPlugin(client_plugin.ClientPlugin):
|
|||||||
return client
|
return client
|
||||||
|
|
||||||
def is_not_found(self, ex):
|
def is_not_found(self, ex):
|
||||||
return isinstance(ex, exceptions.NotFound)
|
return isinstance(ex, mc_exc.NotFound)
|
||||||
|
|
||||||
def is_over_limit(self, ex):
|
def is_over_limit(self, ex):
|
||||||
return isinstance(ex, exceptions.RequestEntityTooLarge)
|
return isinstance(ex, mc_exc.RequestEntityTooLarge)
|
||||||
|
|
||||||
def is_conflict(self, ex):
|
def is_conflict(self, ex):
|
||||||
return isinstance(ex, exceptions.Conflict)
|
return isinstance(ex, mc_exc.Conflict)
|
||||||
|
|
||||||
|
def get_baymodel(self, value):
|
||||||
|
try:
|
||||||
|
self.client().baymodels.get(value)
|
||||||
|
except mc_exc.NotFound:
|
||||||
|
raise exception.EntityNotFound(entity='BayModel',
|
||||||
|
name=value)
|
||||||
|
|
||||||
|
|
||||||
|
class BaymodelConstraint(constraints.BaseCustomConstraint):
|
||||||
|
|
||||||
|
expected_exceptions = (exception.EntityNotFound,)
|
||||||
|
|
||||||
|
def validate_with_client(self, client, value):
|
||||||
|
client.client_plugin('magnum').get_baymodel(value)
|
||||||
|
@ -45,7 +45,10 @@ class Bay(resource.Resource):
|
|||||||
),
|
),
|
||||||
BAYMODEL: properties.Schema(
|
BAYMODEL: properties.Schema(
|
||||||
properties.Schema.STRING,
|
properties.Schema.STRING,
|
||||||
_('The ID of the bay model.'),
|
_('The name or ID of the bay model.'),
|
||||||
|
constraints=[
|
||||||
|
constraints.CustomConstraint('magnum.baymodel')
|
||||||
|
],
|
||||||
required=True
|
required=True
|
||||||
),
|
),
|
||||||
NODE_COUNT: properties.Schema(
|
NODE_COUNT: properties.Schema(
|
||||||
@ -62,7 +65,7 @@ class Bay(resource.Resource):
|
|||||||
),
|
),
|
||||||
DISCOVERY_URL: properties.Schema(
|
DISCOVERY_URL: properties.Schema(
|
||||||
properties.Schema.STRING,
|
properties.Schema.STRING,
|
||||||
_('Url used for bay node discovery.')
|
_('Specifies a custom discovery url for node discovery.')
|
||||||
),
|
),
|
||||||
BAY_CREATE_TIMEOUT: properties.Schema(
|
BAY_CREATE_TIMEOUT: properties.Schema(
|
||||||
properties.Schema.INTEGER,
|
properties.Schema.INTEGER,
|
||||||
|
@ -16,8 +16,11 @@ import mock
|
|||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from magnumclient.openstack.common.apiclient import exceptions as mc_exc
|
||||||
|
|
||||||
from heat.common import exception
|
from heat.common import exception
|
||||||
from heat.common import template_format
|
from heat.common import template_format
|
||||||
|
from heat.engine.clients.os import magnum as mc
|
||||||
from heat.engine import resource
|
from heat.engine import resource
|
||||||
from heat.engine.resources.openstack.magnum import bay
|
from heat.engine.resources.openstack.magnum import bay
|
||||||
from heat.engine import scheduler
|
from heat.engine import scheduler
|
||||||
@ -54,6 +57,7 @@ class TestMagnumBay(common.HeatTestCase):
|
|||||||
self.rsrc_defn = resource_defns['test_bay']
|
self.rsrc_defn = resource_defns['test_bay']
|
||||||
self.client = mock.Mock()
|
self.client = mock.Mock()
|
||||||
self.patchobject(bay.Bay, 'client', return_value=self.client)
|
self.patchobject(bay.Bay, 'client', return_value=self.client)
|
||||||
|
self.patchobject(mc.MagnumClientPlugin, 'get_baymodel')
|
||||||
|
|
||||||
def _create_resource(self, name, snippet, stack, stat='CREATE_COMPLETE'):
|
def _create_resource(self, name, snippet, stack, stat='CREATE_COMPLETE'):
|
||||||
self.resource_id = '12345'
|
self.resource_id = '12345'
|
||||||
@ -144,3 +148,21 @@ class TestMagnumBay(common.HeatTestCase):
|
|||||||
mapping = bay.resource_mapping()
|
mapping = bay.resource_mapping()
|
||||||
self.assertEqual(1, len(mapping))
|
self.assertEqual(1, len(mapping))
|
||||||
self.assertEqual(mapping[RESOURCE_TYPE], bay.Bay)
|
self.assertEqual(mapping[RESOURCE_TYPE], bay.Bay)
|
||||||
|
|
||||||
|
|
||||||
|
class BaymodelConstraintTest(common.HeatTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(BaymodelConstraintTest, self).setUp()
|
||||||
|
self.ctx = utils.dummy_context()
|
||||||
|
self.mock_baymodel_get = mock.Mock()
|
||||||
|
self.ctx.clients.client_plugin(
|
||||||
|
'magnum').client().baymodels.get = self.mock_baymodel_get
|
||||||
|
self.constraint = mc.BaymodelConstraint()
|
||||||
|
|
||||||
|
def test_validate(self):
|
||||||
|
self.mock_baymodel_get.return_value = None
|
||||||
|
self.assertTrue(self.constraint.validate("mybaymodel", self.ctx))
|
||||||
|
|
||||||
|
def test_validate_fail(self):
|
||||||
|
self.mock_baymodel_get.side_effect = mc_exc.NotFound()
|
||||||
|
self.assertFalse(self.constraint.validate("badbaymodel", self.ctx))
|
||||||
|
@ -102,6 +102,7 @@ heat.constraints =
|
|||||||
keystone.group = heat.engine.clients.os.keystone:KeystoneGroupConstraint
|
keystone.group = heat.engine.clients.os.keystone:KeystoneGroupConstraint
|
||||||
keystone.service = heat.engine.clients.os.keystone:KeystoneServiceConstraint
|
keystone.service = heat.engine.clients.os.keystone:KeystoneServiceConstraint
|
||||||
keystone.user = heat.engine.clients.os.keystone:KeystoneUserConstraint
|
keystone.user = heat.engine.clients.os.keystone:KeystoneUserConstraint
|
||||||
|
magnum.baymodel = heat.engine.clients.os.magnum:BaymodelConstraint
|
||||||
manila.share_snapshot = heat.engine.clients.os.manila:ManilaShareSnapshotConstraint
|
manila.share_snapshot = heat.engine.clients.os.manila:ManilaShareSnapshotConstraint
|
||||||
manila.share_network = heat.engine.clients.os.manila:ManilaShareNetworkConstraint
|
manila.share_network = heat.engine.clients.os.manila:ManilaShareNetworkConstraint
|
||||||
manila.share_type = heat.engine.clients.os.manila:ManilaShareTypeConstraint
|
manila.share_type = heat.engine.clients.os.manila:ManilaShareTypeConstraint
|
||||||
|
Loading…
Reference in New Issue
Block a user