create snapshot with generic group fail with XtremIO Driver.

fix a bug in the xtremio driver which cause a create
snapshot from generic group with volumes to fail. the bug was that
the driver did not expect to have group_id instead of
consistency_group_id as part of the cgsnapshots object.

Closes-bug: #1664209
Change-Id: I5682fa5eaa7f265c7e10a2af5704847129704637
(cherry picked from commit 34ebfa6a07)
This commit is contained in:
Elad Zucker 2017-02-13 15:33:19 +02:00 committed by Shay Halsband
parent 23ddc7cbc6
commit 3c3f7147d6
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):
@ -1065,6 +1068,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
@ -1076,6 +1103,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

@ -787,13 +787,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')