Merge "Support Cinder scheduler hints"
This commit is contained in:
commit
5d48414711
@ -461,11 +461,11 @@ class CinderVolume(Volume):
|
||||
PROPERTIES = (
|
||||
AVAILABILITY_ZONE, SIZE, SNAPSHOT_ID, BACKUP_ID, NAME,
|
||||
DESCRIPTION, VOLUME_TYPE, METADATA, IMAGE_REF, IMAGE,
|
||||
SOURCE_VOLID,
|
||||
SOURCE_VOLID, CINDER_SCHEDULER_HINTS,
|
||||
) = (
|
||||
'availability_zone', 'size', 'snapshot_id', 'backup_id', 'name',
|
||||
'description', 'volume_type', 'metadata', 'imageRef', 'image',
|
||||
'source_volid',
|
||||
'source_volid', 'scheduler_hints',
|
||||
)
|
||||
|
||||
ATTRIBUTES = (
|
||||
@ -541,6 +541,12 @@ class CinderVolume(Volume):
|
||||
properties.Schema.STRING,
|
||||
_('If specified, the volume to use as source.')
|
||||
),
|
||||
CINDER_SCHEDULER_HINTS: properties.Schema(
|
||||
properties.Schema.MAP,
|
||||
_('Arbitrary key-value pairs specified by the client to help '
|
||||
'the Cinder scheduler creating a volume.'),
|
||||
support_status=support.SupportStatus(version='2015.1')
|
||||
),
|
||||
}
|
||||
|
||||
attributes_schema = {
|
||||
@ -611,9 +617,10 @@ class CinderVolume(Volume):
|
||||
arguments['imageRef'] = self.properties[self.IMAGE_REF]
|
||||
|
||||
optionals = (self.SNAPSHOT_ID, self.VOLUME_TYPE, self.SOURCE_VOLID,
|
||||
self.METADATA)
|
||||
self.METADATA, self.CINDER_SCHEDULER_HINTS)
|
||||
arguments.update((prop, self.properties[prop]) for prop in optionals
|
||||
if self.properties[prop])
|
||||
|
||||
return arguments
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
@ -731,6 +738,19 @@ class CinderVolume(Volume):
|
||||
def check_delete_snapshot_complete(self, delete_task):
|
||||
return delete_task.step()
|
||||
|
||||
def validate(self):
|
||||
"""Validate provided params."""
|
||||
res = super(CinderVolume, self).validate()
|
||||
if res is not None:
|
||||
return res
|
||||
|
||||
# Scheduler hints are only supported from Cinder API v2
|
||||
if self.properties.get(self.CINDER_SCHEDULER_HINTS) \
|
||||
and self.cinder().volume_api_version == 1:
|
||||
raise exception.StackValidationFailed(
|
||||
message=_('Scheduler hints are not supported by the current '
|
||||
'volume API.'))
|
||||
|
||||
|
||||
class CinderVolumeAttachment(VolumeAttachment):
|
||||
|
||||
|
@ -89,6 +89,13 @@ resources:
|
||||
properties:
|
||||
availability_zone: nova
|
||||
size: 2
|
||||
volume3:
|
||||
type: OS::Cinder::Volume
|
||||
properties:
|
||||
availability_zone: nova
|
||||
size: 1
|
||||
name: test_name
|
||||
scheduler_hints: {"hint1": "good_advice"}
|
||||
attachment:
|
||||
type: OS::Cinder::VolumeAttachment
|
||||
properties:
|
||||
@ -1389,6 +1396,39 @@ class CinderVolumeTest(BaseVolumeTest):
|
||||
self.assertEqual((rsrc.UPDATE, rsrc.COMPLETE), rsrc.state)
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_cinder_create_with_scheduler_hints(self):
|
||||
fv = FakeVolume('creating', 'available')
|
||||
|
||||
cinder.CinderClientPlugin._create().AndReturn(self.cinder_fc)
|
||||
self.cinder_fc.volumes.create(
|
||||
size=1, name='test_name', description=None,
|
||||
availability_zone='nova',
|
||||
scheduler_hints={'hint1': 'good_advice'}).AndReturn(fv)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack_name = 'test_volume_scheduler_hints_stack'
|
||||
stack = utils.parse_stack(self.t, stack_name=stack_name)
|
||||
self.create_volume(self.t, stack, 'volume3')
|
||||
self.assertEqual('available', fv.status)
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_cinder_create_with_scheduler_hints_and_cinder_api_v1(self):
|
||||
cinder.CinderClientPlugin._create().AndReturn(self.cinder_fc)
|
||||
self.cinder_fc.volume_api_version = 1
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
stack_name = 'test_volume_scheduler_hints_api_v1_stack'
|
||||
stack = utils.parse_stack(self.t, stack_name=stack_name)
|
||||
ex = self.assertRaises(exception.StackValidationFailed,
|
||||
self.create_volume, self.t, stack, 'volume3')
|
||||
self.assertIn('Scheduler hints are not supported by the current '
|
||||
'volume API.', six.text_type(ex))
|
||||
|
||||
self.m.VerifyAll()
|
||||
|
||||
|
||||
class FakeVolume(object):
|
||||
status = 'attaching'
|
||||
|
Loading…
x
Reference in New Issue
Block a user