Ibm_storage - fix create volume into group.
Running create_volume --group-id <group-id> fails. The reason for this is because the driver assumes the cg is already replicated. Change-Id: Ia360273ce6ec9f77c2289cd6ec6bf0d7001ec101 Closes-Bug: 1707648
This commit is contained in:
parent
772770327a
commit
162245e7cd
@ -27,6 +27,7 @@ pyxcli_client.mirroring = mock.Mock()
|
||||
pyxcli_client.transports = fake_pyxcli_exceptions
|
||||
pyxcli_client.mirroring.cg_recovery_manager = mock.Mock()
|
||||
pyxcli_client.version = '1.1.5'
|
||||
pyxcli_client.mirroring.mirrored_entities = mock.Mock()
|
||||
|
||||
sys.modules['pyxcli'] = pyxcli_client
|
||||
sys.modules['pyxcli.events'] = pyxcli_client.events
|
||||
|
@ -33,6 +33,7 @@ from cinder.volume import group_types
|
||||
|
||||
errors = fake_pyxcli.pyxcli_client.errors
|
||||
mirroring = fake_pyxcli.pyxcli_client.mirroring
|
||||
mirrored_entities = fake_pyxcli.pyxcli_client.mirroring.mirrored_entities
|
||||
|
||||
test_mock = mock.MagicMock()
|
||||
module_patcher = mock.MagicMock()
|
||||
@ -613,6 +614,41 @@ class XIVProxyTest(test.TestCase):
|
||||
vol=volume['name'],
|
||||
cg='cg')
|
||||
|
||||
@mock.patch('pyxcli.mirroring.mirrored_entities.'
|
||||
'MirroredEntities', mock.MagicMock())
|
||||
@mock.patch('cinder.volume.utils.is_group_a_type',
|
||||
mock.MagicMock(return_value=True))
|
||||
@mock.patch("cinder.volume.drivers.ibm.ibm_storage."
|
||||
"xiv_proxy.XIVProxy._get_extra_specs",
|
||||
mock.MagicMock(return_value=TEST_EXTRA_SPECS_REPL))
|
||||
@mock.patch("cinder.volume.drivers.ibm.ibm_storage."
|
||||
"xiv_replication.VolumeReplication.create_replication",
|
||||
mock.MagicMock())
|
||||
def test_create_volume_with_consistency_group_diff_state(self):
|
||||
"""Test Create volume with consistency_group but diff state"""
|
||||
driver = mock.MagicMock()
|
||||
driver.VERSION = "VERSION"
|
||||
|
||||
p = self.proxy(
|
||||
self.default_storage_info,
|
||||
mock.MagicMock(),
|
||||
test_mock.cinder.exception,
|
||||
driver)
|
||||
|
||||
p.ibm_storage_cli = mock.MagicMock()
|
||||
p._cg_name_from_volume = mock.MagicMock(return_value="cg")
|
||||
|
||||
vol_type = testutils.create_volume_type(self.ctxt, name='WTF')
|
||||
volume = testutils.create_volume(
|
||||
self.ctxt, size=16, volume_type_id=vol_type.id,
|
||||
host=self._get_test_host()['name'])
|
||||
|
||||
grp = self._create_test_group('WTF')
|
||||
grp['replication_status'] = 'enabled'
|
||||
volume.group = grp
|
||||
ex = getattr(p, "_get_exception")()
|
||||
self.assertRaises(ex, p.create_volume, volume)
|
||||
|
||||
@mock.patch("cinder.volume.drivers.ibm.ibm_storage."
|
||||
"xiv_replication.VolumeReplication.create_replication",
|
||||
mock.MagicMock())
|
||||
|
@ -522,18 +522,21 @@ class XIVProxy(proxy.IBMStorageProxy):
|
||||
' should be the same')
|
||||
elif volume.host != volume.group.host:
|
||||
msg = 'Cannot add volume to Group on different host'
|
||||
else:
|
||||
elif volume.group['replication_status'] == 'enabled':
|
||||
# if group is mirrored and enabled, compare state.
|
||||
group_name = self._cg_name_from_group(volume.group)
|
||||
me = mirrored_entities.MirroredEntities(
|
||||
self.ibm_storage_cli)
|
||||
me_objs = me.get_mirror_resources_by_name_map()
|
||||
vol_sync_state = me_objs['volumes'][volume.name].sync_state
|
||||
cg_sync_state = me_objs['cgs'][group_name].sync_state
|
||||
vol_obj = me_objs['volumes'][volume.name]
|
||||
vol_sync_state = vol_obj['sync_state']
|
||||
cg_sync_state = me_objs['cgs'][group_name]['sync_state']
|
||||
|
||||
if (vol_sync_state != 'Synchronized' or
|
||||
cg_sync_state != 'Synchronized'):
|
||||
msg = ('Cannot add volume to Group. Both volume and '
|
||||
'group should have sync_state = Synchronized')
|
||||
|
||||
if msg:
|
||||
LOG.error(msg)
|
||||
raise self.meta['exception'].VolumeBackendAPIException(
|
||||
@ -590,8 +593,10 @@ class XIVProxy(proxy.IBMStorageProxy):
|
||||
self._update_consistencygroup(context, group,
|
||||
remove_volumes=volumes)
|
||||
for volume in volumes:
|
||||
repl.VolumeReplication(self).create_replication(
|
||||
volume.name, replication_info)
|
||||
enabled_status = fields.ReplicationStatus.ENABLED
|
||||
if volume['replication_status'] != enabled_status:
|
||||
repl.VolumeReplication(self).create_replication(
|
||||
volume.name, replication_info)
|
||||
|
||||
# mirror entire group
|
||||
group_name = self._cg_name_from_group(group)
|
||||
|
Loading…
x
Reference in New Issue
Block a user