From 1c7f7aaaafc38ace4b6512c4f0d5a2c5f08a1fea Mon Sep 17 00:00:00 2001 From: Alex O'Rourke Date: Fri, 11 Mar 2016 16:05:00 -0800 Subject: [PATCH] LeftHand: Add default SSH timeout and key values 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 | 38 +++++++++++++++++++ .../volume/drivers/hpe/hpe_lefthand_iscsi.py | 16 ++++---- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/cinder/tests/unit/test_hpelefthand.py b/cinder/tests/unit/test_hpelefthand.py index 2f0e76a3a..0262b67e4 100644 --- a/cinder/tests/unit/test_hpelefthand.py +++ b/cinder/tests/unit/test_hpelefthand.py @@ -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') diff --git a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py index b7a04439d..9b977dbe7 100644 --- a/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py +++ b/cinder/volume/drivers/hpe/hpe_lefthand_iscsi.py @@ -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): -- 2.45.2