From: Alex O'Rourke <alex.orourke@hpe.com>
Date: Mon, 4 Jan 2016 17:06:10 +0000 (-0800)
Subject: Optimize 3PAR array ID retrieval
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4e4870936165fc1927a646e7fa3972df06ee0606;p=openstack-build%2Fcinder-build.git

Optimize 3PAR array ID retrieval

Currently, we are making a call to the 3PAR array every time the
common driver is initialized, which is inefficient considering the
call is already made in get_volume_stats. Instead of making the call
every time, we can pass in the driver stats to common's do_setup and
use the array ID from there.

If the stats are not yet available, we will ask the array directly for
the ID.

Change-Id: Iff065cd9debfc899b1d88475c63c7b2cb1e5e1b6
---

diff --git a/cinder/tests/unit/test_hpe3par.py b/cinder/tests/unit/test_hpe3par.py
index cb9f64751..87b5f0af5 100644
--- a/cinder/tests/unit/test_hpe3par.py
+++ b/cinder/tests/unit/test_hpe3par.py
@@ -5247,6 +5247,7 @@ class TestHPE3PARFCDriver(HPE3PARBaseDriver, test.TestCase):
             stats = self.driver.get_volume_stats(True)
             const = 0.0009765625
             self.assertEqual('FC', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertTrue(stats['pools'][0]['thin_provisioning_support'])
             self.assertTrue(stats['pools'][0]['thick_provisioning_support'])
             self.assertFalse(stats['pools'][0]['QoS_support'])
@@ -5290,6 +5291,7 @@ class TestHPE3PARFCDriver(HPE3PARBaseDriver, test.TestCase):
                 self.standard_logout)
             stats = self.driver.get_volume_stats(True)
             self.assertEqual('FC', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertTrue(stats['pools'][0]['thin_provisioning_support'])
             self.assertTrue(stats['pools'][0]['thick_provisioning_support'])
             self.assertFalse(stats['pools'][0]['QoS_support'])
@@ -5322,6 +5324,7 @@ class TestHPE3PARFCDriver(HPE3PARBaseDriver, test.TestCase):
 
             stats = self.driver.get_volume_stats(True)
             self.assertEqual('FC', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertTrue(stats['pools'][0]['thin_provisioning_support'])
             self.assertTrue(stats['pools'][0]['thick_provisioning_support'])
             self.assertFalse(stats['pools'][0]['QoS_support'])
@@ -5399,6 +5402,7 @@ class TestHPE3PARFCDriver(HPE3PARBaseDriver, test.TestCase):
 
             stats = self.driver.get_volume_stats(True)
             self.assertEqual('FC', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertFalse(stats['pools'][0]['thin_provisioning_support'])
             self.assertTrue(stats['pools'][0]['QoS_support'])
             self.assertEqual(24.0, stats['pools'][0]['total_capacity_gb'])
@@ -5459,6 +5463,7 @@ class TestHPE3PARFCDriver(HPE3PARBaseDriver, test.TestCase):
 
             stats = self.driver.get_volume_stats(True)
             self.assertEqual('FC', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertEqual(24.0, stats['pools'][0]['total_capacity_gb'])
             self.assertEqual(3.0, stats['pools'][0]['free_capacity_gb'])
             self.assertEqual(87.5, stats['pools'][0]['capacity_utilization'])
@@ -6008,6 +6013,7 @@ class TestHPE3PARISCSIDriver(HPE3PARBaseDriver, test.TestCase):
             stats = self.driver.get_volume_stats(True)
             const = 0.0009765625
             self.assertEqual('iSCSI', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertTrue(stats['pools'][0]['thin_provisioning_support'])
             self.assertTrue(stats['pools'][0]['thick_provisioning_support'])
             self.assertEqual(24.0, stats['pools'][0]['total_capacity_gb'])
@@ -6055,6 +6061,7 @@ class TestHPE3PARISCSIDriver(HPE3PARBaseDriver, test.TestCase):
 
             stats = self.driver.get_volume_stats(True)
             self.assertEqual('iSCSI', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertTrue(stats['pools'][0]['thin_provisioning_support'])
             self.assertTrue(stats['pools'][0]['thick_provisioning_support'])
             total_capacity_gb = 8192 * const
@@ -6122,6 +6129,7 @@ class TestHPE3PARISCSIDriver(HPE3PARBaseDriver, test.TestCase):
 
             stats = self.driver.get_volume_stats(True)
             self.assertEqual('iSCSI', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertEqual(24.0, stats['pools'][0]['total_capacity_gb'])
             self.assertEqual(3.0, stats['pools'][0]['free_capacity_gb'])
             self.assertEqual(87.5, stats['pools'][0]['capacity_utilization'])
@@ -6180,6 +6188,7 @@ class TestHPE3PARISCSIDriver(HPE3PARBaseDriver, test.TestCase):
 
             stats = self.driver.get_volume_stats(True)
             self.assertEqual('iSCSI', stats['storage_protocol'])
+            self.assertEqual('12345', stats['array_id'])
             self.assertEqual(24.0, stats['pools'][0]['total_capacity_gb'])
             self.assertEqual(3.0, stats['pools'][0]['free_capacity_gb'])
             self.assertEqual(87.5, stats['pools'][0]['capacity_utilization'])
diff --git a/cinder/volume/drivers/hpe/hpe_3par_common.py b/cinder/volume/drivers/hpe/hpe_3par_common.py
index c3e63545f..2d0963a59 100644
--- a/cinder/volume/drivers/hpe/hpe_3par_common.py
+++ b/cinder/volume/drivers/hpe/hpe_3par_common.py
@@ -219,10 +219,11 @@ class HPE3PARCommon(object):
         3.0.5 - Adds v2 unmanaged replication support
         3.0.6 - Adding manage/unmanage snapshot support
         3.0.7 - Enable standard capabilities based on 3PAR licenses
+        3.0.8 - Optimize array ID retrieval
 
     """
 
-    VERSION = "3.0.7"
+    VERSION = "3.0.8"
 
     stats = {}
 
@@ -378,7 +379,7 @@ class HPE3PARCommon(object):
         if client is not None:
             client.logout()
 
-    def do_setup(self, context, volume=None, timeout=None):
+    def do_setup(self, context, volume=None, timeout=None, stats=None):
         if hpe3parclient is None:
             msg = _('You must install hpe3parclient before using 3PAR'
                     ' drivers. Run "pip install python-3parclient" to'
@@ -430,15 +431,19 @@ class HPE3PARCommon(object):
             LOG.error(msg)
             raise exception.InvalidInput(message=msg)
 
-        # get the client ID for provider_location
-        try:
-            self.client_login()
-            info = self.client.getStorageSystemInfo()
-            self.client.id = six.text_type(info['id'])
-        except Exception:
-            self.client.id = 0
-        finally:
-            self.client_logout()
+        # Get the client ID for provider_location. We only need to retrieve
+        # the ID directly from the array if the driver stats are not provided.
+        if not stats:
+            try:
+                self.client_login()
+                info = self.client.getStorageSystemInfo()
+                self.client.id = six.text_type(info['id'])
+            except Exception:
+                self.client.id = 0
+            finally:
+                self.client_logout()
+        else:
+            self.client.id = stats['array_id']
 
     def check_for_setup_error(self):
         if self.client:
@@ -1267,6 +1272,7 @@ class HPE3PARCommon(object):
                       'storage_protocol': None,
                       'vendor_name': 'Hewlett Packard Enterprise',
                       'volume_backend_name': None,
+                      'array_id': info['id'],
                       'pools': pools}
 
     def _check_license_enabled(self, valid_licenses,
diff --git a/cinder/volume/drivers/hpe/hpe_3par_fc.py b/cinder/volume/drivers/hpe/hpe_3par_fc.py
index bd817fe89..42a422c5d 100644
--- a/cinder/volume/drivers/hpe/hpe_3par_fc.py
+++ b/cinder/volume/drivers/hpe/hpe_3par_fc.py
@@ -95,10 +95,11 @@ class HPE3PARFCDriver(driver.TransferVD,
         3.0.2 - Adds v2 managed replication support
         3.0.3 - Adds v2 unmanaged replication support
         3.0.4 - Adding manage/unmanage snapshot support
+        3.0.5 - Optimize array ID retrieval
 
     """
 
-    VERSION = "3.0.4"
+    VERSION = "3.0.5"
 
     def __init__(self, *args, **kwargs):
         super(HPE3PARFCDriver, self).__init__(*args, **kwargs)
@@ -114,7 +115,8 @@ class HPE3PARFCDriver(driver.TransferVD,
         # If replication is enabled and we cannot login, we do not want to
         # raise an exception so a failover can still be executed.
         try:
-            common.do_setup(None, volume, timeout=timeout)
+            common.do_setup(None, volume=volume, timeout=timeout,
+                            stats=self._stats)
             common.client_login()
         except Exception:
             if common._replication_enabled:
diff --git a/cinder/volume/drivers/hpe/hpe_3par_iscsi.py b/cinder/volume/drivers/hpe/hpe_3par_iscsi.py
index d954c72e8..e9e487c42 100644
--- a/cinder/volume/drivers/hpe/hpe_3par_iscsi.py
+++ b/cinder/volume/drivers/hpe/hpe_3par_iscsi.py
@@ -107,10 +107,11 @@ class HPE3PARISCSIDriver(driver.TransferVD,
         3.0.4 - Adds v2 managed replication support
         3.0.5 - Adds v2 unmanaged replication support
         3.0.6 - Adding manage/unmanage snapshot support
+        3.0.7 - Optimize array ID retrieval
 
     """
 
-    VERSION = "3.0.6"
+    VERSION = "3.0.7"
 
     def __init__(self, *args, **kwargs):
         super(HPE3PARISCSIDriver, self).__init__(*args, **kwargs)
@@ -125,7 +126,8 @@ class HPE3PARISCSIDriver(driver.TransferVD,
         # If replication is enabled and we cannot login, we do not want to
         # raise an exception so a failover can still be executed.
         try:
-            common.do_setup(None, volume, timeout=timeout)
+            common.do_setup(None, volume=volume, timeout=timeout,
+                            stats=self._stats)
             common.client_login()
         except Exception:
             if common._replication_enabled: