Merge "Be safe with getting attachment"
This commit is contained in:
commit
ebe3234d9e
|
@ -1879,6 +1879,16 @@ class VolumeTestCase(BaseVolumeTestCase):
|
|||
volume_id,
|
||||
attachment_id)
|
||||
|
||||
def test_detach_no_attachments(self):
|
||||
volume = tests_utils.create_volume(self.context,
|
||||
admin_metadata={'readonly': 'True'},
|
||||
multiattach=False,
|
||||
**self.volume_params)
|
||||
self.assertRaises(exception.InvalidVolume,
|
||||
self.volume.detach_volume,
|
||||
self.context,
|
||||
volume['id'])
|
||||
|
||||
def test_run_attach_detach_volume_for_instance_no_attachment_id(self):
|
||||
"""Make sure volume can be attached and detached from instance."""
|
||||
mountpoint = "/dev/sdf"
|
||||
|
|
|
@ -854,8 +854,14 @@ class VolumeManager(manager.SchedulerDependentManager):
|
|||
" this volume") % {'id': volume_id}
|
||||
LOG.error(msg)
|
||||
raise exception.InvalidVolume(reason=msg)
|
||||
else:
|
||||
elif len(attachments) == 1:
|
||||
attachment = attachments[0]
|
||||
else:
|
||||
# there aren't any attachments for this volume.
|
||||
msg = _("Volume %(id)s doesn't have any attachments "
|
||||
"to detach") % {'id': volume_id}
|
||||
LOG.error(msg)
|
||||
raise exception.InvalidVolume(reason=msg)
|
||||
|
||||
volume = self.db.volume_get(context, volume_id)
|
||||
self._notify_about_volume_usage(context, volume, "detach.start")
|
||||
|
|
Loading…
Reference in New Issue