Merge "Add constraint for cluster template"
This commit is contained in:
commit
e64e0064ee
@ -45,13 +45,30 @@ class MagnumClientPlugin(client_plugin.ClientPlugin):
|
||||
def is_conflict(self, ex):
|
||||
return isinstance(ex, mc_exc.Conflict)
|
||||
|
||||
def get_baymodel(self, value):
|
||||
def _get_rsrc_name_or_id(self, value, entity, entity_msg):
|
||||
entity_client = getattr(self.client(), entity)
|
||||
try:
|
||||
self.client().baymodels.get(value)
|
||||
return entity_client.get(value).uuid
|
||||
except mc_exc.NotFound:
|
||||
raise exception.EntityNotFound(entity='BayModel',
|
||||
# Magnum cli will find the value either is name or id,
|
||||
# so no need to call list() here.
|
||||
raise exception.EntityNotFound(entity=entity_msg,
|
||||
name=value)
|
||||
|
||||
def get_baymodel(self, value):
|
||||
return self._get_rsrc_name_or_id(value, entity='baymodels',
|
||||
entity_msg='BayModel')
|
||||
|
||||
def get_cluster_template(self, value):
|
||||
return self._get_rsrc_name_or_id(value, entity='cluster_templates',
|
||||
entity_msg='ClusterTemplate')
|
||||
|
||||
|
||||
class ClusterTemplateConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
resource_client_name = CLIENT_NAME
|
||||
resource_getter_name = 'get_cluster_template'
|
||||
|
||||
|
||||
class BaymodelConstraint(constraints.BaseCustomConstraint):
|
||||
|
||||
|
@ -11,6 +11,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from magnumclient import exceptions as mc_exc
|
||||
import mock
|
||||
|
||||
from heat.engine.clients.os import magnum as mc
|
||||
from heat.tests import common
|
||||
from heat.tests import utils
|
||||
|
||||
@ -23,3 +27,50 @@ class MagnumClientPluginTest(common.HeatTestCase):
|
||||
client = plugin.client()
|
||||
self.assertEqual('http://server.test:5000/v3',
|
||||
client.cluster_templates.api.session.auth.endpoint)
|
||||
|
||||
|
||||
class fake_cluster_template(object):
|
||||
def __init__(self, id=None, name=None):
|
||||
self.uuid = id
|
||||
self.name = name
|
||||
|
||||
|
||||
class ClusterTemplateConstraintTest(common.HeatTestCase):
|
||||
def setUp(self):
|
||||
super(ClusterTemplateConstraintTest, self).setUp()
|
||||
self.ctx = utils.dummy_context()
|
||||
self.mock_cluster_template_get = mock.Mock()
|
||||
self.ctx.clients.client_plugin(
|
||||
'magnum').client().cluster_templates.get = \
|
||||
self.mock_cluster_template_get
|
||||
self.constraint = mc.ClusterTemplateConstraint()
|
||||
|
||||
def test_validate(self):
|
||||
self.mock_cluster_template_get.return_value = fake_cluster_template(
|
||||
id='my_cluster_template')
|
||||
self.assertTrue(self.constraint.validate(
|
||||
'my_cluster_template', self.ctx))
|
||||
|
||||
def test_validate_fail(self):
|
||||
self.mock_cluster_template_get.side_effect = mc_exc.NotFound()
|
||||
self.assertFalse(self.constraint.validate(
|
||||
"bad_cluster_template", self.ctx))
|
||||
|
||||
|
||||
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 = fake_cluster_template(
|
||||
id='badbaymodel')
|
||||
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))
|
||||
|
@ -12,7 +12,6 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
from magnumclient import exceptions as mc_exc
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
import six
|
||||
@ -156,21 +155,3 @@ class TestMagnumBay(common.HeatTestCase):
|
||||
self.client.bays.get.return_value = value
|
||||
reality = b.get_live_state(b.properties)
|
||||
self.assertEqual({'node_count': 5, 'master_count': 1}, reality)
|
||||
|
||||
|
||||
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))
|
||||
|
@ -111,6 +111,7 @@ heat.constraints =
|
||||
keystone.service = heat.engine.clients.os.keystone.keystone_constraints:KeystoneServiceConstraint
|
||||
keystone.user = heat.engine.clients.os.keystone.keystone_constraints:KeystoneUserConstraint
|
||||
magnum.baymodel = heat.engine.clients.os.magnum:BaymodelConstraint
|
||||
magnum.cluster_template = heat.engine.clients.os.magnum:ClusterTemplateConstraint
|
||||
manila.share_network = heat.engine.clients.os.manila:ManilaShareNetworkConstraint
|
||||
manila.share_snapshot = heat.engine.clients.os.manila:ManilaShareSnapshotConstraint
|
||||
manila.share_type = heat.engine.clients.os.manila:ManilaShareTypeConstraint
|
||||
|
Loading…
x
Reference in New Issue
Block a user