]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix a few bugs for LeftHand Grizzly
authorWalter A. Boring IV <walter.boring@hp.com>
Fri, 8 Mar 2013 00:19:14 +0000 (16:19 -0800)
committerWalter A. Boring IV <walter.boring@hp.com>
Fri, 8 Mar 2013 16:57:43 +0000 (08:57 -0800)
This patch fixes a few issues with the LH driver.
1) attach wasn't working because there was no host
created.
2) get_volume_stats didn't exist.
3) fixed the unit tests to work with the new config
access.

Bug 1062508
Bug 1150663

Change-Id: I6f80c3d5c70b64ca6496e50fedcb6b3ca0e2be43

cinder/tests/test_HpSanISCSIDriver.py
cinder/volume/drivers/san/hp_lefthand.py

index 1d9d9be109e1cd93b7c875371f77d9aa89e0cbac..a9ef2106cd6a1c55e03ced455f64a8d26d89498b 100644 (file)
@@ -33,6 +33,12 @@ class HpSanISCSITestCase(test.TestCase):
                        self._fake_get_iscsi_properties)
         configuration = mox.MockObject(conf.Configuration)
         configuration.san_is_local = False
+        configuration.san_ip = "10.0.0.1"
+        configuration.san_login = "foo"
+        configuration.san_password = "bar"
+        configuration.san_ssh_port = 16022
+        configuration.san_clustername = "CloudCluster1"
+        configuration.san_thin_provision = True
         configuration.append_config_values(mox.IgnoreArg())
 
         self.driver = HpSanISCSIDriver(configuration=configuration)
@@ -53,7 +59,7 @@ class HpSanISCSITestCase(test.TestCase):
     def _fake_get_iscsi_properties(self, volume):
         return self.properties
 
-    def _fake_cliq_run(self, verb, cliq_args):
+    def _fake_cliq_run(self, verb, cliq_args, check_exit_code=True):
         """Return fake results for the various methods."""
 
         def create_volume(cliq_args):
@@ -159,6 +165,22 @@ class HpSanISCSITestCase(test.TestCase):
                 </volume></response></gauche>"""
             return output, None
 
+        def get_server_info(cliq_args):
+            """
+            input = "getServerInfo serverName=fakeName"
+            """
+            output = """<gauche version="1.0"><response result="0"/>
+                     </gauche>"""
+            return output, None
+
+        def create_server(cliq_args):
+            """
+            input = "createServer serverName=fakeName initiator=something"
+            """
+            output = """<gauche version="1.0"><response result="0"/>
+                     </gauche>"""
+            return output, None
+
         def test_error(cliq_args):
             output = """<gauche version="1.0">
                 <response description="Volume '134234' not found."
@@ -175,6 +197,8 @@ class HpSanISCSITestCase(test.TestCase):
                      'unassignVolumeToServer': unassign_volume,
                      'getClusterInfo': get_cluster_info,
                      'getVolumeInfo': get_volume_info,
+                     'getServerInfo': get_server_info,
+                     'createServer': create_server,
                      'testError': test_error}
         except KeyError:
             raise NotImplementedError()
index c4bd6716d7649c2c5891c641eafd3465f0ef1a0f..af184d0e0e55129504bebcad1277287133df357f 100644 (file)
@@ -17,17 +17,14 @@ HP Lefthand SAN ISCSI Driver.
 The driver communicates to the backend aka Cliq via SSH to perform all the
 operations on the SAN.
 """
-
 from lxml import etree
 
 from cinder import exception
-from cinder import flags
 from cinder.openstack.common import log as logging
 from cinder.volume.drivers.san.san import SanISCSIDriver
 
 
 LOG = logging.getLogger(__name__)
-FLAGS = flags.FLAGS
 
 
 class HpSanISCSIDriver(SanISCSIDriver):
@@ -54,23 +51,31 @@ class HpSanISCSIDriver(SanISCSIDriver):
     compute layer.
     """
 
