From b7dbe6f09026eea1f5c6ddff355a67e680dc16d7 Mon Sep 17 00:00:00 2001 From: Yu Zhang Date: Fri, 3 Aug 2018 09:48:15 +0300 Subject: [PATCH] IBM XIV: fix issues for replication 1. A list has no next method which caused exception while get replication target, and update to be compatible with python2 and python3. 2. Get pool should consider whether it has failed over or not. Change-Id: Id192a4f2ba707c4b906a956435e5796001ea808a Closes-bugs: #1785177 --- .../unit/volume/drivers/ibm/test_xiv_proxy.py | 26 +++++++++++++++++++ .../volume/drivers/ibm/ibm_storage/proxy.py | 2 +- .../drivers/ibm/ibm_storage/xiv_proxy.py | 23 ++++++++++------ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py index 0fedd688e7e..095e0d37c47 100644 --- a/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py +++ b/cinder/tests/unit/volume/drivers/ibm/test_xiv_proxy.py @@ -691,6 +691,32 @@ class XIVProxyTest(test.TestCase): resource_id=group['name'], new_role='Slave') + @mock.patch("cinder.volume.drivers.ibm.ibm_storage." + "xiv_proxy.XIVProxy._get_target_params", + mock.MagicMock(return_value=REPLICA_PARAMS)) + def test_pool_with_replication_failover_back(self): + driver = mock.MagicMock() + driver.VERSION = "VERSION" + + p = self.proxy( + self.default_storage_info, + mock.MagicMock(), + test_mock.cinder.exception, + driver) + + pool_name = p._get_backend_pool() + self.assertEqual(self.default_storage_info['vol_pool'], pool_name) + + p_failback = self.proxy( + self.default_storage_info, + mock.MagicMock(), + test_mock.cinder.exception, + driver, + REPLICA_ID) + + pool_name = p_failback._get_backend_pool() + self.assertEqual(REPLICA_POOL, pool_name) + @mock.patch("cinder.volume.utils.is_group_a_cg_snapshot_type", mock.MagicMock(return_value=True)) def test_create_volume_with_consistency_group(self): diff --git a/cinder/volume/drivers/ibm/ibm_storage/proxy.py b/cinder/volume/drivers/ibm/ibm_storage/proxy.py index b994d409878..06595cd47a6 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/proxy.py @@ -360,7 +360,7 @@ class IBMStorageProxy(object): if not self.targets: return None try: - target = self.targets.keys().next() + target = list(self.targets.keys())[0] return target except Exception: return None diff --git a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py index 0f7f192b120..0aeedb774ba 100644 --- a/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py +++ b/cinder/volume/drivers/ibm/ibm_storage/xiv_proxy.py @@ -448,7 +448,7 @@ class XIVProxy(proxy.IBMStorageProxy): def _create_volume(self, volume): """Internal implementation to create a volume.""" size = storage.gigabytes_to_blocks(float(volume['size'])) - pool = self.storage_info[storage.FLAG_KEYS['storage_pool']] + pool = self._get_backend_pool() try: self._call_xiv_xcli( "vol_create", vol=volume['name'], size_blocks=size, pool=pool) @@ -1510,7 +1510,7 @@ class XIVProxy(proxy.IBMStorageProxy): if (dest != strings.XIV_BACKEND_PREFIX or dest_host != volume_host): return False - pool_name = self.storage_info[storage.FLAG_KEYS['storage_pool']] + pool_name = self._get_backend_pool() # if pool is different. else - we're on the same pool and retype is ok. if (pool_name != dest_pool): @@ -1611,17 +1611,24 @@ class XIVProxy(proxy.IBMStorageProxy): @proxy._trace_time def _get_pool(self): + pool_name = self._get_backend_pool() pools = self._call_xiv_xcli( - "pool_list", pool=self.storage_info[ - storage.FLAG_KEYS['storage_pool']]).as_list + "pool_list", pool=pool_name).as_list if not pools: msg = (_( "Pool %(pool)s not available on storage") % - {'pool': self.storage_info[storage.FLAG_KEYS['storage_pool']]}) + {'pool': pool_name}) LOG.error(msg) raise self.meta['exception'].VolumeBackendAPIException(data=msg) return pools + def _get_backend_pool(self): + if self.active_backend_id == strings.PRIMARY_BACKEND_ID: + return self.storage_info[storage.FLAG_KEYS['storage_pool']] + else: + return self._get_target_params( + self.active_backend_id)['san_clustername'] + def _retrieve_pool_stats(self, data): try: pools = self._get_pool() @@ -2419,7 +2426,7 @@ class XIVProxy(proxy.IBMStorageProxy): return fc_targets def _get_pool_domain(self, connector): - pool_name = self.storage_info[storage.FLAG_KEYS['storage_pool']] + pool_name = self._get_backend_pool() LOG.debug("pool name from configuration: %s", pool_name) domain = None try: @@ -2524,7 +2531,7 @@ class XIVProxy(proxy.IBMStorageProxy): LOG.debug("send event SERVICE_STARTED") service_start_evnt_prop = { "openstack_version": self.meta['openstack_version'], - "pool_name": self.storage_info[storage.FLAG_KEYS['storage_pool']]} + "pool_name": self._get_backend_pool()} ev_mgr = events.EventsManager(self.ibm_storage_cli, OPENSTACK_PRODUCT_NAME, self.full_version) @@ -2537,7 +2544,7 @@ class XIVProxy(proxy.IBMStorageProxy): compute_host_name = socket.getfqdn() vol_attach_evnt_prop = { "openstack_version": self.meta['openstack_version'], - "pool_name": self.storage_info[storage.FLAG_KEYS['storage_pool']], + "pool_name": self._get_backend_pool(), "compute_hostname": compute_host_name} ev_mgr = events.EventsManager(self.ibm_storage_cli,