1,
None)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_replay_profile',
+ return_value='fake')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'update_cg_volumes')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'create_volume',
+ return_value=VOLUME)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_sc',
+ return_value=12345)
+ def test_create_volume_consistency_group(self,
+ mock_find_sc,
+ mock_create_volume,
+ mock_update_cg_volumes,
+ mock_find_replay_profile,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ volume = {'id': self.volume_name, 'size': 1,
+ 'consistencygroup_id': 'guid'}
+ self.driver.create_volume(volume)
+ mock_create_volume.assert_called_once_with(self.volume_name,
+ 1,
+ None)
+ self.assertTrue(mock_find_replay_profile.called)
+ self.assertTrue(mock_update_cg_volumes.called)
+
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'create_volume',
return_value=VOLUME)
self.driver.create_snapshot,
snapshot)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_replay_profile')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_sc',
return_value=12345)
mock_find_replay,
mock_find_volume,
mock_find_sc,
+ mock_find_replay_profile,
mock_close_connection,
mock_open_connection,
mock_init):
volume = {'id': 'fake'}
snapshot = {'id': 'fake', 'volume_id': 'fake'}
self.driver.create_volume_from_snapshot(volume, snapshot)
+ mock_create_view_volume.assert_called_once_with('fake',
+ 'fake')
+ self.assertTrue(mock_find_replay.called)
+ self.assertTrue(mock_find_volume.called)
+ self.assertFalse(mock_find_replay_profile.called)
+
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_replay_profile',
+ return_value='fake')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'update_cg_volumes')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_sc',
+ return_value=12345)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_volume',
+ return_value=VOLUME)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_replay',
+ return_value='fake')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'create_view_volume',
+ return_value=VOLUME)
+ def test_create_volume_from_snapshot_cg(self,
+ mock_create_view_volume,
+ mock_find_replay,
+ mock_find_volume,
+ mock_find_sc,
+ mock_update_cg_volumes,
+ mock_find_replay_profile,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ volume = {'id': 'fake', 'consistencygroup_id': 'guid'}
+ snapshot = {'id': 'fake', 'volume_id': 'fake'}
+ self.driver.create_volume_from_snapshot(volume, snapshot)
+ mock_create_view_volume.assert_called_once_with('fake',
+ 'fake')
+ self.assertTrue(mock_find_replay.called)
+ self.assertTrue(mock_find_volume.called)
+ self.assertTrue(mock_find_replay_profile.called)
+ self.assertTrue(mock_update_cg_volumes.called)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_sc',
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.create_volume_from_snapshot,
volume, snapshot)
+ self.assertTrue(mock_find_volume.called)
+ self.assertTrue(mock_find_replay.called)
+ self.assertFalse(mock_create_view_volume.called)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_sc',
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_volume',
return_value=VOLUME)
- @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- 'find_replay',
- return_value='fake')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'create_cloned_volume',
return_value=VOLUME)
def test_create_cloned_volume(self,
mock_create_cloned_volume,
mock_find_volume,
- mock_find_replay,
mock_find_sc,
mock_close_connection,
mock_open_connection,
volume = {'id': self.volume_name + '_clone'}
src_vref = {'id': self.volume_name}
self.driver.create_cloned_volume(volume, src_vref)
- mock_create_cloned_volume. \
- assert_called_once_with(self.volume_name + '_clone',
- self.VOLUME)
+ mock_create_cloned_volume.assert_called_once_with(
+ self.volume_name + '_clone',
+ self.VOLUME)
+ self.assertTrue(mock_find_volume.called)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_replay_profile',
+ return_value='fake')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'update_cg_volumes')
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_sc',
return_value=12345)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_volume',
- return_value=None)
+ return_value=VOLUME)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
- 'find_replay',
- return_value='fake')
+ 'create_cloned_volume',
+ return_value=VOLUME)
+ def test_create_cloned_volume_consistency_group(self,
+ mock_create_cloned_volume,
+ mock_find_volume,
+ mock_find_sc,
+ mock_update_cg_volumes,
+ mock_find_replay_profile,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ volume = {'id': self.volume_name + '_clone',
+ 'consistencygroup_id': 'guid'}
+ src_vref = {'id': self.volume_name}
+ self.driver.create_cloned_volume(volume, src_vref)
+ mock_create_cloned_volume.assert_called_once_with(
+ self.volume_name + '_clone',
+ self.VOLUME)
+ self.assertTrue(mock_find_volume.called)
+ self.assertTrue(mock_find_replay_profile.called)
+ self.assertTrue(mock_update_cg_volumes.called)
+
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_sc',
+ return_value=12345)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ 'find_volume',
+ return_value=None)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'create_cloned_volume',
return_value=VOLUME)
def test_create_cloned_volume_no_volume(self,
mock_create_cloned_volume,
mock_find_volume,
- mock_find_replay,
mock_find_sc,
mock_close_connection,
mock_open_connection,
self.assertRaises(exception.VolumeBackendAPIException,
self.driver.create_cloned_volume,
volume, src_vref)
+ self.assertTrue(mock_find_volume.called)
+ self.assertFalse(mock_create_cloned_volume.called)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_sc',
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_replay_profile',
return_value=SCRPLAYPROFILE)
+ @mock.patch('cinder.objects.snapshot.SnapshotList.get_all_for_cgsnapshot')
def test_create_cgsnapshot(self,
+ mock_get_all_for_cgsnapshot,
mock_find_replay_profile,
mock_snap_cg_replay,
mock_close_connection,
mock_open_connection,
mock_init):
- self.driver.db = mock.Mock()
mock_snapshot = mock.MagicMock()
expected_snapshots = [mock_snapshot]
- self.driver.db.snapshot_get_all_for_cgsnapshot.return_value = (
- expected_snapshots)
+ mock_get_all_for_cgsnapshot.return_value = (expected_snapshots)
+
context = {}
cggrp = {'consistencygroup_id': 'fc8f2fec-fab2-4e34-9148-c094c913b9a3',
'id': '100'}
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_replay_profile',
return_value=SCRPLAYPROFILE)
+ @mock.patch('cinder.objects.snapshot.SnapshotList.get_all_for_cgsnapshot')
def test_delete_cgsnapshot(self,
+ mock_get_all_for_cgsnapshot,
mock_find_replay_profile,
mock_delete_cg_replay,
mock_close_connection,
mock_open_connection,
mock_init):
- self.driver.db = mock.Mock()
mock_snapshot = mock.MagicMock()
expected_snapshots = [mock_snapshot]
- self.driver.db.snapshot_get_all_for_cgsnapshot.return_value = (
- expected_snapshots)
+ mock_get_all_for_cgsnapshot.return_value = (expected_snapshots)
context = {}
cgsnap = {'consistencygroup_id':
'fc8f2fec-fab2-4e34-9148-c094c913b9a3',
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'find_replay_profile',
return_value=None)
+ @mock.patch('cinder.objects.snapshot.SnapshotList.get_all_for_cgsnapshot')
def test_delete_cgsnapshot_profile_not_found(self,
+ mock_get_all_for_cgsnapshot,
mock_find_replay_profile,
mock_delete_cg_replay,
mock_close_connection,
mock_open_connection,
mock_init):
- self.driver.db = mock.Mock()
mock_snapshot = mock.MagicMock()
expected_snapshots = [mock_snapshot]
- self.driver.db.snapshot_get_all_for_cgsnapshot.return_value = (
- expected_snapshots)
+ mock_get_all_for_cgsnapshot.return_value = (expected_snapshots)
context = {}
cgsnap = {'consistencygroup_id':
'fc8f2fec-fab2-4e34-9148-c094c913b9a3',
remove_volumes)
self.assertFalse(res)
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'get',
+ return_value=RESPONSE_200)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_json',
+ return_value=[INACTIVE_VOLUME])
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_init_volume')
+ def test_init_cg_volumes_inactive(self,
+ mock_init_volume,
+ mock_get_json,
+ mock_get,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ profileid = 100
+ self.scapi._init_cg_volumes(profileid)
+ self.assertTrue(mock_get.called)
+ self.assertTrue(mock_get_json.called)
+ mock_init_volume.assert_called_once_with(self.INACTIVE_VOLUME)
+
+ @mock.patch.object(dell_storagecenter_api.HttpClient,
+ 'get',
+ return_value=RESPONSE_200)
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_get_json',
+ return_value=[VOLUME])
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_init_volume')
+ def test_init_cg_volumes_active(self,
+ mock_init_volume,
+ mock_get_json,
+ mock_get,
+ mock_close_connection,
+ mock_open_connection,
+ mock_init):
+ profileid = 100
+ self.scapi._init_cg_volumes(profileid)
+ self.assertTrue(mock_get.called)
+ self.assertTrue(mock_get_json.called)
+ self.assertFalse(mock_init_volume.called)
+
@mock.patch.object(dell_storagecenter_api.HttpClient,
'post',
return_value=RESPONSE_204)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_get_id',
return_value='100')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_init_cg_volumes')
def test_snap_cg_replay(self,
+ mock_init_cg_volumes,
mock_get_id,
mock_post,
mock_close_connection,
res = self.scapi.snap_cg_replay(profile, replayid, expire)
mock_post.assert_called_once_with(expected_url, expected_payload)
self.assertTrue(mock_get_id.called)
+ self.assertTrue(mock_init_cg_volumes.called)
self.assertTrue(res)
@mock.patch.object(dell_storagecenter_api.HttpClient,
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
'_get_id',
return_value='100')
+ @mock.patch.object(dell_storagecenter_api.StorageCenterApi,
+ '_init_cg_volumes')
def test_snap_cg_replay_bad_return(self,
+ mock_init_cg_volumes,
mock_get_id,
mock_post,
mock_close_connection,
res = self.scapi.snap_cg_replay(profile, replayid, expire)
mock_post.assert_called_once_with(expected_url, expected_payload)
self.assertTrue(mock_get_id.called)
+ self.assertTrue(mock_init_cg_volumes.called)
self.assertFalse(res)
@mock.patch.object(dell_storagecenter_api.StorageCenterApi,
from oslo_utils import excutils
from cinder import exception
+from cinder import objects
from cinder.i18n import _, _LE, _LI, _LW
from cinder.volume import driver
from cinder.volume.drivers.dell import dell_storagecenter_api
return {}
+ def _add_volume_to_consistency_group(self, api, scvolume, volume):
+ '''Just a helper to add a volume to a consistency group.
+
+ :param api: Dell SC API opbject.
+ :param scvolume: Dell SC Volume object.
+ :param volume: Cinder Volume object.
+ :return: Nothing.
+ '''
+ if scvolume and volume.get('consistencygroup_id'):
+ profile = api.find_replay_profile(
+ volume.get('consistencygroup_id'))
+ if profile:
+ api.update_cg_volumes(profile, [volume])
+
def create_volume(self, volume):
'''Create a volume.'''
scvolume = api.create_volume(volume_name,
volume_size,
storage_profile)
+ # Update Consistency Group
+ self._add_volume_to_consistency_group(api, scvolume, volume)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_LE('Failed to create volume %s'),
'''Create new volume from other volume's snapshot on appliance.'''
scvolume = None
src_volume_name = snapshot.get('volume_id')
- snapshot_id = snapshot.get('id')
+ # This snapshot could have been created on its own or as part of a
+ # cgsnapshot. If it was a cgsnapshot it will be identified on the Dell
+ # backend under cgsnapshot_id. Given the volume ID and the
+ # cgsnapshot_id we can find the appropriate snapshot.
+ # So first we look for cgsnapshot_id. If that is blank then it must
+ # have been a normal snapshot which will be found under snapshot_id.
+ snapshot_id = snapshot.get('cgsnapshot_id')
+ if not snapshot_id:
+ snapshot_id = snapshot.get('id')
volume_name = volume.get('id')
LOG.debug(
'Creating new volume %(vol)s from snapshot %(snap)s '
volume_name = volume.get('id')
scvolume = api.create_view_volume(volume_name,
replay)
+ # Update Consistency Group
+ self._add_volume_to_consistency_group(api,
+ scvolume,
+ volume)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_LE('Failed to create volume %s'),
if srcvol is not None:
scvolume = api.create_cloned_volume(volume_name,
srcvol)
+ # Update Consistency Group
+ self._add_volume_to_consistency_group(api,
+ scvolume,
+ volume)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error(_LE('Failed to create volume %s'),
if profile:
LOG.debug('profile %s replayid %s', profile, snapshotid)
if api.snap_cg_replay(profile, snapshotid, 0):
- snapshots = self.db.snapshot_get_all_for_cgsnapshot(
- context,
- snapshotid)
- LOG.debug(snapshots)
+ snapshots = objects.SnapshotList().get_all_for_cgsnapshot(
+ context, snapshotid)
for snapshot in snapshots:
- LOG.debug(snapshot)
- snapshot['status'] = 'available'
+ snapshot.status = 'available'
model_update = {'status': 'available'}
_('Unable to delete Consistency Group snapshot %s') %
snapshotid)
- snapshots = self.db.snapshot_get_all_for_cgsnapshot(context,
- snapshotid)
-
+ snapshots = objects.SnapshotList().get_all_for_cgsnapshot(
+ context, snapshotid)
for snapshot in snapshots:
- snapshot['status'] = 'deleted'
+ snapshot.status = 'deleted'
model_update = {'status': 'deleted'}