Merge "create snapshot with generic group fail with XtremIO Driver."

This commit is contained in:
Jenkins 2017-02-21 19:46:18 +00:00 committed by Gerrit Code Review
commit 2decc903c4
2 changed files with 55 additions and 7 deletions

View File

@ -304,13 +304,16 @@ class CommonData(object):
'name': 'cg1',
'status': 'OK',
}
cgsnapshot = mock.Mock(id='192eb39b-6c2f-420c-bae3-3cfd117f9876',
consistencygroup_id=group['id'])
def cgsnap_getitem(self, val):
return self.__dict__[val]
cgsnapshot = {
'id': '192eb39b-6c2f-420c-bae3-3cfd117f9876',
'consistencygroup_id': group['id'],
'group_id': None, }
cgsnapshot.__getitem__ = cgsnap_getitem
cgsnapshot_as_group_id = {
'id': '192eb39b-6c2f-420c-bae3-3cfd117f9876',
'consistencygroup_id': None,
'group_id': group['id'], }
class BaseXtremIODriverTestCase(test.TestCase):
@ -1019,6 +1022,30 @@ class XtremIODriverISCSITestCase(BaseXtremIODriverTestCase):
[snapshot_obj])
self.assertEqual((None, None), res)
def test_group_snapshot_with_generic_group(self, req):
"""test group snapshot shot with generic group ."""
req.side_effect = xms_request
d = self.data
snapshot_obj = fake_snapshot.fake_snapshot_obj(d.context)
snapshot_obj.consistencygroup_id = d.group['id']
self.driver.create_group(d.context, d.group)
self.driver.update_group(d.context, d.group,
add_volumes=[d.test_volume,
d.test_volume2])
snapset_name = self.driver._get_cgsnap_name(d.cgsnapshot_as_group_id)
self.assertEqual(snapset_name,
'192eb39b6c2f420cbae33cfd117f0345192eb39b6c2f420cbae'
'33cfd117f9876')
snapset1 = {'ancestor-vol-id': ['', d.test_volume['id'], 2],
'consistencygroup_id': d.group['id'],
'name': snapset_name,
'index': 1}
xms_data['snapshot-sets'] = {snapset_name: snapset1, 1: snapset1}
res = self.driver.delete_group_snapshot(d.context, d.cgsnapshot,
[snapshot_obj])
self.assertEqual((None, None), res)
def test_delete_group_snapshot(self, req):
"""test delete group snapshot."""
d = self.data
@ -1030,6 +1057,17 @@ class XtremIODriverISCSITestCase(BaseXtremIODriverTestCase):
'192eb39b6c2f420cbae33cfd117f0345192eb39'
'b6c2f420cbae33cfd117f9876', None, 'v2')
def test_delete_group_snapshot_with_generic_group(self, req):
"""test delete group snapshot."""
d = self.data
snapshot_obj = fake_snapshot.fake_snapshot_obj(d.context)
snapshot_obj.consistencygroup_id = d.group['id']
self.driver.delete_group_snapshot(d.context, d.cgsnapshot_as_group_id,
[snapshot_obj])
req.assert_called_once_with('snapshot-sets', 'DELETE', None,
'192eb39b6c2f420cbae33cfd117f0345192eb39'
'b6c2f420cbae33cfd117f9876', None, 'v2')
def test_group_from_src_snapshot(self, req):
"""test group from source snapshot."""
req.side_effect = xms_request

View File

@ -776,13 +776,23 @@ class XtremIOVolumeDriver(san.SanDriver):
return None, None, None
def _get_cgsnap_name(self, cgsnapshot):
return '%(cg)s%(snap)s' % {'cg': cgsnapshot['consistencygroup_id']
group_id = cgsnapshot.get('group_id')
if group_id is None:
group_id = cgsnapshot.get('consistencygroup_id')
return '%(cg)s%(snap)s' % {'cg': group_id
.replace('-', ''),
'snap': cgsnapshot['id'].replace('-', '')}
def create_cgsnapshot(self, context, cgsnapshot, snapshots):
"""Creates a cgsnapshot."""
data = {'consistency-group-id': cgsnapshot['consistencygroup_id'],
group_id = cgsnapshot.get('group_id')
if group_id is None:
group_id = cgsnapshot.get('consistencygroup_id')
data = {'consistency-group-id': group_id,
'snapshot-set-name': self._get_cgsnap_name(cgsnapshot)}
self.client.req('snapshots', 'POST', data, ver='v2')