+    stats = {'driver_version': '1.0',
+             'free_capacity_gb': 'unknown',
+             'reserved_percentage': 0,
+             'storage_protocol': 'iSCSI',
+             'total_capacity_gb': 'unknown',
+             'vendor_name': 'Hewlett-Packard',
+             'volume_backend_name': 'HpSanISCSIDriver'}
+
     def __init__(self, *args, **kwargs):
         super(HpSanISCSIDriver, self).__init__(*args, **kwargs)
         self.cluster_vip = None
 
-    def _cliq_run(self, verb, cliq_args):
+    def _cliq_run(self, verb, cliq_args, check_exit_code=True):
         """Runs a CLIQ command over SSH, without doing any result parsing"""
         cliq_arg_strings = []
         for k, v in cliq_args.items():
             cliq_arg_strings.append(" %s=%s" % (k, v))
         cmd = verb + ''.join(cliq_arg_strings)
 
-        return self._run_ssh(cmd)
+        return self._run_ssh(cmd, check_exit_code)
 
     def _cliq_run_xml(self, verb, cliq_args, check_cliq_result=True):
         """Runs a CLIQ command over SSH, parsing and checking the output"""
         cliq_args['output'] = 'XML'
-        (out, _err) = self._cliq_run(verb, cliq_args)
+        (out, _err) = self._cliq_run(verb, cliq_args, check_cliq_result)
 
         LOG.debug(_("CLIQ command returned %s"), out)
 
@@ -176,8 +181,13 @@ class HpSanISCSIDriver(SanISCSIDriver):
     def create_volume(self, volume):
         """Creates a volume."""
         cliq_args = {}
-        cliq_args['clusterName'] = FLAGS.san_clustername
-        cliq_args['thinProvision'] = '1' if FLAGS.san_thin_provision else '0'
+        cliq_args['clusterName'] = self.configuration.san_clustername
+
+        if self.configuration.san_thin_provision:
+            cliq_args['thinProvision'] = '1'
+        else:
+            cliq_args['thinProvision'] = '0'
+
         cliq_args['volumeName'] = volume['name']
         if int(volume['size']) == 0:
             cliq_args['size'] = '100MB'
@@ -253,6 +263,7 @@ class HpSanISCSIDriver(SanISCSIDriver):
             }
 
         """
+        self._create_server(connector)
         cliq_args = {}
         cliq_args['volumeName'] = volume['name']
         cliq_args['serverName'] = connector['host']
@@ -264,9 +275,35 @@ class HpSanISCSIDriver(SanISCSIDriver):
             'data': iscsi_properties
         }
 
+    def _create_server(self, connector):
+        cliq_args = {}
+        cliq_args['serverName'] = connector['host']
+        out = self._cliq_run_xml("getServerInfo", cliq_args, False)
+        response = out.find("response")
+        result = response.attrib.get("result")
+        if result != '0':
+            cliq_args = {}
+            cliq_args['serverName'] = connector['host']
+            cliq_args['initiator'] = connector['initiator']
+            self._cliq_run_xml("createServer", cliq_args)
+
     def terminate_connection(self, volume, connector, **kwargs):
         """Unassign the volume from the host."""
         cliq_args = {}
         cliq_args['volumeName'] = volume['name']
         cliq_args['serverName'] = connector['host']
         self._cliq_run_xml("unassignVolumeToServer", cliq_args)
+
+    def get_volume_stats(self, refresh):
+        if refresh:
+            cliq_args = {}
+            result_xml = self._cliq_run_xml("getClusterInfo", cliq_args)
+            cluster_node = result_xml.find("response/cluster")
+            total_capacity = cluster_node.attrib.get("spaceTotal")
+            free_capacity = cluster_node.attrib.get("unprovisionedSpace")
+            GB = 1073741824
+
+            self.stats['total_capacity_gb'] = int(total_capacity) / GB
+            self.stats['free_capacity_gb'] = int(free_capacity) / GB
+
+        return self.stats