Add cinder qos specs constraint

This patch implement qos specs constraint for cinder

blueprint update-cinder-resources

Change-Id: I2220bd9d544cf819b203f9574f144bf7de141ec4
This commit is contained in:
ricolin 2016-08-17 10:26:06 +08:00
parent 831e23d2af
commit 3fbc60e65a
3 changed files with 36 additions and 4 deletions

View File

@ -102,10 +102,7 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
vt_id = None
volume_type_list = self.client().volume_types.list()
for vt in volume_type_list:
if vt.name == volume_type:
vt_id = vt.id
break
if vt.id == volume_type:
if volume_type in [vt.name, vt.id]:
vt_id = vt.id
break
if vt_id is None:
@ -114,6 +111,13 @@ class CinderClientPlugin(client_plugin.ClientPlugin):
return vt_id
def get_qos_specs(self, qos_specs):
try:
qos = self.client().qos_specs.get(qos_specs)
except exceptions.NotFound:
qos = self.client().qos_specs.find(name=qos_specs)
return qos.id
def is_not_found(self, ex):
return isinstance(ex, exceptions.NotFound)
@ -191,3 +195,10 @@ class VolumeTypeConstraint(BaseCinderConstraint):
class VolumeBackupConstraint(BaseCinderConstraint):
resource_getter_name = 'get_volume_backup'
class QoSSpecsConstraint(BaseCinderConstraint):
expected_exceptions = (exceptions.NotFound,)
resource_getter_name = 'get_qos_specs'

View File

@ -14,6 +14,7 @@
import uuid
from cinderclient import exceptions as cinder_exc
from keystoneauth1 import exceptions as ks_exceptions
import mock
@ -135,6 +136,25 @@ class VolumeBackupConstraintTest(common.HeatTestCase):
self.assertFalse(self.constraint.validate("bar", self.ctx))
class QoSSpecsConstraintTest(common.HeatTestCase):
def setUp(self):
super(QoSSpecsConstraintTest, self).setUp()
self.ctx = utils.dummy_context()
self.mock_get_qos_specs = mock.Mock()
self.ctx.clients.client_plugin(
'cinder').get_qos_specs = self.mock_get_qos_specs
self.constraint = cinder.QoSSpecsConstraint()
def test_validation(self):
self.mock_get_qos_specs.return_value = None
self.assertTrue(self.constraint.validate("foo", self.ctx))
def test_validation_error(self):
self.mock_get_qos_specs.side_effect = cinder_exc.NotFound(404)
self.assertFalse(self.constraint.validate("bar", self.ctx))
class CinderClientAPIVersionTest(common.HeatTestCase):
def test_cinder_api_v3(self):

View File

@ -96,6 +96,7 @@ heat.constraints =
barbican.container = heat.engine.clients.os.barbican:ContainerConstraint
barbican.secret = heat.engine.clients.os.barbican:SecretConstraint
cinder.backup = heat.engine.clients.os.cinder:VolumeBackupConstraint
cinder.qos_specs = heat.engine.clients.os.cinder:QoSSpecsConstraint
cinder.snapshot = heat.engine.clients.os.cinder:VolumeSnapshotConstraint
cinder.volume = heat.engine.clients.os.cinder:VolumeConstraint
cinder.vtype = heat.engine.clients.os.cinder:VolumeTypeConstraint