From 3fbc60e65a99626e118592cbfcdcc47362690b01 Mon Sep 17 00:00:00 2001 From: ricolin Date: Wed, 17 Aug 2016 10:26:06 +0800 Subject: [PATCH] Add cinder qos specs constraint This patch implement qos specs constraint for cinder blueprint update-cinder-resources Change-Id: I2220bd9d544cf819b203f9574f144bf7de141ec4 --- heat/engine/clients/os/cinder.py | 19 +++++++++++++++---- heat/tests/clients/test_cinder_client.py | 20 ++++++++++++++++++++ setup.cfg | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/heat/engine/clients/os/cinder.py b/heat/engine/clients/os/cinder.py index e7f831138e..ce11c2ab4f 100644 --- a/heat/engine/clients/os/cinder.py +++ b/heat/engine/clients/os/cinder.py @@ -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' diff --git a/heat/tests/clients/test_cinder_client.py b/heat/tests/clients/test_cinder_client.py index 83852154b3..bebfc574d8 100644 --- a/heat/tests/clients/test_cinder_client.py +++ b/heat/tests/clients/test_cinder_client.py @@ -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): diff --git a/setup.cfg b/setup.cfg index 1aa02f6f29..ed467d9eea 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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