From 552d6fd33a4a2534eea6ca71765ab9936f5920b7 Mon Sep 17 00:00:00 2001
From: Peter Wang <peter.wang13@emc.com>
Date: Wed, 15 Nov 2017 04:13:28 -0500
Subject: [PATCH] VNX: Fix cloning failure when system is busy

In newton, the 30s wait was removed due to refactor, in this case,
If the session hasn't started in the VNX, the driver would perform
unexpected rollback for the migration.

Adding a wait will make sure the session is started on the VNX thus
cloning can succeed.

Change-Id: I3419e628d42eddfe19c55cd72e7b9469e9fccc94
Closes-bug: #1732462
---
 .../tests/unit/volume/drivers/dell_emc/vnx/test_client.py | 8 +++-----
 cinder/volume/drivers/dell_emc/vnx/client.py              | 5 ++++-
 cinder/volume/drivers/dell_emc/vnx/driver.py              | 6 +++---
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/cinder/tests/unit/volume/drivers/dell_emc/vnx/test_client.py b/cinder/tests/unit/volume/drivers/dell_emc/vnx/test_client.py
index d69cc9375db..f4ac7322ae0 100644
--- a/cinder/tests/unit/volume/drivers/dell_emc/vnx/test_client.py
+++ b/cinder/tests/unit/volume/drivers/dell_emc/vnx/test_client.py
@@ -12,7 +12,6 @@
 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 # License for the specific language governing permissions and limitations
 # under the License.
-
 import unittest
 
 from cinder import exception
@@ -50,10 +49,12 @@ class TestClient(test.TestCase):
         super(TestClient, self).setUp()
         self.origin_timeout = vnx_common.DEFAULT_TIMEOUT
         vnx_common.DEFAULT_TIMEOUT = 0
+        vnx_common.INTERVAL_30_SEC = 0
 
     def tearDown(self):
         super(TestClient, self).tearDown()
         vnx_common.DEFAULT_TIMEOUT = self.origin_timeout
+        vnx_common.INTERVAL_30_SEC = 30
 
     @res_mock.patch_client
     def test_create_lun(self, client, mocked):
@@ -116,7 +117,6 @@ class TestClient(test.TestCase):
                           src_id=4,
                           dst_id=5)
         lun.migrate.assert_called_with(5, storops.VNXMigrationRate.HIGH)
-        mock_sleep.assert_called_with(15)
 
     @res_mock.patch_client
     def test_session_finished_faulted(self, client, mocked):
@@ -256,10 +256,8 @@ class TestClient(test.TestCase):
     def test_expand_lun_already_expanded(self, client, _ignore):
         client.expand_lun('lun', 10)
 
-    @unittest.skip("Skip until bug #1578986 is fixed")
-    @utils.patch_sleep
     @res_mock.patch_client
-    def test_expand_lun_not_ops_ready(self, client, _ignore, sleep_mock):
+    def test_expand_lun_not_ops_ready(self, client, _ignore):
         self.assertRaises(storops_ex.VNXLunPreparingError,
                           client.expand_lun, 'lun', 10)
         lun = client.vnx.get_lun()
diff --git a/cinder/volume/drivers/dell_emc/vnx/client.py b/cinder/volume/drivers/dell_emc/vnx/client.py
index f6f2e33a3f7..3fda8e55a21 100644
--- a/cinder/volume/drivers/dell_emc/vnx/client.py
+++ b/cinder/volume/drivers/dell_emc/vnx/client.py
@@ -12,6 +12,8 @@
 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 # License for the specific language governing permissions and limitations
 # under the License.
+import time
+
 from oslo_log import log as logging
 from oslo_utils import excutils
 from oslo_utils import importutils
@@ -227,7 +229,8 @@ class Client(object):
         :returns Boolean: True or False
         """
         src_lun = self.vnx.get_lun(lun_id=src_id)
-
+        # Sleep 30 seconds to make sure the session starts on the VNX.
+        time.sleep(common.INTERVAL_30_SEC)
         utils.wait_until(condition=self.session_finished,
                          interval=common.INTERVAL_30_SEC,
                          src_lun=src_lun)
diff --git a/cinder/volume/drivers/dell_emc/vnx/driver.py b/cinder/volume/drivers/dell_emc/vnx/driver.py
index f28f1aa8f06..9c4d02bf8cc 100644
--- a/cinder/volume/drivers/dell_emc/vnx/driver.py
+++ b/cinder/volume/drivers/dell_emc/vnx/driver.py
@@ -72,14 +72,14 @@ class VNXDriver(driver.ManageableVD,
                   Configurable migration rate support
           8.0.0 - New VNX Cinder driver
           9.0.0 - Use asynchronous migration for cloning
-          10.0.0 - Extend SMP size before aync migration when cloning from an
+          10.0.0 - Extend SMP size before async migration when cloning from an
                    image cache volume
           10.1.0 - Add QoS support
           10.2.0 - Add replication group support
-
+          11.0.0 - Fix failure of migration during cloning
     """
 
-    VERSION = '10.02.00'
+    VERSION = '11.00.00'
     VENDOR = 'Dell EMC'
     # ThirdPartySystems wiki page
     CI_WIKI_NAME = "EMC_VNX_CI"