]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
LeftHand: Add default SSH timeout and key values
authorAlex O'Rourke <alex.orourke@hpe.com>
Sat, 12 Mar 2016 00:05:00 +0000 (16:05 -0800)
committerAlex O'Rourke <alex.orourke@hpe.com>
Tue, 15 Mar 2016 23:34:58 +0000 (16:34 -0700)
Currently if ssh_conn_timeout or san_private_key is not specified
in the remote_array object, the client creation fails. This should not
be the case. Instead, we can add default values to allow the creation
to succeed.

In addition, this patch removes some redudent lines of code and
moves a call to a more logical place.

Change-Id: I0bb32c2ea9a16ea568059ff7a5a5f07a95c718eb
Closes-Bug: #1556331

cinder/tests/unit/test_hpelefthand.py
cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py

index 2f0e76a3a2ace45803459d7fd794931ff122d80d..0262b67e4940ede15135c63bc8293d36c4cc7685 100644 (file)
@@ -2355,3 +2355,41 @@ class TestHPELeftHandISCSIDriver(HPELeftHandBaseDriver, test.TestCase):
                 context.get_admin_context(),
                 [volume],
                 'default')
+
+    def test__create_replication_client(self):
+        # set up driver with default config
+        self.setup_driver()
+
+        # Ensure creating a replication client works without specifiying
+        # ssh_conn_timeout or san_private_key.
+        remote_array = {
+            'hpelefthand_api_url': 'https://1.1.1.1:8080/lhos',
+            'hpelefthand_username': 'user',
+            'hpelefthand_password': 'password',
+            'hpelefthand_ssh_port': '16022'}
+        cl = self.driver._create_replication_client(remote_array)
+        cl.setSSHOptions.assert_called_with(
+            '1.1.1.1',
+            'user',
+            'password',
+            conn_timeout=30,
+            known_hosts_file=mock.ANY,
+            missing_key_policy='AutoAddPolicy',
+            port='16022',
+            privatekey='')
+
+        # Verify we can create a replication client with custom values for
+        # ssh_conn_timeout and san_private_key.
+        cl.reset_mock()
+        remote_array['ssh_conn_timeout'] = 45
+        remote_array['san_private_key'] = 'foobarkey'
+        cl = self.driver._create_replication_client(remote_array)
+        cl.setSSHOptions.assert_called_with(
+            '1.1.1.1',
+            'user',
+            'password',
+            conn_timeout=45,
+            known_hosts_file=mock.ANY,
+            missing_key_policy='AutoAddPolicy',
+            port='16022',
+            privatekey='foobarkey')
index b7a04439da356e0c7cf3fbfa4c7d5fe9b53aecfe..9b977dbe70e49afd56dc2e2b0dc31e0558490746 100644 (file)
@@ -151,9 +151,10 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
         2.0.5 - Changed minimum client version to be 2.1.0
         2.0.6 - Update replication to version 2.1
         2.0.7 - Fixed bug #1554746, Create clone volume with new size.
+        2.0.8 - Add defaults for creating a replication client, bug #1556331
     """
 
-    VERSION = "2.0.7"
+    VERSION = "2.0.8"
 
     device_stats = {}
 
@@ -280,6 +281,9 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
                 remote_array['hpelefthand_username'],
                 remote_array['hpelefthand_password'])
 
+            ssh_conn_timeout = remote_array.get('ssh_conn_timeout', 30)
+            san_private_key = remote_array.get('san_private_key', '')
+
             # Extract IP address from API URL
             ssh_ip = self._extract_ip_from_url(
                 remote_array['hpelefthand_api_url'])
@@ -292,8 +296,8 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
                 remote_array['hpelefthand_username'],
                 remote_array['hpelefthand_password'],
                 port=remote_array['hpelefthand_ssh_port'],
-                conn_timeout=remote_array['ssh_conn_timeout'],
-                privatekey=remote_array['san_private_key'],
+                conn_timeout=ssh_conn_timeout,
+                privatekey=san_private_key,
                 missing_key_policy=policy,
                 known_hosts_file=known_hosts_file)
 
@@ -1417,7 +1421,6 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
                 raise exception.InvalidReplicationTarget(reason=msg)
 
             target_id = failover_target['backend_id']
-            self._active_backend_id = target_id
             volume_update_list = []
             for volume in volumes:
                 if self._volume_of_replicated_type(volume):
@@ -1440,9 +1443,6 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
                     cl = None
                     try:
                         cl = self._create_replication_client(failover_target)
-                        # Make the volume primary so it can be attached after a
-                        # fail-over.
-                        cl.makeVolumePrimary(volume['name'])
                         # Stop snapshot schedule
                         try:
                             name = volume['name'] + (
@@ -1485,6 +1485,8 @@ class HPELeftHandISCSIDriver(driver.ISCSIDriver):
                         {'volume_id': volume['id'],
                          'updates': {'status': 'error'}})
 
+            self._active_backend_id = target_id
+
         return target_id, volume_update_list
 
     def _do_replication_setup(self):