Merge "Add host check while create snapshot"
This commit is contained in:
commit
808862bf37
@ -108,7 +108,7 @@ class SnapshotApiTest(test.TestCase):
|
|||||||
self.stubs.Set(volume.api.API,
|
self.stubs.Set(volume.api.API,
|
||||||
"create_snapshot_force",
|
"create_snapshot_force",
|
||||||
stub_snapshot_create)
|
stub_snapshot_create)
|
||||||
self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
|
self.mock_object(volume.api.API, 'get', stubs.stub_volume_api_get)
|
||||||
snapshot = {"volume_id": fake.VOLUME_ID,
|
snapshot = {"volume_id": fake.VOLUME_ID,
|
||||||
"force": force_param,
|
"force": force_param,
|
||||||
"display_name": "Snapshot Test Name",
|
"display_name": "Snapshot Test Name",
|
||||||
@ -128,7 +128,7 @@ class SnapshotApiTest(test.TestCase):
|
|||||||
self.stubs.Set(volume.api.API,
|
self.stubs.Set(volume.api.API,
|
||||||
"create_snapshot_force",
|
"create_snapshot_force",
|
||||||
stub_snapshot_create)
|
stub_snapshot_create)
|
||||||
self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
|
self.mock_object(volume.api.API, 'get', stubs.stub_volume_api_get)
|
||||||
snapshot = {"volume_id": fake.VOLUME_ID,
|
snapshot = {"volume_id": fake.VOLUME_ID,
|
||||||
"force": force_param,
|
"force": force_param,
|
||||||
"display_name": "Snapshot Test Name",
|
"display_name": "Snapshot Test Name",
|
||||||
@ -145,7 +145,7 @@ class SnapshotApiTest(test.TestCase):
|
|||||||
self.stubs.Set(volume.api.API,
|
self.stubs.Set(volume.api.API,
|
||||||
"create_snapshot_force",
|
"create_snapshot_force",
|
||||||
stub_snapshot_create)
|
stub_snapshot_create)
|
||||||
self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
|
self.mock_object(volume.api.API, 'get', stubs.stub_volume_api_get)
|
||||||
snapshot = {"volume_id": fake.SNAPSHOT_ID,
|
snapshot = {"volume_id": fake.SNAPSHOT_ID,
|
||||||
"force": "**&&^^%%$$##@@",
|
"force": "**&&^^%%$$##@@",
|
||||||
"display_name": "Snapshot Test Name",
|
"display_name": "Snapshot Test Name",
|
||||||
|
@ -3120,6 +3120,19 @@ class VolumeTestCase(base.BaseVolumeTestCase):
|
|||||||
'fake_description',
|
'fake_description',
|
||||||
fake.CONSISTENCY_GROUP_ID)
|
fake.CONSISTENCY_GROUP_ID)
|
||||||
|
|
||||||
|
def test_create_snapshot_failed_host_is_None(self):
|
||||||
|
"""Test exception handling when create snapshot and host is None."""
|
||||||
|
test_volume = tests_utils.create_volume(
|
||||||
|
self.context,
|
||||||
|
host=None)
|
||||||
|
volume_api = cinder.volume.api.API()
|
||||||
|
self.assertRaises(exception.InvalidVolume,
|
||||||
|
volume_api.create_snapshot,
|
||||||
|
self.context,
|
||||||
|
test_volume,
|
||||||
|
'fake_name',
|
||||||
|
'fake_description')
|
||||||
|
|
||||||
def test_cannot_delete_volume_in_use(self):
|
def test_cannot_delete_volume_in_use(self):
|
||||||
"""Test volume can't be deleted in in-use status."""
|
"""Test volume can't be deleted in in-use status."""
|
||||||
self._test_cannot_delete_volume('in-use')
|
self._test_cannot_delete_volume('in-use')
|
||||||
|
@ -772,6 +772,11 @@ class API(base.Base):
|
|||||||
group_snapshot_id=None):
|
group_snapshot_id=None):
|
||||||
check_policy(context, 'create_snapshot', volume)
|
check_policy(context, 'create_snapshot', volume)
|
||||||
|
|
||||||
|
if not volume.host:
|
||||||
|
msg = _("The snapshot cannot be created because volume has "
|
||||||
|
"not been scheduled to any host.")
|
||||||
|
raise exception.InvalidVolume(reason=msg)
|
||||||
|
|
||||||
if volume['status'] == 'maintenance':
|
if volume['status'] == 'maintenance':
|
||||||
LOG.info(_LI('Unable to create the snapshot for volume, '
|
LOG.info(_LI('Unable to create the snapshot for volume, '
|
||||||
'because it is in maintenance.'), resource=volume)
|
'because it is in maintenance.'), resource=volume)
|
||||||
|
Loading…
Reference in New Issue
Block a user