From 91b1d2ce53e407a1f2f823ba87edaa6efabb8db0 Mon Sep 17 00:00:00 2001
From: Clinton Knight <cknight@netapp.com>
Date: Wed, 7 Sep 2016 18:38:50 -0400
Subject: [PATCH] NetApp cDOT driver autosupport broken

The autosupport functionality of the NetApp cDOT driver is not working
with Python 2.7.12, the default in Xenial. Root cause is a deep copy
of the controller connection context, which includes some SSL context
stuff that doesn't play well with copy.deepcopy. So we can do a shallow
copy instead.

Change-Id: Ia2adc4ce27834e384e6d994fcb012ebf1d97c85c
Closes-Bug: #1621260
---
 .../drivers/netapp/dataontap/client/client_cmode.py  |  4 +++-
 .../netapp/dataontap/client/test_client_cmode.py     | 12 ++++++------
 ...xed-netapp-cdot-autosupport-3fabd8ac2e407f70.yaml |  5 +++++
 3 files changed, 14 insertions(+), 7 deletions(-)
 create mode 100644 releasenotes/notes/fixed-netapp-cdot-autosupport-3fabd8ac2e407f70.yaml

diff --git a/manila/share/drivers/netapp/dataontap/client/client_cmode.py b/manila/share/drivers/netapp/dataontap/client/client_cmode.py
index acac70eb52..9eb0c2fd0f 100644
--- a/manila/share/drivers/netapp/dataontap/client/client_cmode.py
+++ b/manila/share/drivers/netapp/dataontap/client/client_cmode.py
@@ -2456,7 +2456,9 @@ class NetAppCmodeClient(client_base.NetAppBaseClient):
     def send_ems_log_message(self, message_dict):
         """Sends a message to the Data ONTAP EMS log."""
 
-        node_client = copy.deepcopy(self)
+        # NOTE(cknight): Cannot use deepcopy on the connection context
+        node_client = copy.copy(self)
+        node_client.connection = copy.copy(self.connection)
         node_client.connection.set_timeout(25)
 
         try:
diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py
index cca54d58de..6deb0e6f3a 100644
--- a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py
+++ b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py
@@ -4311,9 +4311,9 @@ class NetAppClientCmodeTestCase(test.TestCase):
     def test_send_ems_log_message(self):
 
         # Mock client lest we not be able to see calls on its copy.
-        self.mock_object(copy,
-                         'deepcopy',
-                         mock.Mock(return_value=self.client))
+        self.mock_object(
+            copy, 'copy',
+            mock.Mock(side_effect=[self.client, self.client.connection]))
         self.mock_object(self.client,
                          '_get_ems_log_destination_vserver',
                          mock.Mock(return_value=fake.ADMIN_VSERVER_NAME))
@@ -4328,9 +4328,9 @@ class NetAppClientCmodeTestCase(test.TestCase):
     def test_send_ems_log_message_api_error(self):
 
         # Mock client lest we not be able to see calls on its copy.
-        self.mock_object(copy,
-                         'deepcopy',
-                         mock.Mock(return_value=self.client))
+        self.mock_object(
+            copy, 'copy',
+            mock.Mock(side_effect=[self.client, self.client.connection]))
         self.mock_object(self.client,
                          '_get_ems_log_destination_vserver',
                          mock.Mock(return_value=fake.ADMIN_VSERVER_NAME))
diff --git a/releasenotes/notes/fixed-netapp-cdot-autosupport-3fabd8ac2e407f70.yaml b/releasenotes/notes/fixed-netapp-cdot-autosupport-3fabd8ac2e407f70.yaml
new file mode 100644
index 0000000000..9b9d79cf80
--- /dev/null
+++ b/releasenotes/notes/fixed-netapp-cdot-autosupport-3fabd8ac2e407f70.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+  - The NetApp cDOT driver's autosupport reporting
+    now works on Python 2.7.12 and later.
+